CS4620/5620: Lecture 36
Ray Tracing (Shading and Sampling)
Cornell CS4620/5620 Fall 2012 • Lecture 36 © 2012 Kavita Bala • 1 (with previous instructors James/Marschner)
Announcements
• PA3A due Tuesday night
• PPA3 out
Cornell CS4620/5620 Fall 2012 • Lecture 36 © 2012 Kavita Bala • 2 (with previous instructors James/Marschner) Shading
• Compute light reflected toward camera • Inputs: – eye direction – light direction (for each of many lights) l n – surface normal v – surface parameters (color, shininess, …)
Cornell CS4620/5620 Fall 2012 • Lecture 36 © 2012 Kavita Bala • 3 (with previous instructors James/Marschner)
Mirror reflection
• Consider perfectly shiny surface – there isn’t only a highlight – instead there’s a reflection of other objects • Can render this using recursive ray tracing – to find out mirror reflection color, ask what color is seen from surface point in reflection direction – already computing reflection direction for Phong… • “Glazed” material has mirror reflection and direct
– where Lm is evaluated by tracing a new ray
Cornell CS4620/5620 Fall 2012 • Lecture 36 © 2012 Kavita Bala • 4 (with previous instructors James/Marschner) Diffuse + mirror reflection (glazed)
(glazed material on floor)
Cornell CS4620/5620 Fall 2012 • Lecture 36 © 2012 Kavita Bala • 5 (with previous instructors James/Marschner)
Snell’s Law
• Tells us where the refracted ray goes – a.k.a. transmission vector • Computation – ratio of sines is ratio of in-plane components – project to surface; scale by eta ratio; recompute normal- direction component – total internal reflection
Cornell CS4620/5620 Fall 2012 • Lecture 36 © 2012 Kavita Bala • 6 (with previous instructors James/Marschner) Computing the Transmission Vector, t
Cornell CS4620/5620 Fall 2012 • Lecture 36 © 2012 Kavita Bala • 7 (with previous instructors James/Marschner)
Computing the Transmission Vector, t
Cornell CS4620/5620 Fall 2012 • Lecture 36 © 2012 Kavita Bala • 8 (with previous instructors James/Marschner) Ray tracing dielectrics
• Like a simple mirror surface, use recursive ray tracing • But we need two rays – One reflects off the surface (same as mirror ray) – The other crosses the surface (computed using Snell’s law) • Doesn’t always exist (total internal reflection) • Splitting into two rays, recursively, creates a ray tree – Very many rays are traced per viewing ray – Ways to prune the tree • Limit on ray depth • Limit on ray attenuation
Cornell CS4620/5620 Fall 2012 • Lecture 36 © 2012 Kavita Bala • 9 (with previous instructors James/Marschner)
Whitted Ray Tracing
Cornell CS4620/5620 Fall 2012 • Lecture 36 © 2012 Kavita Bala • 10 (with previous instructors James/Marschner) Specular reflection
• Smooth surfaces of pure materials have ideal specular reflection (said this before) – Metals (conductors) and dielectrics (insulators) behave differently • Reflectance (fraction of light reflected) depends on angle
metal dielectric
Cornell CS4620/5620 Fall 2012 • Lecture 36 © 2012 Kavita Bala • 11 (with previous instructors James/Marschner)
Specular reflection from metal
• Reflectance does depend on angle Aluminum – but not much – safely ignored in basic rendering
Cornell CS4620/5620 Fall 2012 • Lecture 36 © 2012 Kavita Bala • 12 (with previous instructors James/Marschner) Specular reflection from glass/water
• Dependence on angle is dramatic! Glass – about 4% at normal incidence – 100% at grazing – remaining light is transmitted • Important for Perfect transmission at Brewster’s angle proper appearance
Cornell CS4620/5620 Fall 2012 • Lecture 36 © 2012 Kavita Bala • 13 (with previous instructors James/Marschner)
Brewster’s Angle
Cornell CS4620/5620 Fall 2012 • Lecture 36 © 2012 Kavita Bala • 14 (with previous instructors James/Marschner) Fresnel reflection
• Black glazed sphere – reflection from glass surface – transmitted ray is discarded
Constant reflectance Fresnel reflectance
Cornell CS4620/5620 Fall 2012 • Lecture 36 © 2012 Kavita Bala • 15 (with previous instructors James/Marschner)
Fresnel’s formulas
• They predict how much light reflects from a smooth interface between two materials – usually one material is empty space
– R is the fraction that is reflected – (1 – R) is the fraction that is transmitted
Cornell CS4620/5620 Fall 2012 • Lecture 36 © 2012 Kavita Bala • 16 (with previous instructors James/Marschner) Schlick’s approximation
• For graphics, a quick hack to get close with less computation:
• R0 is easy to compute:
Cornell CS4620/5620 Fall 2012 • Lecture 36 © 2012 Kavita Bala • 17 (with previous instructors James/Marschner)
Fresnel reflection [Mike & Gaain Hill Kwan | Stanford cs348 competition 2001] Cornell CS4620/5620 Fall 2012 • Lecture 36 © 2012 Kavita Bala • 18 (with previous instructors James/Marschner) Hmm, ... how do we render beer?
Cornell CS4620/5620 Fall 2012 • Lecture 36 © 2012 Kavita Bala • 19 (with previous instructors James/Marschner)
Beer's Law!
Light-carrying ray intensity I is attenuated with distance traveled x according to
Therefore, the attenuated per-channel intensity is
Evaluated on a per-channel basis, e.g., the color of white light after traveling unit distance is
)
Cornell CS4620/5620 Fall 2012 • Lecture 36 © 2012 Kavita Bala • 20 (with previous instructors James/Marschner) Not just for beer... [Josh | Wills 2003 UCSD Rendering Competition]
Cornell CS4620/5620 Fall 2012 • Lecture 36 © 2012 Kavita Bala • 21 (with previous instructors James/Marschner)
Shader for Transparent Objects (pp. 306-7)
Cornell CS4620/5620 Fall 2012 • Lecture 36 © 2012 Kavita Bala • 22 (with previous instructors James/Marschner) Basic ray traced image [Glassner 89]
Cornell CS4620/5620 Fall 2012 • Lecture 36 © 2012 Kavita Bala • 23 (with previous instructors James/Marschner)
Basic ray tracing
• Basic ray tracer: one sample for everything – one ray per pixel – one shadow ray for every point light – one reflection ray per intersection • one refraction ray (if necessary) per intersection • Many advanced methods build on the basic ray tracing paradigm
Cornell CS4620/5620 Fall 2012 • Lecture 36 © 2012 Kavita Bala • 24 (with previous instructors James/Marschner) Discontinuities in basic RT
• Perfectly sharp object silhouettes in image – leads to aliasing problems (stair steps) • Perfectly sharp shadow edges – everything looks like it’s in direct sun • Perfectly clear mirror reflections – reflective surfaces are all highly polished • Perfect focus at all distances – camera always has an infinitely tiny aperture • Perfectly frozen instant in time (in animation) – motion is frozen as if by strobe light
Cornell CS4620/5620 Fall 2012 • Lecture 36 © 2012 Kavita Bala • 25 (with previous instructors James/Marschner)
Antialiasing in ray tracing
aliased image
Cornell CS4620/5620 Fall 2012 • Lecture 36 © 2012 Kavita Bala • 26 (with previous instructors James/Marschner) Antialiasing in ray tracing
aliased image
one sample per pixel
Cornell CS4620/5620 Fall 2012 • Lecture 36 © 2012 Kavita Bala • 27 (with previous instructors James/Marschner)
Antialiasing in ray tracing
antialiased image
four samples per pixel
Cornell CS4620/5620 Fall 2012 • Lecture 36 © 2012 Kavita Bala • 28 (with previous instructors James/Marschner) Antialiasing in ray tracing
one sample/pixel 9 samples/pixel
Cornell CS4620/5620 Fall 2012 • Lecture 36 © 2012 Kavita Bala • 29 (with previous instructors James/Marschner)
Details of supersampling
• For image coordinates with integer pixel centers:
// one sample per pixel // ns^2 samples per pixel for iy = 0 to (ny-1) by 1 for iy = 0 to (ny-1) by 1 for ix = 0 to (nx-1) by 1 { for ix = 0 to (nx-1) by 1 { ray = camera.getRay(ix, iy); Color sum = 0; image.set(ix, iy, trace(ray)); for dx = -(ns-1)/2 to (ns-1)/2 by 1 } for dy = -(ns-1)/2 to (ns-1)/2 by 1 { x = ix + dx / ns; y = iy + dy / ns; ray = camera.getRay(x, y); sum += trace(ray); } image.set(ix, iy, sum / (ns*ns)); }
Cornell CS4620/5620 Fall 2012 • Lecture 36 © 2012 Kavita Bala • 30 (with previous instructors James/Marschner) Soft shadows
Cornell CS4620/5620 Fall 2012 • Lecture 36 © 2012 Kavita Bala • 31 (with previous instructors James/Marschner)
Cause of soft shadows
point lights cast hard shadows
Cornell CS4620/5620 Fall 2012 • Lecture 36 © 2012 Kavita Bala • 32 (with previous instructors James/Marschner) Cause of soft shadows
area lights cast soft shadows
Cornell CS4620/5620 Fall 2012 • Lecture 36 © 2012 Kavita Bala • 33 (with previous instructors James/Marschner)
Creating soft shadows
• For area lights: use many shadow rays – and each shadow ray gets a different point on the light • Choosing samples – general principle: start with uniform in square
Cornell CS4620/5620 Fall 2012 • Lecture 36 © 2012 Kavita Bala • 34 (with previous instructors James/Marschner) Creating soft shadows
Cornell CS4620/5620 Fall 2012 • Lecture 36 © 2012 Kavita Bala • 35 (with previous instructors James/Marschner)