390 likes | 534 Views
Advanced Computer Graphics Lecture 4: Faster Ray Tracing. David Luebke cs551dl@cs.virginia.edu http://www.cs.virginia.edu/~cs551dl. Administrivia. Read Chapter 9 Verify collection of Exercise 1. Recap. Ray tracing is too slow Chapter 9: Different methods to speed it up
E N D
Advanced Computer GraphicsLecture 4: Faster Ray Tracing David Luebke cs551dl@cs.virginia.edu http://www.cs.virginia.edu/~cs551dl David Luebke 9/17/2014
Administrivia • Read Chapter 9 • Verify collection of Exercise 1 David Luebke 9/17/2014
Recap • Ray tracing is too slow • Chapter 9: • Different methods to speed it up • Ways of using ray tracing selectively David Luebke 9/17/2014
Recap • Speedup Techniques • Intersect rays faster • Shoot fewer rays • Shoot “smarter” rays David Luebke 9/17/2014
Recap • Intersect Rays Faster • Bounding volumes • Spatial partitions • Reordering ray intersection tests • Optimizing intersection tests David Luebke 9/17/2014
7 5 3 1 8 6 0 9 2 4 Recap • Bounding volumes • Idea: before intersecting a ray with a collection of objects, test it against one simple object that bounds the collection 7 5 3 1 8 6 0 9 2 4 David Luebke 9/17/2014
Recap • Hierarchical bounding volumes • Group nearby volumes hierarchically • Test rays against hierarchy top-down David Luebke 9/17/2014
Bounding Volumes • Some different bounding volumes: • Spheres • Axis-aligned bounding boxes (AABBs) • Oriented bounding boxes (OBBs) • Slabs • Show examples David Luebke 9/17/2014
Bounding Volumes • What makes a “good” bounding volume? • Tightness of fit (expressed how?) • Simplicity of intersection Total cost = b*B + i*I • b: # times volume tested for intersection • B: cost of ray-volume intersection test • i: # times item is tested for intersection • I: cost of ray-item intersection test David Luebke 9/17/2014
Bounding Volumes • Spheres • Cheap intersection test • Poor fit • A pain to fit to data David Luebke 9/17/2014
Bounding Volumes • Axis-aligned bounding boxes (AABBs) • Relatively cheap intersection test • Usually better fit • Trivial to fit to data David Luebke 9/17/2014
Bounding Volumes • Oriented bounding boxes (OBBs) • Medium-expensive intersection test • Very good fit (asymptotically better) • Medium-difficult to fit to data David Luebke 9/17/2014
Intermission:Parallel Close Proximity We will analyze how OBBs, AABBs, and spheres should perform in parallel close proximity situations. • Define parallel close proximity • Convergence rates of BV types • Asymptotic performance • Experimental evidence (graph) (The following 11 slides are courtesy Stefan Gottschalk, UNC) David Luebke 9/17/2014
Parallel Close Proximity Two models are in parallel close proximity when every point on each model is a given fixed distance (e) from the other model. Q: How does the number of BV tests increase as the gap size decreases? David Luebke 9/17/2014
1 Parallel Close Proximity:Convergence David Luebke 9/17/2014
1 1 / 2 2 / 4 Parallel Close Proximity:Convergence David Luebke 9/17/2014
Parallel Close Proximity:Convergence 1 David Luebke 9/17/2014
1 / 1 4 / 2 2 Parallel Close Proximity:Convergence David Luebke 9/17/2014
Parallel Close Proximity:Convergence 1 David Luebke 9/17/2014
1 1 / / 16 4 Parallel Close Proximity:Convergence David Luebke 9/17/2014
1 1 / / 4 4 1 / 4 Parallel Close Proximity:Convergence David Luebke 9/17/2014
k 2k O(n) 2 O(n ) Spheres & AABBs OBBs Parallel Close Proximity:Asymptotic Performance David Luebke 9/17/2014
Parallel Close Proximity: Experiment OBBs asymptotically outperform AABBs and spheres Log-log plot Number of BV tests Gap Size (e) David Luebke 9/17/2014
Bounding Volumes • Slabs (parallel planes) • Comparatively expensive • Very good fit • A pain to fit to data David Luebke 9/17/2014
Bounding Volume Hierarchies • What makes a “good” bounding volume hierarchy? • Grouped objects (or volumes) should be near each other • Volume should be minimal • Sum of all volumes should be minimal • Top of the tree is most critical • Constructing the hierarchy should pay for itself! David Luebke 9/17/2014
Spatial Partitioning • Hierarchical bounding volumes surround objects in the scene with (possibly overlapping) volumes • Often tightest fit • Spatialpartitioning techniques classify all space into non-overlapping portions • Easier to generate automatically • Can “walk” ray from partition to partition David Luebke 9/17/2014
Spatial Partitioning • Some spatial partitioning schemes: • Uniform grid (2-D or 3-D) • Octree • k-D tree • BSP-tree • Show examples David Luebke 9/17/2014
Uniform Grid • Uniform grid pros: • Very simple and fast to generate • Very simple and fast to trace rays across (How?) • Uniform grid cons: • Not adaptive • Wastes storage on empty space • Assumes uniform spread of data David Luebke 9/17/2014
Octree • Octree pros: • Simple to generate • Adaptive • Octree cons: • Less easy to trace rays across (How?) • Adaptive only in scale David Luebke 9/17/2014
k-D Trees • k-D tree pros: • Moderately simple to generate • More adaptive than octrees • k-D tree cons: • Less efficient to trace rays across • Moderately complex data structure David Luebke 9/17/2014
BSP Trees • BSP tree pros: • Extremely adaptive • Simple & elegant data structure • BSP tree cons: • Very hard to create optimum BSP • Splitting planes can explode storage • Simple but slow to trace rays across David Luebke 9/17/2014
Ray Space Subdivision • Weird acceleration scheme award… • Octree, BSP Tree, grids: 3-D subdivision schemes • Arvo & Kirk: 5-D subdivision scheme • Position: x, y, z • Direction: u, v • Draw it… David Luebke 9/17/2014
Reordering RayIntersection Tests • Caching ray hits • Memory-coherent ray tracing David Luebke 9/17/2014
Caching Ray Hits • Record what object the “last ray” hit • Start by checking that object • Especially for shadow rays…(why?) • RSRT uses a multi-level shadow cache(what’s that?) David Luebke 9/17/2014
Memory-Coherent Ray Tracing • Goal: ray trace very large scenes • Problem: ray tracing typically exhibits poor memory coherence (Why?) • Solution: re-order ray computations • Ray trace where geometry in cache • Postpone rays going out-of-core David Luebke 9/17/2014
Optimizing Ray Intersection Tests • Fine-tune the math! • Share subexpressions • Precompute everything possible • Code with care • Even use assembly, if necessary • Will get its own lecture David Luebke 9/17/2014
Speedup Techniques • Speedup Techniques • Intersect rays faster • Shoot fewer rays • Shoot “smarter” rays David Luebke 9/17/2014
Shoot Fewer Rays • Adaptive depth control • Naïve ray tracer: spawn 2 rays per intersection until max recursion limit • In practice, few surfaces are transparent or reflective • Contribution of most rays to image: 0% • Don’t shoot rays w/ contribution near 0% David Luebke 9/17/2014
Shoot Fewer Rays • Adaptive sampling • Shoot rays coarsely, interpolating their values across pixels • Where adjacent rays differ greatly in value, sample more finely • Stop when some maximum resolution is reached • Show example David Luebke 9/17/2014