Download presentation

Presentation is loading. Please wait.

Published byDevon Alvin Modified over 2 years ago

1
1 Ray Tracing Mani Thomas CISC 440/640 Computer Graphics

2
2 Photo-Realism Created by David Derman – CISC 440

3
3 Created by Jan Oberlaender – CISC 640

4
4

5
5 Created by Donald Hyatt

6
6 Bunny – A computer animated short film Blue Sky Studios Inc A film by Chris Wedge with music by Tom Waits and produced by Nina Rappaport

7
7 Introduction - Light Three Ideas about light Three Ideas about light Light rays travel in straight lines Light rays travel in straight lines Light rays do not interfere with each other if they cross Light rays do not interfere with each other if they cross Light rays travel from light source to the eye, but the physics is invariant under path reversal (Helmholtz reciprocity) Light rays travel from light source to the eye, but the physics is invariant under path reversal (Helmholtz reciprocity) P. Sen, et al., “Dual Photography”, SIGGRAPH 2005 P. Sen, et al., “Dual Photography”, SIGGRAPH 2005 Novel photographic technique to interchange the lights and cameras in a scene Novel photographic technique to interchange the lights and cameras in a scene

8
8 Introduction - Ray tracing What is Ray Tracing? What is Ray Tracing? Ray Tracing is a global illumination based rendering method for generating realistic images on the computer Ray Tracing is a global illumination based rendering method for generating realistic images on the computer Originators Originators Appel 1968 Appel 1968 Goldstein and Nagel Goldstein and Nagel Whited 1979 Whited 1979 Courtesy of Pat Hanrahan, Computer Graphics: Image Synthesis Techniques

9
9 Introduction – Ray tracing Appel Appel Ray Casting Goldstein and Nagel Goldstein and Nagel Scene Illumination Whited Whited Recursive ray tracing (reflection and refraction) Forward and Backward Ray tracing Courtesy of Pat Hanrahan, Computer Graphics: Image Synthesis Techniques

10
10 Introduction – Ray tracing Forward Ray tracing Forward Ray tracing Rays from light source bounce of objects before reaching the camera Computational wastage Backward Ray tracing Backward Ray tracing Track only those rays that finally made it to the camera Courtesy: Angel

11
11 Ray Casting Ray Casting Ray Casting visible surfaces of objects are found by throwing (or casting) rays of light from the viewer into the scene Ray Tracing Ray Tracing Extension to Ray casting Recursively cast rays from the points of intersection Courtesy: Angel

12
12 Ray casting In ray casting, a ray of light is traced in a backwards direction. In ray casting, a ray of light is traced in a backwards direction. We start from the eye or camera and trace the ray through a pixel in the image plane into the scene and determine what it intersects We start from the eye or camera and trace the ray through a pixel in the image plane into the scene and determine what it intersects The pixel is then set to the color values returned by the ray. The pixel is then set to the color values returned by the ray. If the ray misses all objects, then that pixel is shaded the background color If the ray misses all objects, then that pixel is shaded the background color

13
13 Algorithm – Ray casting Courtesy F.S. Hill, “Computer Graphics using OpenGL”

14
14 Ray tracing - overview Ray casting finds the visible surfaces of objects Ray casting finds the visible surfaces of objects Ray tracing determines what each visible surface looks like Ray tracing determines what each visible surface looks like This extra curiosity is quite heavy on your processor This extra curiosity is quite heavy on your processor But it allows you to create effects that are very difficult or even impossible to do using other methods. But it allows you to create effects that are very difficult or even impossible to do using other methods. Reflection Reflection Transparency Transparency Shadows Shadows Courtesy:

15
15 Ray tracing - overview Ray tracing algorithm is a “finitely” recursive image rendering Ray tracing algorithm is a “finitely” recursive image rendering First stage: Like ray casting First stage: Like ray casting Shoot a ray from the eye (Primary ray) Shoot a ray from the eye (Primary ray) Determine all the objects that intersect the ray Determine all the objects that intersect the ray Find the nearest of intersections Find the nearest of intersections Second stage: Second stage: Recurses by shooting more rays from the point of intersection (Secondary rays) Recurses by shooting more rays from the point of intersection (Secondary rays) Find the objects that are reflected at that point Find the objects that are reflected at that point Find other objects that may be seen through the object at that point Find other objects that may be seen through the object at that point Find out light sources that are directly visible from that point Find out light sources that are directly visible from that point Repeat the second stage until required Repeat the second stage until required

16
16 Ray Tracing – example Sometimes a ray misses all objects Sometimes a ray misses all objects created by Michael Sweeny, et al for ACM SIGGRAPH Education slide set 1991

17
17 Ray Tracing – example Sometimes a ray hits an object Sometimes a ray hits an object created by Michael Sweeny, et al for ACM SIGGRAPH Education slide set 1991

18
18 Ray Tracing – example Is the intersected point in shadow? Is the intersected point in shadow? “Shadow Rays” to light source “Shadow Rays” to light source created by Michael Sweeny, et al for ACM SIGGRAPH Education slide set 1991

19
19 Ray Tracing – example Shadow rays intersect another object Shadow rays intersect another object First intersection point in shadow of the second object First intersection point in shadow of the second object created by Michael Sweeny, et al for ACM SIGGRAPH Education slide set 1991

20
20 Ray Tracing – example Shadow rays intersect another object Shadow rays intersect another object First intersection point in shadow of the second object First intersection point in shadow of the second object created by Michael Sweeny, et al for ACM SIGGRAPH Education slide set 1991

21
21 Ray Tracing - example Reflected ray generated at point of intersection Reflected ray generated at point of intersection Tested with all the objects in the scene Tested with all the objects in the scene created by Michael Sweeny, et al for ACM SIGGRAPH Education slide set 1991

22
22 Ray Tracing - example Local illumination model applied at the point of intersection Local illumination model applied at the point of intersection created by Michael Sweeny, et al for ACM SIGGRAPH Education slide set 1991

23
23 Ray Tracing – example Transparent object Transparent object Spawn a transmitted ray and test against all objects in the scene Spawn a transmitted ray and test against all objects in the scene created by Michael Sweeny, et al for ACM SIGGRAPH Education slide set 1991

24
24 Requirements for Ray tracing Compute 3D ray into the scene for each 2D image pixel Compute 3D ray into the scene for each 2D image pixel Compute 3D intersection point of ray with nearest object in scene Compute 3D intersection point of ray with nearest object in scene Test each primitive in the scene for intersection Test each primitive in the scene for intersection Find nearest intersection Find nearest intersection Recursively spawn rays from the point of intersection Recursively spawn rays from the point of intersection Shadow Rays Shadow Rays Reflected rays Reflected rays Transmitted rays Transmitted rays Accumulate the color from each of the spawned rays at the point of intersection Accumulate the color from each of the spawned rays at the point of intersection

25
25 Ray object intersection Equation of a ray Equation of a ray “S” is the starting point and “c” is the direction of the ray “S” is the starting point and “c” is the direction of the ray Given a surface in implicit form F(x,y,z) Given a surface in implicit form F(x,y,z) plane: plane: sphere: sphere: cylinder: cylinder: All points on the surface satisfy F(x,y,z)=0 All points on the surface satisfy F(x,y,z)=0 Thus for ray r(t) to intersect the surface Thus for ray r(t) to intersect the surface The hit time can be got by solving The hit time can be got by solving

26
26 Ray object intersection 3D Object Intersection:

27
27 Ray plane intersection Equation of a ray Equation of a ray Equation of a plane Equation of a plane n is the normal to the plane and d is the distance of the plane from the origin n is the normal to the plane and d is the distance of the plane from the origin Substituting and solving for t Substituting and solving for t

28
28 Ray triangle intersection Tomas Möller and Ben Trumbore, “Fast, minimum storage ray-triangle intersection”, Journal of graphics tools, 2(1):21-28, 1997 Tomas Möller and Ben Trumbore, “Fast, minimum storage ray-triangle intersection”, Journal of graphics tools, 2(1):21-28, 1997 Barycentric coordinates Barycentric coordinates p is a point in a triangle with vertices P 0, P 1, P 2 p is a point in a triangle with vertices P 0, P 1, P 2 If r(t) belongs to both the line and triangle If r(t) belongs to both the line and triangle Solve for (t, u, v) Solve for (t, u, v) If (u, v) complies with the restriction, then ray r(t) intersects the triangle If (u, v) complies with the restriction, then ray r(t) intersects the triangle Using t the intersection point can be easily computed Using t the intersection point can be easily computed Courtesy of

29
29 Ray triangle intersection R. J. Segura, F. R. Feito,”Algorithms to test Ray-triangle Intersection Comparative Study”, WSCG 2001 Courtesy of

30
30 Ray Sphere intersection Implicit form of sphere given center (a,b,c) and radius r Implicit form of sphere given center (a,b,c) and radius r Intersection with r(t) gives Intersection with r(t) gives By the identity By the identity the intersection equation is a quadratic in “t” the intersection equation is a quadratic in “t” Solving for “t” Solving for “t” Real solutions, indicate one or two intersections Real solutions, indicate one or two intersections Negative solutions are behind the eye Negative solutions are behind the eye If discriminant is negative, the ray missed the sphere If discriminant is negative, the ray missed the sphere

31
31 Adding shadows P is not in shadow with respect to L 1 P is not in shadow with respect to L 1 P is in the shadow of the cube with respect to L 2 P is in the shadow of the cube with respect to L 2 “Self-shadowing” of P with respect to L 3 “Self-shadowing” of P with respect to L 3 “Shadow Feelers” “Shadow Feelers” Spawn a ray from P to the light sources Spawn a ray from P to the light sources If there is an intersection of the shadow ray with any object then P is in shadow If there is an intersection of the shadow ray with any object then P is in shadow NOTE: Intersection should be between the point and light source and not behind light source Courtesy F.S. Hill, “Computer Graphics using OpenGL”

32
32 Adding shadows “Self-Shadowing” “Self-Shadowing” Always an intersection of shadow feeler with object itself Always an intersection of shadow feeler with object itself Move start point of the shadow ray towards the eye by a small amount Move start point of the shadow ray towards the eye by a small amount No intersection with itself No intersection with itself Courtesy F.S. Hill, “Computer Graphics using OpenGL”

33
33 Reflection Given surface normal “n” and incident ray “a” find the reflected ray “r” Given surface normal “n” and incident ray “a” find the reflected ray “r” adapted from F.S. Hill, “Computer Graphics using OpenGL”

34
34 Reflection Created by David Derman – CISC 440

35
35 Reflection Created by David Derman – CISC 440

36
36 Reflection Created by David Derman – CISC 440

37
37 Reflection Created by David Derman – CISC 440

38
38 Refraction Bending of light rays as it crosses interface between media having different refractive indices Bending of light rays as it crosses interface between media having different refractive indices Snell’s Law Snell’s Law c 1,c 2 – Refractive index Courtesy F.S. Hill, “Computer Graphics using OpenGL”

39
39 Refraction Estimation the refracted ray T, given u and N (unit vectors) Estimation the refracted ray T, given u and N (unit vectors) If we assume that n i and n r are the refractive indices of the medium having the incoming ray and refracted ray respectively If we assume that n i and n r are the refractive indices of the medium having the incoming ray and refracted ray respectively Let and be the corresponding angle of incidence and refraction Let and be the corresponding angle of incidence and refraction Let k be a unit vector perpendicular to N Let k be a unit vector perpendicular to N By Snell’s Law we have By Snell’s Law we have Adapted from Hearn and Baker, “Computer Graphics with openGL”

40
40 Refraction Decomposing the incident ray (u) Decomposing the incident ray (u) Decomposing the refracted ray (T) Decomposing the refracted ray (T) Solving for k from u Solving for k from u Adapted from Hearn and Baker, “Computer Graphics with openGL”

41
41 Refraction Substituting in T Substituting in T From Snell’s Law From Snell’s Law Solving for T Solving for T Adapted from Hearn and Baker, “Computer Graphics with openGL”

42
42 Tree of Light Contributions of light grows at each contact point Contributions of light grows at each contact point I is the sum of reflected component R 1, transmitted component T 1 and the local component L 1 I is the sum of reflected component R 1, transmitted component T 1 and the local component L 1 Local component is the ambient, diffuse and specular reflections at P h Local component is the ambient, diffuse and specular reflections at P h R 1 is the sum of R 3, T 3 and local L 3 and so on ad infinitum R 1 is the sum of R 3, T 3 and local L 3 and so on ad infinitum

43
43 Ray tracing flow Figure out reflected/ refracted ray direction and recurse Local Phong illumination Adapted from F.S. Hill and CISC 640/440, Fall 2005

44
44 References Textbooks Textbooks F. S. Hill, “Computer Graphics Using OpenGL” F. S. Hill, “Computer Graphics Using OpenGL” Commonly used ray tracing program (completely free and available for most platforms) Commonly used ray tracing program (completely free and available for most platforms) Interesting Links Interesting Links Interactive Ray Tracer – Alyosha Efros Interactive Ray Tracer – Alyosha Efros Ray Tracing explained Ray Tracing explained aph/raytrace/rtrace0.htm aph/raytrace/rtrace0.htm aph/raytrace/rtrace0.htm aph/raytrace/rtrace0.htm

Similar presentations

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google