David Luebke 3/5/2016 Advanced Computer Graphics Lecture 4: Faster Ray Tracing David Luebke
David Luebke 3/5/2016 Administrivia l Read Chapter 9 l Verify collection of Exercise 1
David Luebke 3/5/2016 Recap l Ray tracing is too slow l Chapter 9: –Different methods to speed it up –Ways of using ray tracing selectively
David Luebke 3/5/2016 Recap l Speedup Techniques –Intersect rays faster –Shoot fewer rays –Shoot “smarter” rays
David Luebke 3/5/2016 Recap l Intersect Rays Faster –Bounding volumes –Spatial partitions –Reordering ray intersection tests –Optimizing intersection tests
David Luebke 3/5/2016 Recap l Bounding volumes –Idea: before intersecting a ray with a collection of objects, test it against one simple object that bounds the collection
David Luebke 3/5/2016 Recap l Hierarchical bounding volumes –Group nearby volumes hierarchically –Test rays against hierarchy top-down
David Luebke 3/5/2016 Bounding Volumes l Some different bounding volumes: –Spheres –Axis-aligned bounding boxes (AABBs) –Oriented bounding boxes (OBBs) –Slabs l Show examples
David Luebke 3/5/2016 Bounding Volumes l 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 : # times volume tested for intersection B : cost of ray-volume intersection test B : cost of ray-volume intersection test i : # times item is tested for intersection i : # times item is tested for intersection I : cost of ray-item intersection test I : cost of ray-item intersection test
David Luebke 3/5/2016 Bounding Volumes l Spheres –Cheap intersection test –Poor fit –A pain to fit to data
David Luebke 3/5/2016 Bounding Volumes l Axis-aligned bounding boxes (AABBs) –Relatively cheap intersection test –Usually better fit –Trivial to fit to data
David Luebke 3/5/2016 Bounding Volumes l Oriented bounding boxes (OBBs) –Medium-expensive intersection test –Very good fit (asymptotically better) –Medium-difficult to fit to data
David Luebke 3/5/2016 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 3/5/2016 Parallel Close Proximity Q: How does the number of BV tests increase as the gap size decreases? Two models are in parallel close proximity when every point on each model is a given fixed distance ( ) from the other model.
David Luebke 3/5/2016 Parallel Close Proximity: Convergence 1
David Luebke 3/5/ / / Parallel Close Proximity: Convergence
David Luebke 3/5/ Parallel Close Proximity: Convergence
David Luebke 3/5/ / / Parallel Close Proximity: Convergence
David Luebke 3/5/ Parallel Close Proximity: Convergence
David Luebke 3/5/ / 1 16 / Parallel Close Proximity: Convergence
David Luebke 3/5/ / 1 4 / 1 4 / Parallel Close Proximity: Convergence
David Luebke 3/5/2016 OBBs k O(n) Spheres & AABBs 2k O(n ) 2 Parallel Close Proximity: Asymptotic Performance
David Luebke 3/5/2016 OBBs asymptotically outperform AABBs and spheres Log-log plot Gap Size ( ) Number of BV tests Parallel Close Proximity: Experiment
David Luebke 3/5/2016 Bounding Volumes l Slabs (parallel planes) –Comparatively expensive –Very good fit –A pain to fit to data
David Luebke 3/5/2016 Bounding Volume Hierarchies l 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 3/5/2016 Spatial Partitioning l Hierarchical bounding volumes surround objects in the scene with (possibly overlapping) volumes –Often tightest fit l Spatial partitioning techniques classify all space into non-overlapping portions –Easier to generate automatically –Can “walk” ray from partition to partition
David Luebke 3/5/2016 Spatial Partitioning l Some spatial partitioning schemes: –Uniform grid (2-D or 3-D) –Octree –k-D tree –BSP-tree l Show examples
David Luebke 3/5/2016 Uniform Grid l Uniform grid pros: –Very simple and fast to generate –Very simple and fast to trace rays across (How?) l Uniform grid cons: –Not adaptive n Wastes storage on empty space n Assumes uniform spread of data
David Luebke 3/5/2016 Octree l Octree pros: –Simple to generate –Adaptive l Octree cons: –Less easy to trace rays across (How?) –Adaptive only in scale
David Luebke 3/5/2016 k-D Trees l k-D tree pros: –Moderately simple to generate –More adaptive than octrees l k-D tree cons: –Less efficient to trace rays across –Moderately complex data structure
David Luebke 3/5/2016 BSP Trees l BSP tree pros: –Extremely adaptive –Simple & elegant data structure l BSP tree cons: –Very hard to create optimum BSP –Splitting planes can explode storage –Simple but slow to trace rays across
David Luebke 3/5/2016 Ray Space Subdivision l Weird acceleration scheme award… l Octree, BSP Tree, grids: 3-D subdivision schemes l Arvo & Kirk: 5-D subdivision scheme –Position: x, y, z –Direction: u, v l Draw it…
David Luebke 3/5/2016 Reordering Ray Intersection Tests l Caching ray hits l Memory-coherent ray tracing
David Luebke 3/5/2016 Caching Ray Hits l Record what object the “last ray” hit l Start by checking that object l Especially for shadow rays…(why?) l RSRT uses a multi-level shadow cache (what’s that?)
David Luebke 3/5/2016 Memory-Coherent Ray Tracing l Goal: ray trace very large scenes l Problem: ray tracing typically exhibits poor memory coherence (Why?) l Solution: re-order ray computations –Ray trace where geometry in cache –Postpone rays going out-of-core
David Luebke 3/5/2016 Optimizing Ray Intersection Tests l Fine-tune the math! –Share subexpressions –Precompute everything possible l Code with care –Even use assembly, if necessary –Will get its own lecture
David Luebke 3/5/2016 Speedup Techniques l Speedup Techniques –Intersect rays faster –Shoot fewer rays –Shoot “smarter” rays
David Luebke 3/5/2016 Shoot Fewer Rays l Adaptive depth control –Naïve ray tracer: spawn 2 rays per intersection until max recursion limit –In practice, few surfaces are transparent or reflective n Contribution of most rays to image: 0% n Don’t shoot rays w/ contribution near 0%
David Luebke 3/5/2016 Shoot Fewer Rays l 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 l Show example