200 likes | 419 Views
Ray Tracing 2: Acceleration. Ray Tracing Acceleration Techniques. Too Slow!. Faster intersection. Fewer rays. Generalized rays. N. 1. Uniform grids Spatial hierarchies K-D Octtree BSP Hierarchical grids Hierarchical bounding volumes (HBV). Tighter bounds Faster intersector.
E N D
Ray Tracing Acceleration Techniques Too Slow! Faster intersection Fewer rays Generalized rays N 1 • Uniform grids • Spatial hierarchies • K-D • Octtree • BSP • Hierarchical grids • Hierarchical • bounding • volumes (HBV) Tighter bounds Faster intersector Early ray termination Adaptive sampling Beam tracing Cone tracing Pencil tracing
Preprocess scene Find bounding box Uniform Grids
Preprocess scene Find bounding box Determine grid resolution Uniform Grids
Preprocess scene Find bounding box Determine grid resolution Place object in cell if its bounding box overlaps the cell Uniform Grids
Preprocess scene Find bounding box Determine grid resolution Place object in cell if its bounding box overlaps the cell Check that object overlaps cell (expensive!) Uniform Grids
Preprocess scene Traverse grid 3D line = 3D-DDA 6-connected line Uniform Grids
Caveat: Overlap • Optimize objects that overlap multiple cells • Caveat 1 (correctness): • Intersection must lie within current cell • Caveat 2 (efficiency): • Redundant intersection tests • “Mailboxes” • Assign each ray a number • Object intersection cache (“mailbox”) • Store ray number, intersection information
Spatial Hierarchies A D B B C C D A Leaf nodes correspond to unique regions in space
Spatial Hierarchies A D B B C C D A Point location by recursive search
Variations octtree BSP tree KD tree
Creating Spatial Hierarchies • insert(node,prim) { • if( overlap(node->bound,prim) ) • if( leaf(node) ) { • if( node->nprims > MAXPRIMS && • node->depth < MAXDEPTH ) { • subdivide(node); • foreach child in node • insert(child,prim) • } • else list_insert(node->prims,prim); • } • else • foreach child in node • insert(child,prim) • } • // Typically MAXDEPTH=16, MAXPRIMS=2-8
Median-Cut • Build hierarchy bottom-up • Chose direction and position carefully • Surface-area heuristic
Surface Area and Rays • Number of rays in a given direction that hit an object is proportional to its projected area • The total number of rays hitting an object is • Crofton’s theorem: • For a convex body: • Example: Sphere
Surface Area and Rays • Probability of a ray hitting an object that is completely inside a cell is:
Intersect(L,tmin,tmax) Intersect(L,tmin,t*) Intersect(R,t*,tmax) Intersect(R,tmin,tmax) Ray Traversal Algorithms • Recursive inorder traversal • Kaplan, Arvo, Jansen
IMAGE IMAGE IMAGE Hierarchical Grids • Good compromise preferred by many practitioners
Hierarchical Bounding Volumes • Create tree of bounding volumes • Children are contained within parent • Creation preprocess • From model hierarchy • Automatic clustering • Search • intersect(node,ray,hits) { • if( intersectp(node->bound,ray) • if( leaf(node) ) • intersect(node->prims,ray,hits) • else • for each child • inter sect(child,ray,hits) • }
Comparison Vlastimil Havran, Best Efficiency Scheme Project http://sgi.felk.cvut.cz/BES/