Lecture 19: All Together with Refraction December 1, 2016 12/1/16 CSU CS410 Fall 2016, Ross Beveridge & Bruce Draper 1
How about Interreflections? Note reflections Granite tabletop Visible on base Also on handle This is a featured picture on the English language Wikipedia (Featured pictures) and is considered one of the finest images. (October 2012) 12/1/16 Bruce Draper & J. Ross Beveridge 2
Rationale for Interreflections Not all the light striking a surface comes directly from a light source. Some reflects off one surface onto another. We ignore diffuse reflected light: Because its small, and we can get away with it Because it is very expensive to compute Specular reflection much more sensitive Just consider reflections in previous image. 12/1/16 Bruce Draper & J. Ross Beveridge 3
Interreflections v L In the case of mirrors or shiny objects, this can have a major impact 12/1/16 Bruce Draper & J. Ross Beveridge 4
Illustrating Recursive Ray Tracing V R L L L N L N poi V V R L R L V R R L R L poi 12/1/16 Bruce Draper & J. Ross Beveridge 5
You have a full working illustration! 12/1/16 CSU CS410 Fall 2016, Ross Beveridge & Bruce Draper 6
In 3D locate Focal Point Image Plane Objects Light 1 Light 2 3D Scene Layout 12/1/16 CSU CS410 Fall 2016, Ross Beveridge & Bruce Draper 7
Rays of Reflection To add reflections, we need the light hitting the surface from the reflected viewing ray. R V L T N T R L V C q q S Multiply reflected illumination by k r and add to total illumination. 12/1/16 Bruce Draper & J. Ross Beveridge 8
Computing V R R V = 2(V N)N-V Just like R L, but V replaces L To be more detailed N T V N V = (V N)N T V = N V V = (V N)N V R V = V + 2T V = 2(V N)N-V R V S V 12/1/16 Bruce Draper & J. Ross Beveridge 9
The Same Thing in Code From the notebook refr = make_unit((2*np.dot(n,uinv)*n)-uinv) Includes: Function to make result unit length The numpy dot product function The surface normal The ray pointing back the way the original ray came into the surface namely U inverse 12/1/16 CSU CS410 Fall 2016, Ross Beveridge & Bruce Draper 10
Example Code with Recursion There is a lot more going on in this code, study it and play with it until you understand each line; Why is it there? What does it do? 12/1/16 Bruce Draper & J. Ross Beveridge 11
Complications that Arise Is the reflection `colored by the material Notebook example uses K r Other systems may use the diffuse coeficients. Is anything lost through bounces? Does bouncing light from surface to surface take away energy? (Yes). So in code there should be an attenuation term. This is set to 0.9 in all the Notebook examples. 12/1/16 CSU CS410 Fall 2016, Ross Beveridge & Bruce Draper 12
Translucence Some light passes through the material. Typically, passed through light gets the diffuse reflection properties of the surface, unless object is 100% translucent (i.e. transparent) Speed of light is a function of the medium This causes light to bend at boundaries example: looking at the bottom of a pool 12/1/16 Bruce Draper & J. Ross Beveridge 13
Refraction - With Trigonomety Key is Snell s law sin( θ t )= η i sin θ i η t θ i angle of incidence θ r angle of refraction η i index of refraction material #1 η t index of refraction material #2 ( ) W θ i N θ i R The refraction ray is: " T = η i $ cos θ i # η t ( ) cos( θ t ) % 'N η i W & η t θ t T 12/1/16 Bruce Draper & J. Ross Beveridge 14
Practical Refraction: Solids When light enters a solid glass object? h air = 1.0 h glass = 1.5 N W Theta i Sin mu Theta r 0 0.00 0.67 0.00 10 0.17 0.67 6.67 20 0.34 0.67 13.33 30 0.50 0.67 20.00 40 0.64 0.67 26.67 50 0.77 0.67 33.33 60 0.87 0.67 40.00 70 0.94 0.67 46.67 80 0.98 0.67 53.33 90 1.00 0.67 60.00 " θ r = sin 1 η $ i sin θ i # η r ( ) % ' = sin 1 & ( 0.67 sin( θ i )) 12/1/16 Bruce Draper & J. Ross Beveridge 15
More Recursion This changes ray tracing from tail-recursion to double-recursion light1 light2 N N camera This is the recursive Refraction ray light3 12/1/16 Bruce Draper & J. Ross Beveridge 16
Practical Refraction: Surfaces What happens as it passes through a solid or surface? sinθ 1 = η i η r sinθ i sinθ i = η r η i sinθ 2 sinθ 1 = η i η r η r η i sinθ 2 = sinθ 2 Ø Overall effect: displacement of the incident vector Note: this assumes the two surfaces of the solid are coplanar! 12/1/16 Bruce Draper & J. Ross Beveridge 17
Refraction - No Trigonometry. First Constraint: Snells Law T = αw + βn sin( θ i ) 2 µ 2 = sin( θ t ) 2 µ = µ i µ t ( 1 cos( θ i ) 2 ) µ 2 =1 cos( θ t ) 2 W θ i N θ i R ( 1 ( W N) 2 ) µ 2 =1 ( N T ) 2 ( 1 ( W N) 2 ) µ 2 =1 N ( αw + βn) ( ) 2 -N θ t T 12/1/16 Bruce Draper & J. Ross Beveridge 18
Refraction - No Trigonometry Second Constraint: Refraction ray is unit length. T T = αw + βn ( ) αw + βn ( ) =1 = α 2 + 2αβ W N ( ) + β 2 =1 Two quadratic equations in two unknowns. Solving is a bit involved, next slide & writeup. Here is the answer. α = µ β = µ ( W N) 1 µ 2 + µ 2 ( W N) 2 12/1/16 Bruce Draper & J. Ross Beveridge 19
A Wonderful Real Example https://physicsb-2009-10.wikispaces.com Yes, refraction typically makes everthing upside down and backwards. 12/1/16 Bruce Draper & J. Ross Beveridge 20
Refraction and Polygons It is entirely possible to implement refraction through complex solid models defined by polygons. But! Doing so requires the following: Models must be complete: no holes! All faces (triangles) must be tagged to a solid. Needed to find where refraction ray exits the solid. There is a simpler special case Thin faces with parallel sides (next slide). 12/1/16 CSU CS410 Fall 2016, Ross Beveridge & Bruce Draper 21
Special Case: Thin Faces Consider entrance and exit The are parallel (see picture) Refraction vectors Pass through at a shifted angle But exit in the same direction Result is an offset only Offset depends on index of refraction Offset depends on the thickness of the face 12/1/16 Bruce Draper & J. Ross Beveridge 22
Double Recursion With refraction, ray tracing changes from tail-recursion to double recursion light1 light2 N N camera light3 This is the recursive refraction ray 12/1/16 Bruce Draper & J. Ross Beveridge 23
12/1/16 CSU CS410 Fall 2016, Ross Beveridge & Bruce Draper 24
Semester Wrap Up If you understand every line of code in the Sage Notebook creating this image you have covered a good portion of what is needed to have succeeded in CS 410 12/1/16 CSU CS410 Fall 2016, Ross Beveridge & Bruce Draper 25