Presentation is loading. Please wait.

Presentation is loading. Please wait.

Ray Tracing (2) Recursive Ray Tracing and Beyond.

Similar presentations


Presentation on theme: "Ray Tracing (2) Recursive Ray Tracing and Beyond."— Presentation transcript:

1 Ray Tracing (2) Recursive Ray Tracing and Beyond

2 One of the earliest ray-traced scenes from T. Whitted’s paper State of the art 20 years ago

3 Ray Tracing Example (with texture mapping) courtesy of J. Lee

4 Ray Tracing: Example from povray.org

5 Ray Tracing Example (plus other methods) from povray.org

6 Ray-Tracing: Why Use It? Simulate rays of light Produces natural lighting effects Simulate rays of light Produces natural lighting effects http://www.cs.berkeley.edu/~efros/java/tracer/tracer.html

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

8 Ray-Tracing: Who Uses It? Entertainment (Movies, Commercials)Entertainment (Movies, Commercials) Games pre-productionGames pre-production SimulationSimulation Entertainment (Movies, Commercials)Entertainment (Movies, Commercials) Games pre-productionGames pre-production SimulationSimulation

9 The Basics 1.Generating Rays 2.Intersecting Rays with the Scene 3.Lighting 4.Shadowing 5.Reflections 1.Generating Rays 2.Intersecting Rays with the Scene 3.Lighting 4.Shadowing 5.Reflections

10 Ray Tracing: Recursion from Hill

11 Anatomy of shade() Local Phong illumination make sure all channels are clamped to [0, 1] range Figure out reflected/ refracted ray direction and recurse

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

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

14 Ray Parametric form Ray expressed as function of a single parameter (“ t ”) = + t * = r o + tr d r o = r d = t = 0.0 t = 1.0 t = 2.0 t = 2.5

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

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

17 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); }

18 Triangle Intersection Want to know: at what point ( p ) does ray intersect triangle?Want to know: at what point ( p ) does ray intersect triangle? Compute lighting, reflected rays, shadowing from that pointCompute lighting, reflected rays, shadowing from that point Want to know: at what point ( p ) does ray intersect triangle?Want to know: at what point ( p ) does ray intersect triangle? Compute lighting, reflected rays, shadowing from that pointCompute lighting, reflected rays, shadowing from that point roro rdrd (t = ???) p

19 Triangle Intersection Step 1 : Intersect with plane ( Ax + By + Cz + D = 0 ) Step 1 : Intersect with plane ( Ax + By + Cz + D = 0 ) Plane normal n = Plane normal n = p p = -(n. r o + D) / (n. r d ) rdrd roro

20 Triangle Intersection Step 2 : Check against triangle edges p p V1V1 V1V1 V2V2 V2V2 V0V0 V0V0 n Plug p into ( p. E i + d i ) for each edgePlug p into ( p. E i + d i ) for each edge if signs are all positive or negative, point is inside triangle!if signs are all positive or negative, point is inside triangle! Plug p into ( p. E i + d i ) for each edgePlug p into ( p. E i + d i ) for each edge if signs are all positive or negative, point is inside triangle!if signs are all positive or negative, point is inside triangle! V0V1V0V1 V0V1V0V1 E0E0 E i = V i V i+1 x n (plane A, B, C) d i = -A. N (plane D)

21 Triangle Normals Could use plane normals (flat shading) Better to interpolate from vertices Could use plane normals (flat shading) Better to interpolate from vertices p p n n n V1 n V2 n V0 b b a a c c V1V1 V1V1 V2V2 V2V2 V0V0 V0V0 n = an V0 + bn V1 + cn V2 Find areas area( V 0 V 1 V 2 )

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

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

24 Lighting Use modified Phong lighting similar to OpenGL similar to OpenGL simulates rough and shiny surfaces simulates rough and shiny surfaces Use modified Phong lighting similar to OpenGL similar to OpenGL simulates rough and shiny surfaces 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

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

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

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

28 Shadow Test Check against other objects to see if point is shadowedCheck against other objects to see if point is shadowed Eye Shadowing Object

29 No shadows Light 1 onlyLight 2 only Lights 1 and 2

30 Shadows Light 1 onlyLight 2 only Lights 1 and 2

31 Reflection Mirror-like surfaces should reflect other objects in scene Mirror-like surfaces should reflect other objects in scene courtesy of J. Arvo

32 Reflections incident ray v reflected ray r

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

34 Example: Reflections at depth = 0

35 Example: Reflections at depth = 1

36 Example: Reflections at depth = 2

37 Example: Reflections at depth = 3

38

39 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)); }

40 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); }

41 Putting It All Together The main program main() { triangles = readTriangles(); image = renderImage(triangles); writeImage(image); }

42 This is A Good Start Lighting, Shadows, Reflection are enough to make some compelling imagesLighting, Shadows, Reflection are enough to make some compelling images Want better lighting and objectsWant better lighting and objects Need more speedNeed more speed Lighting, Shadows, Reflection are enough to make some compelling imagesLighting, Shadows, Reflection are enough to make some compelling images Want better lighting and objectsWant better lighting and objects Need more speedNeed more speed

43 More Quality, More Speed Better Lighting + Forward TracingBetter Lighting + Forward Tracing Texture MappingTexture Mapping Modeling TechniquesModeling Techniques Motion Blur, Depth of Field, Blurry Reflection/RefractionMotion Blur, Depth of Field, Blurry Reflection/Refraction Distributed Ray-Tracing Distributed Ray-Tracing Improving Image QualityImproving Image Quality Acceleration TechniquesAcceleration Techniques Better Lighting + Forward TracingBetter Lighting + Forward Tracing Texture MappingTexture Mapping Modeling TechniquesModeling Techniques Motion Blur, Depth of Field, Blurry Reflection/RefractionMotion Blur, Depth of Field, Blurry Reflection/Refraction Distributed Ray-Tracing Distributed Ray-Tracing Improving Image QualityImproving Image Quality Acceleration TechniquesAcceleration Techniques

44 Refraction Keep track of medium (air, glass, etc) Need index of refraction (  ) Need solid objects Keep track of medium (air, glass, etc) Need index of refraction (  ) Need solid objects T N I II TT sin(  I )  1 sin(  T )  2 = Medium 1 (e.g. air) Medium 2 (e.g. water)

45 Refraction Transparent surfaces should refract scene objects behind them Transparent surfaces should refract scene objects behind them

46 Example: Refraction (with texture mapping) courtesy of J. Lee

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

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

49 “Forward” Ray-Tracing Trace rays from lightTrace rays from light Lots of work for little returnLots of work for little return Trace rays from lightTrace rays from light Lots of work for little returnLots of work for little return Eye Light Image Plane Object Light Rays

50 Using “Forward” Ray Tracing

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

52 Texture Mapping

53 Parametric Surfaces More expressive than triangleMore expressive than triangle Intersection is probably slowerIntersection is probably slower u and v on surface can be used as texture s,tu and v on surface can be used as texture s,t More expressive than triangleMore expressive than triangle Intersection is probably slowerIntersection is probably slower u and v on surface can be used as texture s,tu and v on surface can be used as texture s,t

54 Constructive Solid Geometry Union, Subtraction, Intersection of solid objectsUnion, Subtraction, Intersection of solid objects Have to keep track of intersectionsHave to keep track of intersections Union, Subtraction, Intersection of solid objectsUnion, Subtraction, Intersection of solid objects Have to keep track of intersectionsHave to keep track of intersections

55 Hierarchical Transformation Scene made of partsScene made of parts Each part made of smaller partsEach part made of smaller parts Each smaller part has transformation linking it to larger partEach smaller part has transformation linking it to larger part Transformation can be changing over time - AnimationTransformation can be changing over time - Animation Scene made of partsScene made of parts Each part made of smaller partsEach part made of smaller parts Each smaller part has transformation linking it to larger partEach smaller part has transformation linking it to larger part Transformation can be changing over time - AnimationTransformation can be changing over time - Animation

56 Distributed Ray Tracing Average multiple rays instead of just one rayAverage multiple rays instead of just one ray Use for both shadows, reflections, transmission (refraction)Use for both shadows, reflections, transmission (refraction) Use for motion blurUse for motion blur Use for depth of fieldUse for depth of field Average multiple rays instead of just one rayAverage multiple rays instead of just one ray Use for both shadows, reflections, transmission (refraction)Use for both shadows, reflections, transmission (refraction) Use for motion blurUse for motion blur Use for depth of fieldUse for depth of field

57 Distributed Ray Tracing

58 One ray is not enough (jaggies)One ray is not enough (jaggies) Can use multiple rays per pixel - supersamplingCan use multiple rays per pixel - supersampling Can use a few samples, continue if they’re very different - adaptive supersamplingCan use a few samples, continue if they’re very different - adaptive supersampling Texture interpolation & filteringTexture interpolation & filtering One ray is not enough (jaggies)One ray is not enough (jaggies) Can use multiple rays per pixel - supersamplingCan use multiple rays per pixel - supersampling Can use a few samples, continue if they’re very different - adaptive supersamplingCan use a few samples, continue if they’re very different - adaptive supersampling Texture interpolation & filteringTexture interpolation & filtering

59 Acceleration 1280x1024 image with 10 rays/pixel 1000 objects (triangle, CSG, NURBS) 3 levels recursion 39321600000 intersection tests 39321600000 intersection tests 100000 tests/second -> 109 days! Must use an acceleration method! 1280x1024 image with 10 rays/pixel 1000 objects (triangle, CSG, NURBS) 3 levels recursion 39321600000 intersection tests 39321600000 intersection tests 100000 tests/second -> 109 days! Must use an acceleration method!

60 Bounding volumes Use simple shape for quick test, keep a hierarchy

61 Space Subdivision Break your space into pieces Search the structure linearly Break your space into pieces Search the structure linearly

62 Parallel Processing You can always throw more processors at it.You can always throw more processors at it.

63 Really Advanced Stuff Error analysis Hybrid radiosity/ray-tracing Metropolis Light Transport Memory-Coherent Ray-tracing Error analysis Hybrid radiosity/ray-tracing Metropolis Light Transport Memory-Coherent Ray-tracing


Download ppt "Ray Tracing (2) Recursive Ray Tracing and Beyond."

Similar presentations


Ads by Google