Ray Tracing
CPSC 453 – Fall 2018 Sonny Chan
Ray Tracing CPSC 453 Fall 2018 Sonny Chan Ray Tracing A method - - PowerPoint PPT Presentation
Ray Tracing CPSC 453 Fall 2018 Sonny Chan Ray Tracing A method for synthesizing images of virtual 3D scenes. Image Capture Devices Which one shall we use? Goal: Simulate a Camera Obscura! Spheres & Checkerboard Turner Whitted,
Ray Tracing
CPSC 453 – Fall 2018 Sonny Chan
Ray Tracing
A method for synthesizing images
Image Capture Devices
Which one shall we use?
Goal: Simulate a Camera Obscura!
“Spheres & Checkerboard”
Turner Whitted, 1979
Whitted Ray Tracing
model for shaded display”
computer render this today?
[image courtesy of P . Hanrahan, Stanford University]
The Ray Tracing Algorithm
Ray Generation
virtual image plane
[from photojojo.com]
Let’s see how we might
Ray Generation
r(t) = e + t(s − e)
Ray Intersection
What do we see?
Ray Intersection
determine whether or not we can see it
Ray-Sphere Intersection
||p − c|| = R (p − c) · (p − c) − R2 = 0 r(t) = o + td (r(t) − c) · (r(t) − c) − R2 = 0 (o + td − c) · (o + td − c) − R2 = 0 A ray: A sphere: Intersection:
Solve for t…
c R
Ray-Plane Intersection
A ray: A plane: Intersection: r(t) = o + td (p − q) · ˆ n = 0
Solve for t…
(r(t) − q) · ˆ n = 0 (o + td − q) · ˆ n = 0
q ˆ n
How might we test
intersection of a ray and a triangle?
Barycentric Coordinates
p0 p1 p2 f(u, v) = (1 − u − v)p0 + up1 + vp2 u
v
w
(.6, .4, 0) (.3, .2, .5)
Another Interpretation
Ratio of (signed) areas of triangles:
u = A1 A v = A2 A
f(u, v) = (1 − u − v)p0 + up1 + vp2
A = 1
2(p1 − p0) × (p2 − p0)
p0 p1
(.3, .2, .5)
p2
A0 A1 A2
A Direct Approach for Intersection
r(t) = o + td −d p1 − p0 p2 − p0 t u v = o − p0
A ray: A triangle: Rearrange terms:
f(u, v) = (1 − u − v)p0 + up1 + vp2
Ray-triangle intersect:
Solve for t, u, and v…
Cramer’s Rule
a b c x y z = d det(a, b, c) =
b1 c1 a2 b2 c2 a3 b3 c3
det(a, b, c) y = det(a, d, c) det(a, b, c) z = det(a, b, d) det(a, b, c)
A Direct Approach for Intersection
−d p1 − p0 p2 − p0 t u v = o − p0 e1 = p1 − p0, e2 = p2 − p0, s = o − p0 t u v = 1 det(−d, e1, e2) det(s, e1, e2) det(−d, s, e2) det(−d, e1, s)
Our equation: Applying Cramer’s rule: where
Check that t > 0 and u, v, u+v are within [0,1] interval!
Ray-Object Intersection Tests
triangles in perspective with a ray tracer!
[from photojojo.com]
I think we need some shading…
What we’ve got now… and what we really want!
Shadows & More
What happens if we have more than one light?
How do we get these nice, soft shadows?
Depth of Field
Can we ray trace it?
image
The Ray Tracing Algorithm
scene.
Things to Remember
images of a 3D scene in perspective
willing to wait!