1
So You Want to Write a Ray Tracer
Checkpoint 6 – Refraction
Ray Tracing Assignment
Goal is to reproduce the following Whitted, 1980
Ray Tracing Assignment Goal is to reproduce the following Whitted, - - PDF document
So You Want to Write a Ray Tracer Checkpoint 6 Refraction Ray Tracing Assignment Goal is to reproduce the following Whitted, 1980 1 Ray Tracing Assignment Seven checkpoints Setting the Scene Camera Modeling
Goal is to reproduce the following Whitted, 1980
Setting the Scene Camera Modeling Basic Shading Procedural Shading Recursive Ray Tracing – Reflection Recursive Ray Tracing – Transmission Tone Reproduction
Setting the Scene Camera Modeling Basic Shading Procedural Shading Recursive Ray Tracing – Reflection Recursive Ray Tracing – Transmission Tone Reproduction
Perform recursive ray tracing by
Parameters to add:
For each object
kr, kt – reflection and transmission constants kt ≠ 0 for this checkpoint Index of refraction (example 0.95)
color illuminate (ray, depth) find closest intersect if (!intersection) return background color else spawn shadow ray retcolor = local illumination if (depth < MAX_DEPTH)
if (kr > 0) spawn reflection ray retcolor += kr * illuminate (reflect ray, depth+1) if (kt > 0) spawn transmission ray retcolor += kt * illuminate (trans ray, depth +1)
return retcolor
2 2 2 i i
) ) n d ( 1 (
n ) n) n(d d ( t
t t
η η η η
+
=
i
η
i
θ
an optical phenomenon that occurs
In these cases, the transmission ray will
Snell’s law applet
http://www.physics.northwestern.edu/ugrad/vpl/opt
Index of refraction of air = 1.0 Optimization
If indices of refractions are the same
no bending Transmission direction is the same as incoming direction
Must keep track if you are inside or
η Index of refraction Normal vector
2 ways to deal
If n • d < 0 then
Inside Use –n as normal for calculations Use inside η as
Keep track as you are spawning rays
i
{ // For acute angles, dot product will // be positive if (A.dot(B) >= 0) return A; // Obtuse angle, reverse the first vector Vector3f V = new Vector3f (A); V.scale (-1.0f); return V; }
For sake of checkpoint
Make one sphere transparent (kt = 0.8) Make other sphere non-transparent May wish to test first with index of refraction = 1.0
Note:
If done correctly, you should now have a faithful
Sample parameters
Sphere1 – front Color (all) = white Ka = 0 .0 7 5 Kd = 0 .0 7 5 Ks = 0 .2 Ke = 2 0 .0 Kr = 0 .0 1 Kt = 0 .8 5 Sphere2 – rear Color (amb/diffuse)
(0.7, 0.7, 0.7)
Color (spec) = white Ka = 0 .1 5 Kd = 0 .2 5 Ks = 1 .0 Ke = 2 0 .0 Kr = 0 .7 5 Kt = 0 .0
Due date:
Must be posted to Web site by Feb 6th Recall:
10% penalty per day
Having trouble?
Let me know EARLY.
Questions?
For 5 points:
Adjust shadow ray based upon