Raytrace
Raytrace
Raytrace
CMSC 435/634
Projections
orthographic
axis-aligned
orthographic
perspective oblique
2
Computing Viewing Rays
w v
e u
w e
u
+ + =
10
Diffuse Component
• Lambert’s Law
– Intensity of reflected light proportional to
cosine of angle between surface and incoming
light direction
– Applies to “diffuse,” “Lambertian,” or “matte”
surfaces
– Independent of viewing angle
• Use as a component of non-Lambertian surfaces
11
Diffuse Component
kd I(l̂ · n̂)
max(kd I(l̂ · n̂), 0)
12
Diffuse Component
• Plot light leaving in a given direction:
13
Specular Component
• Specular component is a mirror-like reflection
• Phong Illumination Model
– A reasonable approximation for some surfaces
– Fairly cheap to compute
• Depends on view direction
14
Specular Component
ksI(r̂ · v̂) p N
L V
p R
ksI max(r̂ · v̂, 0)
15
Specular Component
• Computing the reflected direction
r̂ = l̂ + 2(l̂ · n̂)n̂ n
l r
θ n cos θ
n cos θ
l̂ + v̂
-l
ĥ =
||l̂ + v̂||
n h
l
ω
e
16
Specular Component
• Plot light leaving in a given direction:
19
Summing the Parts
R = kaI + kd I max(l̂ · n̂, 0) + ksI max(r̂ · v̂, 0) p
+ + =
21
Ray Traced Shadows
• Trace a ray
– Start = point on surface
– End = light source
– t=0 at Surface, t=1 at Light
– “Bias” to avoid surface acne
• Test
– Bias ≤ t ≤ 1 = shadow
– t < Bias or t > 1 = use this light
Mirror Reflection
23
The Dark Side of the Trees - Gilles Tran,
Spheres - Martin K. B.
Ray Tracing Reflection
• Viewer looking in direction d sees whatever the
viewer “below” the surface sees looking in
direction r
• In the real world
– Energy loss on the bounce
– Loss different for different colors
• New ray
– Start on surface, in reflection direction
24
Ray Traced Reflection
• Avoid looping forever
– Stop after n bounces
– Stop when contribution to pixel gets too small
Specular vs. Mirror Reflection
Combined Specular & Mirror
• Many surfaces have both
Refraction
Top
Front
Refraction and Alpha
• Refraction = what direction
• α = how much
– Often approximate as a constant
– Better: Use Fresnel
– Schlick approximation
Full Ray-Tracing
• For each pixel
– Compute ray direction
– Find closest surface
– For each light
• Shoot shadow ray
• If not shadowed, add direct illumination
– Shoot ray in reflection direction
– Shoot ray in refraction direction
Dielectric
if (p is on a dielectric) then
r = reflect (d, n)
if (d.n < 0) then
refract (d, n , n, t)
c = -d.n
kr = kg = kb = 1
else
kr = exp(-alphar * t)
kg = exp(-alphag * t)
kb = exp(-alphab * t)
if (refract(d, -n, 1/n t) then
c = t.n
else
return k * color(p+t*r)
R0 = (n-1)^2 / (n+1)^2
R = R0 + (1-R0)(1 - c)^5
return k(R color(p + t*r) + (1-R)color(p+t*t)
Distribution Ray Tracing
35
Distribution Ray Tracing
• Anti-aliasing
• Soft Shadows
• Depth of Field
• Glossy Reflection
• Motion Blur
36
Sampling
37
Soft Shadows
38
Depth of Field
Soler et al., Fourier Depth of Field, ACM TOG v28n2, April 2009
Pinhole Lens
Lens Model
Real Lens
Focal Plane
Lens Model
Focal Plane
Ray Traced DOF
• Move image plane out to focal plane
• Jitter start position within lens aperture
– Smaller aperture = closer to pinhole
– Larger aperture = more DOF blur
Glossy Reflection
45
Motion Blur
• Things move while the shutter is open
Ray Traced Motion Blur
• Include information on object motion
• Spread multiple rays per pixel across time