infogr computer graphics
play

INFOGR Computer Graphics Jacco Bikker & Debabrata Panja - - PowerPoint PPT Presentation

INFOGR Computer Graphics Jacco Bikker & Debabrata Panja - April-July 2017 Lecture 3: Ray Tracing Welcome! Todays Agenda: Ray Tracing Intersections Shading Assignment 2 Textures INFOGR Lecture 3


  1. INFOGR – Computer Graphics Jacco Bikker & Debabrata Panja - April-July 2017 Lecture 3: “Ray Tracing” Welcome!

  2. Today’s Agenda: Ray Tracing  Intersections  Shading  Assignment 2  Textures 

  3. INFOGR – Lecture 3 – “Ray Tracing” 4 Ray Tracing PART 1: Introduction & shading (today) PART 2: Reflections, refraction, absorption (next week) PART 3: Path Tracing (later)

  4. INFOGR – Lecture 3 – “Ray Tracing” 5 Ray Tracing Ray Tracing: World space  Geometry  Eye  Screen plane  Screen pixels  Primary rays  Intersections  Point light  Shadow rays Light transport  Extension rays Light transport

  5. INFOGR – Lecture 3 – “Ray Tracing” 6 Ray Tracing Ray Tracing: World space  Geometry  Eye  Screen plane  Screen pixels  Primary rays  Intersections  Point light  Shadow rays Light transport  Extension rays Light transport

  6. INFOGR – Lecture 8 – “Ray Tracing” Ray Tracing

  7. INFOGR – Lecture 3 – “Ray Tracing” 8 Ray Tracing Ray Tracing: World space  Geometry  Eye  Screen plane  Screen pixels  Primary rays  Intersections  Point light  Shadow rays Note: Light transport We are calculating  Extension rays light transport backwards. Light transport

  8. INFOGR – Lecture 8 – “Ray Tracing” Ray Tracing

  9. INFOGR – Lecture 3 – “Ray Tracing” 10 Ray Tracing

  10. INFOGR – Lecture 3 – “Ray Tracing” 11 Ray Tracing

  11. INFOGR – Lecture 3 – “Ray Tracing” 12 Ray Tracing Physical basis Ray tracing uses ray optics to simulate the behavior of light in a virtual environment. It does so by finding light transport paths:  From the ‘eye’  Through a pixel  Via scene surfaces  To one or more light sources. At each surface, the light is modulated. The final value is deposited at the pixel (simulating reception by a sensor). T. Whitted , “An Improved Illumination Model for Shaded Display”, ACM, 1980.

  12. Today’s Agenda: Ray Tracing  Intersections  Shading  Assignment 2  Textures 

  13. INFOGR – Lecture 3 – “Ray Tracing” 14 Intersections Ray definition A ray is an infinite line with a start point: 𝑞(𝑢) = 𝑃 + 𝑢𝐸 , where 𝑢 > 0 . struct Ray { float3 O; // ray origin float3 D; // ray direction float t; // distance }; The ray direction is generally normalized .

  14. INFOGR – Lecture 3 – “Ray Tracing” 15 Intersect Ray setup Only if 𝑊 = (0,0,1) of course. A ray is initially shot through a pixel on the screen plane. The screen plane is defined in world space: Camera position: E = (0,0,0) View direction: 𝑊 Screen center: C = 𝐹 + 𝑒𝑊 Screen corners: p 0 = 𝐷 + −1, −1,0 , 𝑞 1 = 𝐷 + 1, −1,0 , 𝑞 2 = 𝐷 + (−1,1,0) From here:  Change FOV by altering 𝑒 ;  Transform camera by multiplying E, 𝑞 0 , 𝑞 1 , 𝑞 2 with the camera matrix.

  15. INFOGR – Lecture 3 – “Ray Tracing” 16 Intersect Ray setup 𝑞 0 Point on the screen: 𝑞 1 𝑞 𝑣, 𝑤 = 𝑞 0 + 𝑣 𝑞 1 − 𝑞 0 + 𝑤(𝑞 2 − 𝑞 0 ) , 𝑣, 𝑤 ∈ [0,1) Ray direction (before normalization): 𝐹 𝐸 = 𝑞 𝑣, 𝑤 − 𝐹 𝑞 2 − 𝑞 0 Ray origin: 𝑃 = 𝐹 𝑞 2

  16. INFOGR – Lecture 3 – “Ray Tracing” 17 Intersect Ray intersection 𝑞 0 Given a ray 𝑞(𝑢) = 𝑃 + 𝑢𝐸 , we determine the smallest intersection distance 𝑢 by intersecting the 𝑞 1 ray with each of the primitives in the scene. Ray / plane intersection: 𝐹 Plane: p ∙ 𝑂 + 𝑒 = 0 Ray: 𝑞(𝑢) = 𝑃 + 𝑢𝐸 Substituting for 𝑞(𝑢) , we get 𝑞 2 𝑃 + 𝑢𝐸 ∙ 𝑂 + 𝑒 = 0 𝑢 = −(𝑃 ∙ 𝑂 + 𝑒)/(𝐸 ∙ 𝑂) 𝑄 = 𝑃 + 𝑢𝐸

  17. INFOGR – Lecture 3 – “Ray Tracing” 18 Intersect Ray intersection 𝑞 0 Ray / sphere intersection: 𝑞 1 Sphere: 𝑞 − 𝐷 ∙ 𝑞 − 𝐷 − 𝑠 2 = 0 Ray: 𝑞(𝑢) = 𝑃 + 𝑢𝐸 𝐹 Substituting for 𝑞(𝑢) , we get 𝑃 + 𝑢𝐸 − 𝐷 ∙ 𝑃 + 𝑢𝐸 − 𝐷 − 𝑠 2 = 0 𝐸 ∙ 𝐸 𝑢 2 + 2𝐸 ∙ 𝑃 − 𝐷 𝑢 + (𝑃 − 𝐷) 2 −𝑠 2 = 0 𝑞 2 𝑐 2 − 4𝑏𝑑 𝑏𝑦 2 + 𝑐𝑦 + 𝑑 = 0 → 𝑦 = −𝑐 ± 2𝑏 𝑏 = 𝐸 ∙ 𝐸 Negative: 𝑐 = 2𝐸 ∙ (𝑃 − 𝐷) no intersections 𝑑 = 𝑃 − 𝐷 ∙ 𝑃 − 𝐷 − 𝑠 2

  18. INFOGR – Lecture 3 – “Ray Tracing” 19 Intersect 𝐸 Ray Intersection Efficient ray / sphere intersection: void Sphere::IntersectSphere( Ray ray ) { vec3 c = this.pos - ray.O; float t = dot( c, ray.D ); vec3 q = c - t * ray.D; float p 2 = dot( q, q ); if (p 2 > sphere.r 2 ) return; t t -= sqrt( sphere.r 2 – p 2 ); 𝑑 if ((t < ray.t) && (t > 0)) ray.t = t; // or: ray.t = min( ray.t, max( 0, t ) ); 𝑟 } O Note: 𝑞 2 This only works for rays that start outside the sphere.

  19. Today’s Agenda: Ray Tracing  Intersections  Shading  Assignment 2  Textures 

  20. INFOGR – Lecture 3 – “Ray Tracing” 21 Shading

  21. INFOGR – Lecture 3 – “Ray Tracing” 22 Shading The End We used primary rays to find the primary intersection point. Determining light transport:  Sum illumination from all light sources  …If they are visible . We used a primary ray to find the object visible through a pixel: Now we will use a shadow ray to determine visibility of a light source.

  22. INFOGR – Lecture 3 – “Ray Tracing” 23 Shading 𝑄 𝑚𝑗𝑕ℎ𝑢 Shadow Ray Constructing the shadow ray: 𝑞(𝑢) = 𝑃 + 𝑢𝐸 Ray origin: the primary intersection point 𝐽 . 𝐽 Ray direction: 𝑄 𝑚𝑗𝑕ℎ𝑢 − 𝐽 (normalized) Restrictions on 𝑢 : 0 < 𝑢 < | 𝑄 𝑚𝑗𝑕ℎ𝑢 − 𝐽 |

  23. INFOGR – Lecture 3 – “Ray Tracing” 24 Shading 𝑄 𝑚𝑗𝑕ℎ𝑢 Shadow Ray 𝑄 𝑚𝑗𝑕ℎ𝑢 −𝐽 Direction of the shadow ray: | 𝑄 𝑚𝑗𝑕ℎ𝑢 −𝐽 | 𝐽−𝑄 𝑚𝑗𝑕ℎ𝑢 𝐽−𝑄 𝑚𝑗𝑕ℎ𝑢 Equally valid: | 𝑄 𝑚𝑗𝑕ℎ𝑢 −𝐽 | or | 𝐽−𝑄 𝑚𝑗𝑕ℎ𝑢 | 𝐽 Note that we get different intersection points depending on the direction of the shadow ray. It doesn’t matter: the shadow ray is used to determine if there is an occluder, not where . This has two consequences: 1. We need a dedicated shadow ray query; 2. Shadow ray queries are (on average) twice as fast. (w (why?)

  24. INFOGR – Lecture 3 – “Ray Tracing” 25 Shading Shadow Ray “In theory, theory and practice are the same. In practice, they are not.” Problem 1: Our shadow ray queries report intersections at 𝑢 = ~0 . Why? Cause: the shadow ray sometimes finds the surface it originated from as an occluder, resulting in shadow acne . Fix: offset the origin by ‘epsilon’ times the shadow ray direction. Note: don’t forget to reduce 𝑢 𝑛𝑏𝑦 by epsilon.

  25. INFOGR – Lecture 3 – “Ray Tracing” 26 Shading Shadow Ray “In theory, theory and practice are the same. In practice, they are not.” Problem 2: Our shadow ray queries report intersections at 𝑢 = 𝑢 𝑛𝑏𝑦 . Why? Cause: when firing shadow rays from the light source, they may find the surface that we are trying to shade. Fix: reduce 𝑢 m𝑏x by 2 ∗ 𝑓𝑞𝑡𝑗𝑚𝑝𝑜 .

  26. INFOGR – Lecture 3 – “Ray Tracing” 27 Shading Shadow Ray “The most expensive shadow rays are those that do not find an intersection.” Why? (because those rays tested every primitive before concluding that there was no occlusion)

  27. INFOGR – Lecture 3 – “Ray Tracing” 28 Shading Transport The amount of energy travelling from the light via the surface point to the eye depends on:  The brightness of the light source  The distance of the light source to the surface point  Absorption at the surface point  The angle of incidence of the light energy

  28. INFOGR – Lecture 3 – “Ray Tracing” 29 Shading Transport Brightness of the light source: Expressed in watt (W) , or joule per second ( 𝐾/𝑡 or 𝐾𝑡 −1 ) . Energy is transported by photons. Photon energy depends on wavelength; energy for a ‘yellow’ photon is ~3.31 ∙ 10 −19 J. A 100W light bulb thus emits ~3.0 ∙ 10 21 photons per second.

  29. INFOGR – Lecture 3 – “Ray Tracing” 30 Shading Transport Energy at distance 𝑠 : For a point light, a brief pulse of light energy spreads out as a growing sphere. The energy is distributed over the surface of this sphere. It is therefore proportional to the inverse area of the sphere at distance 𝑠 , i.e.: 1 𝐹/𝑛 2 = 𝐹 𝑚𝑗𝑕ℎ𝑢 4𝜌𝑠 2 Light energy thus dissipates at a rate of 1 𝑠 2 . This is referred to as distance attenuation .

  30. INFOGR – Lecture 3 – “Ray Tracing” 31 Shading Transport Absorption: Most materials absorb light energy. The wavelengths that are not fully absorbed define the ‘color’ of a material. The reflected light is thus: 𝐹 𝑠𝑓𝑔𝑚𝑓𝑑𝑢𝑓𝑒 = 𝐹 𝑗𝑜𝑑𝑝𝑛𝑗𝑜𝑕 ∙ 𝐷 𝑛𝑏𝑢𝑓𝑠𝑗𝑏𝑚 Note that 𝐷 𝑛𝑏𝑢𝑓𝑠𝑗𝑏𝑚 cannot exceed 1; the reflected light is never more than the incoming light.

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend