ray tracing assignment
play

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 1. Setting the Scene 2. Camera Modeling 3. Basic


  1. So You Want to Write a Ray Tracer Checkpoint 6 – Refraction Ray Tracing Assignment • Goal is to reproduce the following Whitted, 1980 1

  2. Ray Tracing Assignment • Seven checkpoints 1. Setting the Scene 2. Camera Modeling 3. Basic Shading 4. Procedural Shading 5. Recursive Ray Tracing – Reflection 6. Recursive Ray Tracing – Transmission 7. Tone Reproduction Ray Tracing Assignment • Seven checkpoints 1. Setting the Scene 2. Camera Modeling 3. Basic Shading 4. Procedural Shading 5. Recursive Ray Tracing – Reflection 6. Recursive Ray Tracing – Transmission 7. Tone Reproduction 2

  3. Refraction • Perform recursive ray tracing by considering reflection and refraction • Parameters to add: – For each object • k r , k t – reflection and transmission constants • k t ≠ 0 for this checkpoint • Index of refraction (example 0.95) Recursive Ray Tracing color illuminate (ray, depth) find closest intersect if (!intersection) return background color else spawn shadow ray retcolor = local illumination if (depth < MAX_DEPTH) if (k r > 0) spawn reflection ray retcolor += k r * illuminate (reflect ray, depth+1) if (k t > 0) spawn transmission ray retcolor += k t * illuminate (trans ray, depth +1) return retcolor 3

  4. Recursive Ray Tracing For each pixel spawn ray from camera pos to pixel pixel_color = illuminate (ray, 1) Calculating Transmission Ray Starting with Snell’s law θ d n η θ = η θ i η sin sin i i i t t η t θ t Assume d and n are normalized. t We can find the equation for t, the transmission ray: d is the incoming ray, t is the η − • η − • 2 2 ( d n(d n) ) ( 1 ( d n ) ) transmission ray. = − i i t n 1 - η η 2 t t If negative – total internal reflection 4

  5. Calculating transmission ray • Snell’s law applet – http://www.physics.nwu.edu/ugrad/vpl/optics/snell.htm l • 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 Things to think about • Must keep track if you are inside or outside Index of refraction η Normal vector 5

  6. Things to think about • 2 ways to deal – If n • d < 0 then • Inside • Use –n as normal for calculations η • Use inside η as i – Use faceForward Things to think about • FaceForward (RenderMan) – The result is A, if A and B form an acute angle when placed head to tail, otherwise the result is -A. A (input): This is the first input vector. B (input): This is the second input vector. OUT (output): The result is A, if A and B form an acute angle when placed head to tail, otherwise the result is -A. 6

  7. Things to think about public Vector3f faceForward (Vector3f A Vector3f B) { // 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; } Refraction • For sake of checkpoint – Make one sphere transparent (k t = 0.8) – Make other sphere non-transparent – May wish to test first with index of refraction = 1.0 7

  8. Refraction • Note: – If done correctly, you should now have a faithful reproduction of the target image. – Sample parameters � Sphere2 – rear � Sphere1 – front � Color (amb/diffuse) � Color (all) = white � Ka = 0.075 (0.7, 0.7, 0.7) � Kd = 0.075 � Color (spec) = white � Ka = 0.15 � Ks = 0.2 � Kd = 0.25 � Ke = 20.0 � Ks = 1.0 � Kr = 0.01 � Ke = 20.0 � Kt = 0.85 � Kr = 0.75 � Kt = 0.0 Refraction • Due date: – Must be posted to Web site by Midnight Feb 7 th – Recall: • 10% penalty per day – Having trouble? • Let me know EARLY. • Questions? 8

  9. Extra extra • For 5 points: – Like reflection…spawn multiple rays. 9

Recommend


More recommend