Ra Tracing Ra-Tracing A B C D Photorealism Objective: To generate images that are as close as possible to those perceived b the human ee. Method: Accurate simulation of optical phenomena. Copright Page 1
Ra Tracing Illumination Models Local: Depends onl on the model, the light sources and the viewer. Eas to simulate. Eamples: Diffuse and specular illumination models. Flat, Gourard and Phong shading of polhedra. Global: Depends on the entire scene, the light sources and the viewer. Comple to simulate. Eamples: Shadow algorithms, ra-tracing, radiosit methods. 7 9 11 1 Copright Page
Ra Tracing 13 14 15 16 The Phsics Basic Illumination Model Light ras are emitted from light sources and bounce (reflect) in the scene until the reach the ee 17 18 Copright Page 3
Ra Tracing Rendering Equation I (, ) g(, )[ e(, ) s(,, ) I(, ) d] Surf Bring the objects to the screen Bring the screen to the objects 19 0 Ra-Casting Algorithm A Basic Ra-Casting Algorithm Ee RaCast (r, scene) Primar Ra <obj, p> := FirstIntersection(r, scene); if (no obj) return BackgroundColor; else return Shade(p, obj); end; 1 Ra-Object Intersection Ra-Tracing Algorithm In the kernel of ever ra-tracer Ra-object intersections are computed millions of times for a single image, hence must be ver efficient Eample: Ra-Sphere intersection ra: ( t) p v t, ( t) p v t, ( t) p v t (unit) sphere: 1 Solve a quadratic equation in t : p v (,,) Ee Primar Ra Reflected Ra Reflected Ra 0 ( p v t) ( p v t) ( p v t) 1 t ( v v v ) t( p v p v p v ) ( p p p ) 1 Refracted Ra 3 4 Copright Page 4
Ra Tracing Reflection and Refraction A Basic Ra-Tracing Algorithm Snell s law sin 1 c1 sin c n n 1 RaTrace(r, scene) <obj, p> := FirstIntersection(r, scene); if (no obj) return BackgroundColor; else begin if ( Reflect(obj) ) then ReflectColor := RaTrace(ReflectRa(r, p, obj)); else ReflectColor := Black; if ( Transparent(obj) ) then RefractColor := RaTrace(RefractRa(r, p, obj)); else RefractColor := Black; return Shade(ReflectColor, RefractColor, p, obj); end; 5 6 Termination in Ra-Tracing Possible termination criteria: No intersection Contribution of secondar ra attenuated below a threshold Maimal depth 7 8 Ra-Tracing as a Sampling Process Supersampling Trace multiple primar ras per piel and average their results. Ee 1 ra/piel 16 ras/piel 64 ras/piel 30 Copright Page 5
Ra Tracing Optimied Ra-Tracing Bounding Volumes Basic algorithm is simple but VERY epensive. Optimied ra-tracing is critical Reduce number of ras traced Reduce number of ra-object intersection calculations Methods Bounding Boes Object Hierarchies Spatial Subdivision (Octrees/BSP) Tree Pruning (Randomied) Bound each scene object b a simple volume (e.g. sphere). This enables fast reject of non-intersections. More work is performed when there is an intersection (or near intersection). Since, on the average, a tpical ra will not intersect the vast majorit of the scene objects, this results in a significant speedup. The time compleit is still linear in the number of scene objects. 31 Choosing Bounding Volumes Bounding volume should be: As tight-fitting as possible As simple as possible Uniform Spatial Partition 3D space is divided into voels of identical sie. Each voel contains a list of objects it intersects. A tradeoff eists between voel sie and list length. Disadvantage: The subdivision is totall independent of the scene structure. Advantages: Simple! The voels pierced b a ra ma be accessed ver efficientl b incremental calculation. A 3D version of Bresenham's algorithm is used. A B {C} {A,B} C {} 34 Simulating Shadows Simulating Shadows Ee Reflected Ra Light Source Trace ra from each ra-object intersection point to light source(s) If no line-of-sight point is shadowed Shadow computation routine: shadow = RaTrace(LightRa(p,obj,light)); to be included in the final shading: return Shade(shadow, ReflectColor, RefractColor, p, obj); Refracted Ra 35 36 Copright Page 6
Ra Tracing 37 38 Copright Page 7