ray tracing
play

Ray tracing Computer Graphics 2006 Based on slides by: Santa Clara - PowerPoint PPT Presentation

Ray tracing Computer Graphics 2006 Based on slides by: Santa Clara University Ray Tracing What is it? Why use it? Basics Advanced topics References Ray-Tracing: Why Use It? Simulate rays of light Produces natural


  1. Ray tracing Computer Graphics 2006 Based on slides by: Santa Clara University

  2. Ray Tracing � What is it? � Why use it? � Basics � Advanced topics � References

  3. Ray-Tracing: Why Use It? � Simulate rays of light � Produces natural lighting effects • • Reflection Depth of Field • • Refraction Motion Blur Soft Shadows • • Caustics

  4. Spheres galore

  5. Ray-Tracing: Why Use It? � Hard to simulate effects with rasterization techniques (OpenGL) � Rasterizers require many passes � Ray-tracing easier to implement

  6. Ray-Tracing: Who Uses It? � Entertainment (Movies, Commercials) � Games pre-production � Simulation

  7. Ray-Tracing: History � Decartes, 1637 A.D. - analysis of rainbow � Arthur Appel, 1968 - used for lighting 3D models � Turner Whitted, 1980 - “An Improved Illumination Model for Shaded Display” really kicked everyone off. � 1980-now - Lots of research

  8. The Basics � Generating Rays � Intersecting Rays with the Scene � Lighting � Shadowing � Reflections

  9. The Basic Idea � Simulate light rays from light source to eye Light Eye Reflected ray Incident ray Surface

  10. “Forward” Ray-Tracing � Trace rays from light � Lots of work for little return Light Image Light Rays Plane Eye Object

  11. “Backward” Ray-Tracing � Trace rays from eye instead � Do work where it matters Light Image Plane Eye Object This is what most people mean by “ray tracing”.

  12. Ray Parametric form � Ray expressed as function of a single parameter (“ t ”) <x, y, z> = <x o , y o , z o > + t * <x d , y d , z d > <x, y, z> = r o + tr d t = 2.5 r d = <x d , y d , z d > t = 2.0 t = 1.0 r o = <x o , y o , z o > t = 0.0

  13. Image Plane � Trace a ray for each pixel in the image (Looking down from the top) Eye Generating Rays tan(fov x ) * 2 Eye plane fov x

  14. (tan(fov x )* 2) / m (tan(fov y )* 2) / n � Trace a ray for each pixel in the image m Generating Rays n (Looking from Image Plane the side) plane Eye

  15. Generating Rays � Trace a ray for each pixel in the image plane renderImage(){ for each pixel i, j in the image ray.setStart(0, 0, 0); // r o ray.setDir ((.5 + i) * tan(fov x )* 2 / m, (.5 + j) * tan(fov y )* 2 / n, 1.0); // r d ray.normalize(); image[i][j] = rayTrace(ray); }

  16. Intersection Computation � Parametric ray: r ( t ) = o + t d • t ≥ 0 • t is distance along ray � Implicit object: f ( p ) = 0 � Intersection occurs when f ( r ( t )) = 0 • Real function of one real variable • Intersection ≡ root finding

  17. boolean intersects(Ray r, HitObject ho); class Sphere : public Primitive { r c double r; Point c; Sphere Object }

  18. Sphere Intersection f ( p )=( p - c ) ⋅ ( p - c ) - r 2 f ( r ( t )) = ( o + t d - c ) ⋅ ( o + t d - c ) - r 2 = d ⋅ d t 2 + 2 ( o - c ) ⋅ d t + ( o - c ) ⋅ ( o - c ) - r 2 2 − − ± D = B*B - 4*C; B B 4 AC = t if (D < 0.0) return FALSE; 2 A rootD = sqrt(D); t0 = 0.5*(-B - rootD); A = d ⋅ d = 1 t1 = 0.5*(-B + rootD); B = 2 ( o - c ) ⋅ d if (t0 >= 0) t = t0, return TRUE; C = ( o - c ) ⋅ ( o - c ) - r 2 if (t1 >= 0) t = t1, return TRUE; return FALSE;

  19. Other HitObject Values n = hit - c hit = r.o + t*r.d What about an ellipsoid?

  20. Ellipsoid Intersection Let T be a 4x4 transformation f ( T -1 r ( t )) T distorts a sphere into an ellipsoid = f ( T -1 ( o + t d )) = f ( T -1 o + t T -1 d )) T -1 d d T -1 o Ellipsoid::intersects(r,&ho) { o Ray Tir = (Ti * o, Ti * d); f ( T -1 x )=0 f ( x ) = 0 T Sphere::intersects(Tir,ho); } x T -1 x Ellipsoid is implicit surface of f ( T -1 x )

  21. What about the normal? n n ’ x Tx f ( T -1 x )=0 f ( x ) = 0 T ( n Q ) Tx = 0 n is tangent plane [a b c d] What is Q ? x is point [x y z 1] T Q = T -1 Such that matrix product n x = 0 ( n T -1 ) Tx = n ( T -1 T)x = 0 New normal n ’ = n T -1 = ( T -1 ) T n T

  22. Plane Intersection � So how do we do it with a minimum of work? � The road to the square is a close one

  23. Quadrics � Sphere: x 2 + y 2 + z 2 – r 2 � Cylinder: x 2 + y 2 – r 2 � Cone: x 2 + y 2 – z 2 � Tapered cylinder : x 2 + y 2 – ( 1 + (s-1) z) 2 � Paraboloid: x 2 + y 2 – z � Hyperboloid: x 2 + y 2 – z 2 ± r 2 (Variations: Use again the 4x4 transformation trick)

  24. Torus r R � Product of two implicit circles ( x – R ) 2 + z 2 – r 2 = 0 ( x + R ) 2 + z 2 – r 2 = 0 (( x – R ) 2 + z 2 – r 2 )(( x + R ) 2 + z 2 – r 2 ) ( x 2 – 2 Rx + R 2 + z 2 – r 2 ) ( x 2 + 2 Rx + R 2 + z 2 – r 2 ) x 4 + 2 x 2 z 2 + z 4 – 2 x 2 r 2 – 2 z 2 r 2 + r 4 – 2 x 2 R 2 + 2 z 2 R 2 – 2 r 2 R 2 + R 4 ( x 2 + z 2 – r 2 – R 2 ) 2 + 4 z 2 R 2 – 4 r 2 R 2 � Surface of rotation replace x 2 with x 2 + y 2 f ( x , y , z ) = ( x 2 + y 2 + z 2 – r 2 – R 2 ) 2 + 4 R 2 ( z 2 – r 2 ) � Quartic!!!

  25. Finding Roots � How do we find roots for higher degrees? � Newton’s Method • Converges fast • Might converge to wrong root � Root Isolation • Guarantees single root • Sturm Sequences

  26. Newton’s Method f x ( ) + = − x x i 1 i '( ) f x .

  27. Finding Intersections � Check all the objects, keep the closest intersection hitObject(ray) { for each object in scene does ray intersect the object? if(intersected and was closer) save that intersection if(intersected) return intersection point and normal }

  28. Lighting � We’ll use triangles for lights • Build complex shapes from triangles � Some lighting terms Light Eye N I R V Surface

  29. Lighting � Use modified Phong lighting • similar to OpenGL • simulates rough and shiny surfaces for each light I n = I ambient K ambient + I diffuse K diffuse (L . N) + I specular K specular (R . V) n

  30. Ambient Light � I ambient Simulates the indirect lighting in a scene. Eye Light

  31. Diffuse Light � I diffuse simulates direct lighting on a rough surface � Viewer independent � Paper, rough wood, brick, etc... Eye Light

  32. Specular Light � I specular simulates direct lighting on a smooth surface � Viewer dependent � Plastic, metal, polished wood, etc... Eye Light

  33. Shadow Test � Check against other objects to see if point is shadowed Eye Shadowing Object

  34. Reflection � Angle of incidence = angle of reflection ( θ I = θ R ) � I, R, N lie in the same plane N θ I θ R I R R = I - 2 (N . I) N

  35. Putting It All Together � Recursive ray evaluation rayTrace(ray) { hitObject(ray, p, n, triangle); color = object color; if(object is light) return(color); else return(lighting(p, n, color)); }

  36. Putting It All Together � Calculating surface color lighting(point) { color = ambient color; for each light if(hitObject(shadow ray)) color += lightcolor * dot(shadow ray, n); color += rayTrace(reflection) * pow(dot(reflection, ray), shininess); return(color); }

  37. Putting It All Together � The main program main() { objects = readObjects (); image = renderImage(objects); writeImage(image); }

  38. This is A Good Start � Lighting, Shadows, Reflection are enough to make some compelling images � Want better lighting and objects � Need more speed

  39. But we prefer something like this

  40. More Quality, More Speed � Better Lighting + Forward Tracing � Texture Mapping � Modeling Techniques � Motion Blur, Depth of Field, Blurry Reflection/Refraction • Distributed Ray-Tracing � Improving Image Quality � Acceleration Techniques

  41. Refraction � Keep track of medium (air, glass, etc) � Need index of refraction ( η ) � Need solid objects N θ I Medium 1 sin( θ I ) η 1 I (e.g. air) = sin( θ T ) η 2 Medium 2 (e.g. water) T θ T

  42. Refraction

  43. Improved Light Model � Cook & Torrance • Metals have different color at angle • Oblique reflections leak around corners • Based on a microfacet model

  44. Using “Forward” Ray Tracing � Backward tracing doesn’t handle indirect lighting too well � To get caustics , trace forward and store results in texture map.

  45. Using “Forward” Ray Tracing

  46. Texture Mapping � Use texture map to add surface detail • Think of it like texturing in OpenGL � Diffuse, Specular colors � Shininess value � Bump map � Transparency value

  47. Texture Mapping

  48. Parametric Surfaces � More expressive than triangle � Intersection is probably slower � u and v on surface can be used as texture s,t

  49. Constructive Solid Geometry � Union, Subtraction, Intersection of solid objects � Have to keep track of intersections

  50. Hierarchical Transformation � Scene made of parts � Each part made of smaller parts � Each smaller part has transformation linking it to larger part � Transformation can be changing over time - Animation

  51. Distributed Ray Tracing � Average multiple rays instead of just one ray � Use for both shadows, reflections, transmission (refraction) � Use for motion blur � Use for depth of field

  52. Distributed Ray Tracing

  53. Distributed Ray Tracing � One ray is not enough (jaggies) � Can use multiple rays per pixel - supersampling � Can use a few samples, continue if they’re very different - adaptive supersampling � Texture interpolation & filtering

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