Ray Tracing and Shading

Ray Tracing and Shading

1 Ray tracing and simple shading 15-468, 15-668, 15-868 Physics-based Rendering http://graphics.cs.cmu.edu/courses/15-468 Spring 2021, Lecture 3 2 Course announcements • Take-home quiz 1 will be posted tonight, Tuesday 2/9, and will be due a week later. • Programming assignment 1 will be posted on Friday 2/12, will be due two weeks later. - We will post an ungraded programming assignment 0 tomorrow, Wednesday 2/10. - Used to set up our rendering environment and github-based submission system. - Should take no more than 1 – 2 hours max. • Office hours for the rest of the semester: - Bailey, Tuesdays 3 – 5 pm ET. - Yannis, Thursdays 2 – 4 pm ET. - Zoom details on Piazza and Canvas. - Yannis may schedule additional office hours on Fridays. 3 Overview of today’s lecture • Leftover from previous lecture: intersections, meshes, acceleration structures. • Basics of shading. • Basic reflection models. 4 Slide credits Most of these slides were directly adapted from: • Wojciech Jarosz (Dartmouth). Recap: Raytracing Ray Generation Intersection Shading 5 Shading When ray hits a surface we perform lighting/shading Determine “what color/light should we see at this location?” Surfaces can scatter and/or emit light - Surface emits light? just return emitted color (determined by the material) - Surface scatters/reflects/refracts light? (recursively) trace a ray in a scattering direction (determined by the underlying material) 6 Overview Diffuse shading Specular reflection Refraction Diffuse emission 8 Light-material interactions 9 Real-world materials Metals Dielectric 10 Real-world materials Metals Dielectric 11 Light-material interactions 12 The BSDF Bidirectional Scattering Distribution Function - informally: how much the material scatters light coming from one direction l into some other direction v, at each point p 13 The BSDF Bidirectional Scattering Distribution Function - informally: how much the material scatters light coming from one direction l into some other direction v, at each point p You’ll also see BRDF R for reflectance 14 Idealized material models Diffuse reflection - light is reflected in all directions - colored by surface color Smooth specular reflection/refraction (e.g. chrome, glass, glaze/varnish) - light reflected/refracted only in a single direction - colored by source color 15 Idealized materials 16 Diffuse reflection 17 Diffuse reflection Real surface Lambertian reflection Also called ideal diffuse reflection Lambertian surface Basic Ray Tracing Pipeline diffuse object Ray Generation Intersection light scatters towards multiple directions Shading What direction should we trace a new ray towards? 20 Basic Ray Tracing Pipeline diffuse object Ray Generation Intersection light scatters towards multiple directions Shading What direction should we trace a new ray towards? • Pick a direction at random! 21 Sampling Lambertian scattering From what distribution should we sample directions? 22 Sampling Lambertian scattering From what distribution should we sample directions? - Probability proportional to cos( · ). - Even though BSDF scatters to all directions uniformly, we � � need to account for foreshortening. How do we sample directions based on this cosine-weighted distribution? 23 Sampling Lambertian scattering Generate points on sphere (unit directions) 24 Sampling Lambertian scattering Generate points on sphere Add unit normal (unit directions) unit normal 25 Sampling Lambertian scattering Generate points on sphere Add unit normal (unit directions) normalize unit normal 26 Rejection Sampling a Sphere Vector3D v; v.x = 1-2*randf(); v.y = 1-2*randf(); v.z = 1-2*randf(); 27 Rejection Sampling a Sphere Vector3D v; do { v.x = 1-2*randf(); v.y = 1-2*randf(); v.z = 1-2*randf(); } while(v.length2() > 1) 28 Rejection Sampling a Sphere Vector3D v; do { v.x = 1-2*randf(); v.y = 1-2*randf(); v.z = 1-2*randf(); } while(v.length2() > 1) 29 Rejection Sampling a Sphere Vector3D v; do { v.x = 1-2*randf(); v.y = 1-2*randf(); v.z = 1-2*randf(); } while(v.length2() > 1) // Project onto sphere v /= v.length(); 30 Sampling a Sphere using normal samples Vector3D v; v.x = randnf(); v.y = randnf(); v.z = randnf(); // Project onto sphere v /= v.length(); • No rejection sampling required (no while loop). • Need to use normal, rather than uniform, samples. 31 Diffuse shading After a slide by Steve Marschner Steve by slide a After 32 Image so far Scene::trace(Ray ray) hit = surfaces.intersect(ray); if hit [col, sRay] = hit->mat->scatter(ray) return col * trace(sRay); else return backgroundColor; 33 Rounding errors Don’t fall victim to one of the classic blunders: affectionately called “shadow acne” What’s going on? After a slide by Steve Marschner Steve by slide a After - hint: at what t does a recursive ray intersect the surface you’re shading? 34 Rounding errors Don’t fall victim to one of the classic blunders: intersection inside ray blocked by due to floating point self-intersection After a slide by Steve Marschner Steve by slide a After error 35 Shadow rounding errors Solution: recursive rays start a tiny distance from the surface Do this by limiting the t range After a slide by Steve Marschner Steve by slide a After 36 Specular/Mirror reflection 37 Mirror reflection Evaluated by tracing a new ray: reflected recursive light reflection scaled call down/tinted 38 Basic Ray Tracing Pipeline specular object Ray Generation Intersection light reflects towards only one direction Shading What direction should we trace a new ray towards? • Just use law of mirror reflection, no need for random selection! 39 Mirror reflection Consider perfectly shiny surface - 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?” 40 Mirror reflection Evaluated by tracing a new ray: reflected recursive light reflection scaled call down/tinted Implementation details: - don’t self-intersect (tmin > ϵ) - don’t recurse indefinitely 41 Diffuse & mirror spheres 42 Same pseudo-code Scene::trace(Ray ray) hit = surfaces.intersect(ray); if hit [col, sRay] = hit->mat->scatter(ray) return col * trace(sRay); else return backgroundColor; 43 Mirror reflection Assume n is unit length reflected direction view direction What two properties defined reflection direction? 44 Mirror reflection Assume n is unit length reflected direction view direction What two properties defined reflection direction? - co-planar view direction, reflected direction, and normal direction - equal angles between normal-view directions, and normal-reflected directions 45 Mirror reflection Assume n is unit length reflected direction view direction 46 Mirror reflection reflected direction view direction 47 Mirror reflection reflected direction view direction 48 Mirror reflection reflected direction view direction 49 Mirror reflection Assumes n is unit length reflected direction view direction 50 Specular refraction 51 Refraction 52 Refraction 53 Index of Refraction Speed of light in vacuum / speed of light in medium Some values of Vacuum 1 Air at STP 1.00029 Ice 1.31 Water 1.33 Crown glass 1.52 - 1.65 Diamond 2.417 54 Specular transmission/refraction Materials like water, glass, etc., also refract/blend light Trace a recursive ray in the refraction direction refracted recursive light refraction call scaled down 55 Specular transmission/refraction Snell’s law reflected direction view direction refracted direction refracted direction 56 Specular transmission/refraction Snell’s law reflected direction view direction refracted direction 57 Index of Refraction Speed of light in vacuum / speed of light in medium Some values of Vacuum 1 Air at STP 1.00029 Ice 1.31 Water 1.33 Crown glass 1.52 - 1.65 Diamond 2.417 These are actually wavelength dependent! 58 Dispersion 59 Refraction in a Waterdrop 60 Double rainbow all the way across the sky! 61 Dispersion: “Halos” and “Sun dogs” 62 Halos and Sundogs Dispersion 64 Practical consequences of refraction What is this dark circle? source: mrreid.org 66 What is this dark circle? Called “Snell's window” Caused by total internal reflection source: mrreid.org 67 Recall… Snell’s law reflected direction view direction refracted direction 68 Total Internal Reflection source: mrreid.org 69 Total Internal Reflection 70 Total Internal Reflection Can only happen when the ray starts in the higher index medium 71 Total Internal Reflection 72 Total Internal Reflection source: imgur.com 73 Reflection vs. Refraction How much light is reflected vs. refracted? - in reality determined by “Fresnel equations” reflected direction view direction refracted direction 74 Fresnel Equations Reflection and refraction from smooth dielectric (e.g. glass) surfaces Reflection from conducting (e.g. metal) surfaces Derived from Maxwell equations Involves polarization of the wave 75 Fresnel Equations for Dielectrics Reflection of light polarized parallel and perpendicular to the plane of refraction reflected: refracted: 76 What’s happening in this photo? source: flickr user neofob 77 Polarizing Filter 78 Polarization Without Polarizer With Polarizing Filter source: photography.ca 79 Polarization Without Polarizer With Polarizing Filter source: wikipedia 80 Effect of Polarization Effect of Polarization Fresnel Equations for Dielectrics Reflection of light polarized parallel and perpendicular to the plane of refraction reflected: refracted: - The Shirley book uses a faster approximation (Schlick), but to get full accuracy you’d need to use these equations 83 Fresnel equations

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    103 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us