welcome today s agenda
play

Welcome! Todays Agenda: Primitives (contd.) Ray Tracing - PowerPoint PPT Presentation

INFOGR Computer Graphics Jacco Bikker - April-July 2016 - Lecture 3: Ray Tracing (Introduction) Welcome! Todays Agenda: Primitives (contd.) Ray Tracing Intersections Assignment 2 Textures INFOGR


  1. INFOGR – Computer Graphics Jacco Bikker - April-July 2016 - Lecture 3: “Ray Tracing (Introduction)” Welcome!

  2. Today’s Agenda: Primitives (contd.)  Ray Tracing  Intersections  Assignment 2  Textures 

  3. INFOGR – Lecture 2 – “Graphics Fundamentals” 3 Previously in INFOGR

  4. INFOGR – Lecture 3 – “Ray Tracing (Introduction)” 4 Primitives Implicit curves: 𝑔 𝑦, 𝑧 = 0 𝑦 2 + 𝑧 2 − 𝑠 2 = 0 Circle: Line: 𝐵𝑦 + 𝐶𝑧 + 𝐷 = 0 Slope-intersect form of a line: 𝑧 = 𝑏𝑦 + 𝑑 Normal of line 𝐵𝑦 + 𝐶𝑧 + 𝐷 = 0 : 𝑂 = 𝐵 𝐶 Distance of line 𝐵𝑦 + 𝐶𝑧 + 𝐷 = 0 to the origin: |𝐷| (if 𝑂 = 1 ).

  5. INFOGR – Lecture 3 – “Ray Tracing (Introduction)” 5 Primitives Parametric representation p 1 Parametric curve: 𝑦 𝑧 = 𝑕(𝑢) ℎ(𝑢) In this example: Example: line p 0 𝑞 0 is the support vector; 𝑞 0 = 𝑦 𝑞 0 , 𝑧 𝑞 0 , 𝑞 1 = (𝑦 𝑞 1 , 𝑧 𝑞 1 ) 𝑞 1 − 𝑞 0 is the direction 𝑦 𝑞 0 𝑦 𝑞 1 − 𝑦 𝑞 0 𝑦 vector. 𝑧 = + 𝑢 𝑧 𝑞 0 𝑧 𝑞 1 − 𝑧 𝑞 0 Or 𝑞 𝑢 = 𝑞 0 + 𝑢 𝑞 1 − 𝑞 0 , 𝑢 ∈ ℝ.

  6. INFOGR – Lecture 3 – “Ray Tracing (Introduction)” 6 Primitives Slope-intercept: p 1 𝑧 = 𝑏𝑦 + 𝑑 ∆𝑧 Implicit representation: ∆𝑦 −𝑏𝑦 + 𝑧 − 𝑑 = 0 𝐵𝑦 + 𝐶𝑧 + 𝐷 = 0 p 0 Parametric representation: 𝑞 𝑢 = 𝑞 0 + 𝑢 𝑞 1 − 𝑞 0

  7. INFOGR – Lecture 3 – “Ray Tracing (Introduction)” 7 Primitives Circle - parametric 𝑦 𝑧 = 𝑦 𝑑 + 𝑠 cos 𝜚 𝑧 𝑑 + 𝑠 sin 𝜚 𝜚 = “phi” cos 𝜚 = 𝑦 𝜚 𝑠 c 𝑡𝑗𝑜 𝜚 = 𝑧 𝑠 𝑠 𝑧 opposite 𝑢𝑏𝑜 𝜚 = 𝑧 𝑦 𝜚 SOH CAH TOA adjacent 𝑦

  8. INFOGR – Lecture 3 – “Ray Tracing (Introduction)” 8 Primitives 𝑞 Circle – sphere (implicit) c Recall: the implicit representation for a circle with radius 𝑠 and center 𝑑 is: 𝑦 − 𝑑 𝑦 2 + 𝑧 − 𝑑 𝑧 2 − 𝑠 2 = 0 or: ∥ p − c ∥ 2 − 𝑠 2 = 0  ∥ 𝑞 − 𝑑 ∥ = 𝑠 In ℝ 3 , we get: 2 + 𝑧 − 𝑑 𝑧 2 + 𝑨 − 𝑑 𝑨 2 − 𝑠 2 = 0 𝑦 − 𝑑 𝑦 or: ∥ 𝑞 − 𝑑 ∥= 𝑠

  9. INFOGR – Lecture 3 – “Ray Tracing (Introduction)” 9 Primitives Line – plane (implicit) p 2 Recall: the implicit representation for a line is: 𝐵𝑦 + 𝐶𝑧 + 𝐷 = 0 In ℝ 3 , we get a plane: 𝐵𝑦 + 𝐶𝑧 + 𝐷𝑨 + 𝐸 = 0 p 1

  10. INFOGR – Lecture 3 – “Ray Tracing (Introduction)” 10 Primitives Parametric surfaces A parametric surface in ℝ 3 needs two parameters: 𝜄 𝑦 = 𝑔(𝑣, 𝑤) , 𝑧 = 𝑕(𝑣, 𝑤) , 𝑨 = ℎ(𝑣, 𝑤) . For example, a sphere: 𝜚 𝑦 = 𝑠 cos 𝜚 sin 𝜄 , 𝑧 = 𝑠 sin 𝜚 sin 𝜄 , 𝑨 = 𝑠 cos 𝜄. Doesn’t look very convenient (compared to the implicit form), but it will prove useful for texture mapping.

  11. INFOGR – Lecture 3 – “Ray Tracing (Introduction)” 11 Primitives Parametric planes 𝑞 0 𝑤 Recall the parametric line definition: 𝑞 𝑢 = 𝑞 0 + 𝑢 𝑞 1 − 𝑞 0 𝑥 For a plane, we need to parameters: y 𝑞 𝑡, 𝑢 = 𝑞 0 + 𝑡 𝑞 1 − 𝑞 0 + 𝑢(𝑞 2 − 𝑞 0 ) or: x 𝑞 𝑡, 𝑢 = 𝑞 0 + 𝑡 𝑤 + 𝑢𝑥 z where:  𝑞 0 is a point on the plane; 𝑤 and 𝑥 are two linearly independent  vectors on the plane;  𝑡, 𝑢 ∈ ℝ .

  12. Today’s Agenda: Primitives (contd.)  Ray Tracing  Intersections  Assignment 2  Textures 

  13. INFOGR – Lecture 3 – “Ray Tracing (Introduction)” 14 Ray Tracing PART 1: Introduction (today) PART 2: Shading (May 10) PART 3: Reflections, refraction, absorption (May 17) PART 4: Path Tracing (June 21)

  14. INFOGR – Lecture 3 – “Ray Tracing (Introduction)” 15 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

  15. INFOGR – Lecture 3 – “Ray Tracing (Introduction)” 16 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

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

  17. INFOGR – Lecture 3 – “Ray Tracing (Introduction)” 18 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

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

  19. INFOGR – Lecture 3 – “Ray Tracing (Introduction)” 20 Ray Tracing

  20. INFOGR – Lecture 3 – “Ray Tracing (Introduction)” 21 Ray Tracing

  21. INFOGR – Lecture 3 – “Ray Tracing (Introduction)” 22 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).

  22. Today’s Agenda: Primitives (contd.)  Ray Tracing  Intersections  Assignment 2  Textures 

  23. INFOGR – Lecture 3 – “Ray Tracing (Introduction)” 24 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 .

  24. INFOGR – Lecture 3 – “Ray Tracing (Introduction)” 25 Intersect Ray setup 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.

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

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

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

  28. INFOGR – Lecture 3 – “Ray Tracing (Introduction)” 29 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 p2 = dot( q, q ); if (p2 > sphere.r2) return; t t -= sqrt( sphere.r2 – p2 ); 𝑑 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.

  29. Today’s Agenda: Primitives (contd.)  Ray Tracing  Intersections  Assignment 2  Textures 

  30. INFOGR – Lecture 3 – “Ray Tracing (Introduction)” 31 Assignment 2 Deadline assignment 1: Wednesday May 11, 23.59 Assignment 2: ”Write a basic ray tracer.”  Using the template  In a 1024x512 window  Two views, each 512x512  Left view: 3D  Right view: 2D slice

Recommend


More recommend