Last Time: Acceleration Data Structures for Ray Tracing Modeling Transformations Illumination (Shading) Viewing Transformation (Perspective / Orthographic) Clipping Projection (to Screen Space) Scan Conversion (Rasterization) Graphics Pipeline!! Clipping Line & Polygon Rasterization Bresenham (DDA) Visibility Depth Buffer (z- buffer) Visibility / Display Schedule Wed Oct 13 th Assignment 4 due (Shadows, Reflection, & Refraction) Wed Oct 20 th Assignment 5 due (Voxel Rendering) Review Session for Quiz 1 Monday 25 th, 7:30 9pm, room TBA Tuesday October 26 th, in class: Quiz 1 Soft shadows Antialiasing (getting rid of jaggies) Glossy reflection Motion blur Depth of field (focus) Shadows Shadows & Light Sources one shadow ray per intersection per point light source no shadow rays http://www.davidfay.com/index.php one shadow ray clear bulb frosted bulb http://3media.initialized.org/photos/2000-10-18/index_gall.htm http://www.pa.uky.edu/~sciworks/light/preview/bulb2.htm
Soft Shadows Antialiasing Supersampling multiple shadow rays to sample area light source multiple rays per pixel jaggies w/ antialiasing one shadow ray point light lots of shadow rays area light Reflection one reflection ray per intersection Glossy Reflection multiple reflection rays Justin Legakis θ θ perfect mirror θ θ polished surface Motion Blur Sample objects temporally Depth of Field multiple rays per pixel Rob Cook film focal length Justin Legakis
Ray Tracing Algorithm Analysis Questions? Ray casting Lots of primitives Recursive Distributed Ray Tracing Effects Soft shadows Anti- aliasing Glossy reflection Motion blur Depth of field cost height * width * num primitives * intersection cost * size of recursive ray tree * num shadow rays * num supersamples * num glossy rays * num temporal samples * num focal samples *... can we reduce this? of each primitive of groups of ed primitives Acceleration of Ray Casting Goal: Reduce the number of ray/primitive intersections Conservative Bounding Region Conservative Bounding Regions First check for an intersection with a conservative bounding region Early reject tight avoid false positives fast to intersect non-aligned bounding box bounding sphere axis-aligned bounding box arbitrary convex region (bounding half-spaces)
Intersection with Axis-Aligned Box Bounding Box of a Triangle From Lecture 2, Ray Casting II t far t 2y t 2x y=y2 For all 3 axes, calculate the intersection distances t 1 and t 2 t near = max (t 1x, t 1y, t 1z ) t far = min (t 2x, t 2y, t 2z ) If t near > t far, box is missed (x 1, y 1, z 1 ) (x 0, y 0, z 0 ) = (max(x 0,x 1,x 2 ), max(y 0,y 1,y 2 ), max(z 0,z 1,z 2 )) t 1y t near t 1x x=x1 y=y1 x=x2 If t far < t min, box is behind If box survived tests, report intersection at t near = (min(x 0,x 1,x 2 ), min(y 0,y 1,y 2 ), min(z 0,z 1,z 2 )) (x 2, y 2, z 2 ) Bounding Box of a Sphere Bounding Box of a Plane = (x+r, y+r, z+r) = (+, +, + )* (x, y, z) r ax + by + cz = d n = (a, b, c) = (x-r, y-r, z-r) = (-, -, - )* * unless n is exactly perpendicular to an axis Bounding Box of a Group Bounding Box of a Transform (x max_a, y max_a, z max_a ) (x max_b, y max_b, z max_b ) = (max(x max_a,x max_b ), max(y max_a,y max_b ), max(z max_a,z max_b )) M (x 3,y 3,z 3 ) = M (x max,y max,z min ) (x' max, y' max, z' max ) = (max(x 0,x 1,x 2,x 3,x 4,x 5,x 6,x 7 ), max(y 0,y 1,y 2,y 3,y 4,x 5,x 6,x 7 ), max(z 0,z 1,z 2,z 3,z 4,x 5,x 6,x 7 )) (x min_b, y min_b, z min_b ) (x min_a, y min_a, z min_a ) (x 2,y 2,z 2 ) = M (x min,y max,z min ) (x 1,y 1,z 1 ) = M (x max,y min,z min ) = (min(x min_a,x min_b ), min(y min_a,y min_b ), min(z min_a,z min_b )) (x' min, y' min, z' min ) = (min(x 0,x 1,x 2,x 3,x 4,x 5,x 6,x 7 ), min(y 0,y 1,y 2,y 3,y 4,x 5,x 6,x 7 ), min(z 0,z 1,z 2,z 3,z 4,x 5,x 6,x 7 )) (x 0,y 0,z 0 ) = M (x min,y min,z min )
Special Case: Transformed Triangle Special Case: Transformed Triangle Can we do better? M (x 0, y 0, z 0 ) M (x' 0,y' 0,z' 0 ) = M (x 0,y 0,z 0 ) = (max(x' 0,x' 1,x' 2 ), max(y' 0,y' 1,y' 2 ), max(z' 0,z' 1,z' 2 )) (x 1, y 1, z 1 ) (x' 1,y' 1,z' 1 ) = M (x 1,y 1,z 1 ) (x' 2,y' 2,z' 2 ) = M (x 2,y 2,z 2 ) (x 2, y 2, z 2 ) = (min(x' 0,x' 1,x' 2 ), min(y' 0,y' 1,y' 2 ), min(z' 0,z' 1,z' 2 )) Questions? Regular Grid Adaptive Grids Hierarchical Bounding Volumes Regular Grid Create Grid Find bounding box of scene Choose grid resolution (n x, n y, n z ) grid x need not = grid y Cell (i, j) grid y grid x
Insert Primitives into Grid Primitives that overlap multiple cells? Insert into multiple cells (use pointers) For Each Cell Along a Ray Does the cell contain an intersection? Yes: return closest intersection No: continue Preventing Repeated Computation Perform the computation once, "mark" the object Don't re- intersect marked objects Don't Return Distant Intersections If intersection t is not within the cell range, continue (there may be something closer) Which Cells Should We Examine? Where Do We Start? Should we intersect the ray with each voxel? No! we can do better! Intersect ray with scene bounding box Ray origin may be inside the scene bounding box Cell (i, j) t next_y t next_x t min t next_y t min t next_x
Is there a Pattern to Cell Crossings? What's the Next Cell? Yes, the horizontal and vertical crossings have regular spacing dt x = grid x / dir x if ( t next_x < t next_y ) i += sign x t min = t next_x t next_x += dt x else j += sign y t min = t next_y Cell (i+1, j) Cell (i, j) t next_x t min t next_y t next_y += dt y dir x dir y dt y = grid y / dir y grid y (dir x, dir y ) dt y dt x grid x if (dir x > 0) sign x = 1 else sign x = -1 if (dir y > 0) sign y = 1 else sign y = -1 What's the Next Cell? 3DDDA Three Dimensional Digital Difference Analyzer Similar to Bresenham s Line Rasterization! Pseudo-Code create grid insert primitives into grid for each ray r find initial cell c(i,j), t min, t next_x & t next_y compute dt x, dt y, sign x and sign y while c!= NULL for each primitive p in c intersect r with p if intersection in range found return c = find next cell Regular Grid Discussion Advantages? easy to construct easy to traverse Disadvantages? may be only sparsely filled geometry may still be clumped A Note about Typos Typos happen in lecture notes Don t be afraid of thinking and asking questions Please tell us about any typos you find & we ll fix them ASAP Typos happen in textbooks The pseudocode for the 3DDDA ray/grid marching in Shirley is buggy Think, don t just copy directly
Questions? Regular Grid Adaptive Grids Hierarchical Bounding Volumes Adaptive Grids Subdivide until each cell contains no more than n elements, or maximum depth d is reached Primitives in an Adaptive Grid Can live at intermediate levels, or be pushed to lowest level of grid Nested Grids Octree/(Quadtree) Octree/(Quadtree) Adaptive Grid Discussion Advantages? grid complexity matches geometric density Disadvantages? more expensive to traverse (especially octree) Regular Grid Adaptive Grids Hierarchical Bounding Volumes
Bounding Volume Hierarchy Find bounding box of objects Split objects into two groups Recurse Bounding Volume Hierarchy Find bounding box of objects Split objects into two groups Recurse Bounding Volume Hierarchy Find bounding box of objects Split objects into two groups Recurse Bounding Volume Hierarchy Find bounding box of objects Split objects into two groups Recurse Bounding Volume Hierarchy Find bounding box of objects Split objects into two groups Recurse Where to split objects? At midpoint OR Sort, and put half of the objects on each side OR Use modeling hierarchy
Intersection with BVH Check sub-volume with closer intersection first Intersection with BVH Don't return intersection immediately if the other subvolume may have a closer intersection Bounding Volume Hierarchy Discussion Advantages easy to construct easy to traverse binary Disadvantages may be difficult to choose a good split for a node poor split may result in minimal spatial pruning Transformation Hierarchy Assignments 5 & 6 A B group C group D E Flatten Group & Transformation hierarchy may not be a good spatial hierarchy A B group C D C E Assignment 5: Voxel Rendering Bounding boxes for primitives Sphere voxelization Regular grid data structure Fast ray-grid intersection Flatten the ation hierarchy Assignment 6: Grid Acceleration & Solid Textures Accelerated ray tracing (6) Analyze ray tracing statistics (average # of rays, intersections, etc. per pixel) Solid textures (next time) Extra Credit: Distribution Ray Tracing
Ray Marching Visualization Next Time: sphere voxelization cells traversed Texture Mapping primitive density entered faces