Title: MIT%206.837%20-%20Ray%20Tracing
1MIT 6.837 - Ray Tracing
2Ray Tracing
- MIT EECS 6.837
- Frédo Durand and Barb Cutler
- Some slides courtesy of Leonard McMillan
3Administrative
- Assignment 2
- Due tomorrow at 1159pm
- Assignment 3
- Online this evening
- Due Wednesday October 1
4Cool assignment 1 results
seantek
koi
emmav
dym
5Review of last week?
6Review of last week
- Linear, affine and projective transforms
- Homogeneous coordinates
- Matrix notation
- Transformation composition is not commutative
- Orthonormal basis change
7Review of last week
- Transformation for ray tracing
- Transforming the ray
- For the direction, linear part of the transform
only - Transforming t or not
- Normal transformation
- Constructive Solid Geometry (CSG)
nWS
nWST nOS (M-1)
vWS
8Fun with transformations Relativity
- Special relativity Lorentz transformation
- 4 vector (t, x, y, z)
- 4th coordinate can be ct or t
- Lorentz transformation depends on object speed v
Digression
http//casa.colorado.edu/ajsh/sr/sr.shtml
9Relativity
- Transform ray by Lorentz transformation
Digression
0.65c
0.70c
0.90c
0.99c
See also http//www.cs.mu.oz.au/andrbh/raytrace/r
aytrace.html
10Today Ray Tracing
Image by Turner Whitted
11Overview of today
- Shadows
- Reflection
- Refraction
- Recursive Ray Tracing
12Ray Casting (a.k.a. Ray Shooting)
- For every pixel (x,y)Construct a ray from the
eye colorx,ycastRay(ray) - Complexity?
- O(n m)
- n number of objects, m number of pixels
13Ray Casting with diffuse shading
- Color castRay(ray)Hit hit()
- For every object ob
- ob-gtintersect(ray, hit, tmin)
- Color colambienthit-gtgetColor()
- For every light L
- colcolhit-gtgetColorL()L-gtgetColorL-gtgetDir()-
gtDot3( hit-gtgetNormal() ) - Return col
14Encapsulating shading
- Color castRay(ray)Hit hit()
- For every object ob
- ob-gtintersect(ray, hit, tmin)
- Color colambienthit-gtgetMaterial()-gtgetDiffuse()
- For every light L
- colcolhit-gtgetMaterial()-gtshade (ray, hit,
L-gtgetDir(), L-gtgetColor()) - Return col
15Questions?
- Image computed using the RADIANCE system by Greg
Ward
16How can we add shadows?
- Color castRay(ray)Hit hit()
- For every object ob
- ob-gtintersect(ray, hit, tmin)
- Color colambienthit-gtgetMaterial()-gtgetDiffuse()
- For every light L
- colcolhit-gtgetMaterial()-gtshade (ray, hit,
L-gtgetDir(), L-gtgetColor()) - Return col
17Shadows
- Color castRay(ray)Hit hit()
- For every object ob
- ob-gtintersect(ray, hit, tmin)
- Color colambienthit-gtgetMaterial()-gtgetDiffuse()
- For every light L
- Ray ray2(hitPoint, L-gtgetDir()) Hit
hit2(L-gtgetDist(),,) - For every object ob
- ob-gtintersect(ray2, hit2, 0)
- If (hit-gtgetTgt L-gtgetDist())
- colcolhit-gtgetMaterial()-gtshade (ray, hit,
L-gtgetDir(), L-gtgetColor()) - Return col
18Shadows problem?
- Color castRay(ray)Hit hit()
- For every object ob
- ob-gtintersect(ray, hit, tmin)
- Color colambienthit-gtgetMaterial()-gtgetDiffuse()
- For every light L
- Ray ray2(hitPoint, L-gtgetDir()) Hit
hit2(L-gtgetDist(),,) - For every object ob
- ob-gtintersect(ray2, hit2, 0)
- If (hit-gtgetTgt L-gtgetDist())
- colcolhit-gtgetMaterial()-gtshade (ray, hit,
L-gtgetDir(), L-gtgetColor()) - Return col
19Avoiding self shadowing
- Color castRay(ray)Hit hit()
- For every object ob
- ob-gtintersect(ray, hit, tmin)
- Color colambienthit-gtgetMaterial()-gtgetDiffuse()
- For every light L
- Ray ray2(hitPoint, L-gtgetDir()) Hit
hit2(L-gtgetDist(),,) - For every object ob
- ob-gtintersect(ray2, hit2, epsilon)
- If (hit-gtgetTgt L-gtgetDist())
- colcolhit-gtgetMaterial()-gtshade (ray, hit,
L-gtgetDir(), L-gtgetColor()) - Return col
20Shadow optimization
- Shadow rays are special
- How can we accelerate our code?
21Shadow optimization
- We only want to know whether there is an
intersection, not which one is closest - Special routine Object3DintersectShadowRay()
- Stops at first intersection
22Shadow ray casting history
- Due to Appel 1968
- First shadow method in graphics
- Not really used until the 80s
23Questions?
24Overview of today
- Shadows
- Reflection
- Refraction
- Recursive Ray Tracing
25Mirror Reflection
- Compute mirror contribution
- Cast ray
- In direction symmetric wrt normal
- Multiply by reflection coefficient (color)
26Mirror Reflection
- Cast ray
- In direction symmetric wrt normal
- Dont forget to add epsilon to the ray
Without epsilon
With epsilon
27Reflection
- Reflection angle view angle
N
R
V
q
q
R
V
28Reflection
- Reflection angle view angle
29Amount of Reflection
- Traditional (hacky) ray tracing
- Constant coefficient reflectionColor
- Component per component multiplication
30Amount of Reflection
- More realistic
- Fresnel reflection term
- More reflection at grazing angle
- Schlicks approximation R(q)R0(1-R0)(1-cos q)5
metal
Dielectric (glass)
31Fresnel reflectance demo
- Lafortune et al., Siggraph 1997
32Questions?
- Image by Henrik Wann Jensen
33Overview of today
- Shadows
- Reflection
- Refraction
- Recursive Ray Tracing
34Transparency
- Compute transmitted contribution
- Cast ray
- In refracted direction
- Multiply by transparency coefficient (color)
35Qualitative refraction
- From Color and Light in Nature by Lynch and
Livingston
36Refraction
Snell-Descartes Law
Note that I is the negative of the incoming ray
37Refraction
Snell-Descartes Law
Note that I is the negative of the incoming ray
38Refraction
Snell-Descartes Law
Note that I is the negative of the incoming ray
39Refraction
Snell-Descartes Law
Note that I is the negative of the incoming ray
40Refraction
Snell-Descartes Law
Note that I is the negative of the incoming ray
41Refraction
Snell-Descartes Law
Note that I is the negative of the incoming ray
Dont forget to normalize
Total internal reflection when the square root is
imaginary
42Total internal reflection
- From Color and Light in Nature by Lynch and
Livingstone
43Cool refraction demo
- Enright, D., Marschner, S. and Fedkiw, R.,
44Cool refraction demo
- Enright, D., Marschner, S. and Fedkiw, R.,
45Refraction and the lifeguard problem
- Running is faster than swimming
Lifeguard
Beach
Water
Run
Person in trouble
Digression
Swim
46Wavelength
- Refraction is wavelength-dependent
- Newtons experiment
- Usually ignored in graphics
Pittoni, 1725, Allegory to Newton
Pink Floyd, The Dark Side of the Moon
47Rainbow
- From Color and Light in Nature by Lynch and
Livingstone
Digression
48Rainbow
- Refraction depends on wavelength
- Rainbow is caused by refractioninternal
reflectionrefraction - Maximum for angle around 42 degrees
Digression
From Color and Light in Nature by Lynch and
Livingstone
49Questions?
50Overview of today
- Shadows
- Reflection
- Refraction
- Recursive Ray Tracing
51Recap Ray Tracing
- traceRay
- Intersect all objects
- Ambient shading
- For every light
- Shadow ray
- shading
- If mirror
- Trace reflected ray
- If transparent
- Trace transmitted ray
52Recap Ray Tracing
- Color traceRay(ray)For every object ob
- ob-gtintersect(ray, hit, tmin)
- Color colambienthit-gtgetMaterial()-gtgetDiffuse()
- For every light L
- If ( not castShadowRay( hit-gtgetPoint(),
L-gtgetDir()) - colcolhit-gtgetMaterial()-gtshade (ray, hit,
L-gtgetDir(), L-gtgetColor()) - If (hit-gtgetMaterial()-gtisMirror())
- Ray rayMirror (hit-gtgetPoint(),
getMirrorDir(ray-gtgetDirection(),
hit-gtgetNormal()) - Colcolhit-gtgetMaterial-gtgetMirrorColor()traceR
ay(rayMirror, hit2) - If (hit-gtgetMaterial()-gtisTransparent()
- Ray rayTransmitted(hit-gtgetPoint(),
getRefracDir(ray, hit-gtgetNormal(),
curentRefractionIndex, hit-gtMaterial-gtgetRefractio
nIndex()) - Colcolhit-gtgetMaterial-gtgetTransmittedColor()t
raceRay(rayTransmitted, hit3) - Return col
53Does it end?
- Color traceRay(ray)For every object ob
- ob-gtintersect(ray, hit, tmin)
- Color colambienthit-gtgetMaterial()-gtgetDiffuse()
- For every light L
- If ( not castShadowRay( hit-gtgetPoint(),
L-gtgetDir()) - colcolhit-gtgetMaterial()-gtshade (ray, hit,
L-gtgetDir(), L-gtgetColor()) - If (hit-gtgetMaterial()-gtisMirror())
- Ray rayMirror (hit-gtgetPoint(),
getMirrorDir(ray-gtgetDirection(),
hit-gtgetNormal()) - Colcolhit-gtgetMaterial-gtgetMirrorColor()traceR
ay(rayMirror, hit2) - If (hit-gtgetMaterial()-gtisTransparent()
- Ray rayTransmitted(hit-gtgetPoint(),
getRefracDir(ray, hit-gtgetNormal(),
curentRefractionIndex, hit-gtMaterial-gtgetRefractio
nIndex()) - Colcolhit-gtgetMaterial-gtgetTransmittedColor()t
raceRay(rayTransmitted, hit3) - Return col
54Avoiding infinite recursion
- Stopping criteria
- Recursion depth
- Stop after a number of bounces
- Ray contribution
- Stop if transparency/transmitted attenuation
becomes too small - Usually do both
Color traceRay(ray)For every object
ob ob-gtintersect(ray, hit, tmin) Color
colambienthit-gtgetMaterial()-gtgetDiffuse() For
every light L If ( not castShadowRay(
hit-gtgetPoint(), L-gtgetDir()) colcolhit-gtgetMate
rial()-gtshade (ray, hit, L-gtgetDir(),
L-gtgetColor()) If (hit-gtgetMaterial()-gtisMirror()
) Ray rayMirror (hit-gtgetPoint(),
getMirrorDir(ray-gtgetDirection(),
hit-gtgetNormal()) Colcolhit-gtgetMaterial-gtgetMi
rrorColor()traceRay(rayMirror) If
(hit-gtgetMaterial()-gtisTransparent() Ray
rayTransmitted(hit-gtgetPoint(),
getRefracDir(ray, hit-gtgetNormal(),
curentRefractionIndex, hit-gtMaterial-gtgetRefractio
nIndex()) Colcolhit-gtgetMaterial-gtgetTransmitte
dColor()traceRay(rayTransmitted) Return col
55Recursion for reflection
1 recursion
0 recursion
2 recursions
56The Ray Tree
T3
Eye
R2
N2
T1
R3
R1
N3
L1
L2
L3
N1
L1
T1
R1
L3
L2
Ni surface normal Ri reflected ray Li shadow
ray Ti transmitted (refracted) ray
Eye
T3
R3
R2
57Kewl visualization
- Ben Garlicks SGI demo flyray
- On an Athena SGI O2
- add 6.837
- cd /mit/6.837/demos/flyray/data
- ../flyray
58Real-time ray tracing
- Steve Parker et al. (U. of Utah)
59Ray Tracing History
- Ray Casting Appel, 1968
- CSG and quadrics Goldstein Nagel 1971
- Recursive ray tracing Whitted, 1980
60Does Ray Tracing simulate physics?
- Photons go from the light to the eye, not the
other way - What we do is backward ray tracing
61Forward ray tracing
- Start from the light source
- But low probability to reach the eye
- What can we do about it?
62Forward ray tracing
- Start from the light source
- But low probability to reach the eye
- What can we do about it?
- Always send a ray to the eye
- Still not efficient
63Does Ray Tracing simulate physics?
- Ray Tracing is full of dirty tricks
- e.g. shadows of transparent objects
- Dirtiest opaque
- Still dirty multiply by transparency color
- But then no refraction
64Correct transparent shadow
- Animation by Henrik Wann Jensen
- Using advanced refraction technique (refraction
for illumination is usually not handled that well)
Digression
65The Rendering equation
- Clean mathematical framework for light-transport
simulation - Well see that in November
- At each point, outgoing light in one directionis
the integral of incoming light in all directions
multiplied by reflectance property
66Thursday
- Reflectance properties, shading and BRDF
- Guest lecture by Wojciech Matusik