Acceleration Data Structures for Ray Tracing Most slides are taken from Fredo Durand
Extra rays needed for these effects: • Distribution Ray Tracing – Soft shadows – Anti-aliasing (getting rid of jaggies) g (g g j gg ) – Glossy reflection – Motion blur Motion blur – Depth of field (focus)
Shadows • one shadow ray per i intersection per point i i light source no shadow rays one shadow ray
Soft Shadows • multiple shadow rays to sample area light l li h source one shadow ray lots of shadow rays
Antialiasing – Supersampling jaggies w/ antialiasing • multiple rays per pixel point light area light g
Reflection • one reflection ray per intersection perfect mirror p θ θ θ θ
Glossy Reflection • multiple reflection rays Justin Legakis Justin Legakis polished surface p θ θ θ θ
Motion Blur • Sample objects temporally ll Rob Cook
Algorithm Analysis • Ray casting cost ≤ height * width * • Lots of primitives num primitives * intersection cost * • Recursive num shadow rays * num shadow rays * • Distributed Ray supersampling * Tracing Effects Tracing Effects num glossy rays * g y y num temporal samples * – Soft shadows max recursion depth * – Anti-aliasing Anti aliasing . . . – Glossy reflection – Motion blur can we reduce this? – Depth of field p
The Ray Tree T 3 T 3 E Eye R 2 N 2 T 1 R R R N 3 3 1 L 1 L 2 N 1 L 3 1 3 L 1 R T 1 1 L L 2 L 3 L N i surface normal Eye R R T 3 R reflected ray R i reflected ray 2 3 L i shadow ray T t T i transmitted (refracted) ray itt d ( f t d)
Questions?
Accelerating Ray Tracing • Four main groups of acceleration techniques: – Reducing the average cost of intersecting a ray with a scene: • Faster intersection calculations • Fewer intersection calculations – Reducing the total number of rays that are traced • Adaptive recursion depth control p p – Discrete Ray Tracing • proximity clouds proximity clouds – Using generalized rays – Parallelization, specialized hardware P ll li ti i li d h d
Acceleration of Ray Casting • Goal: Reduce the number of b f ray/primitive intersections
Bounding Volumes • Idea: associate with each object a simple bounding volume. If a ray misses the bounding volume, it also l If i th b di l it l misses the object contained therein. • Common bounding volumes: – spheres – bounding boxes – bounding slabs • Effective for additional applications: – Clipping acceleration pp g – Collision detection • Note: bounding volumes offer no asymptotic Note: bounding volumes offer no asymptotic improvement!
Conservative Bounding Region • First check for an i intersection with a i i h conservative bounding region • Early reject • Early reject
Conservative Bounding Regions • tight → avoid bounding sphere p false positives • fast to intersect • fast to intersect non-aligned bounding box axis-aligned b bounding box di b arbitrary convex region (bounding half-spaces)
Bounding Volumes
Bounding Boxes can overlap
Intersection with Axis-Aligned Box From Lecture 3, • For all 3 axes, For all 3 axes, Ray Casting II 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 ) t 2x t far y Y2 y=Y2 • If t near > t far , t 2y box is missed t t nea r t 1x • If t far < t min , box is behind y=Y1 y Y1 • If box survived tests, t 1y report intersection at t near x=X2 x=X1
Bounding Volume Hierarchy • Introduced by James Clark (SGI, Netscape) in 1976 for efficient view-frustum culling. f ffi i i f lli Procedure IntersectBVH(ray, node) ( y, ) begin if IsLeaf(node) then Intersect(ray, node.object) else if IntersectBV(ray,node.boundingVolume) then foreach child of node do IntersectBVH(ray, child) endfor endif end
Bounding Volume Hierarchy • Find bounding box of objects • Split objects into two groups • Recurse • Recurse
Bounding Volume Hierarchy • Find bounding box of objects • Split objects into two groups • Recurse • Recurse
Bounding Volume Hierarchy • Find bounding box of objects • Split objects into two groups • Recurse • Recurse
Bounding Volume Hierarchy • Find bounding box of objects • Split objects into two groups • Recurse • Recurse
Bounding Volume Hierarchy • Find bounding box of objects • Split objects into two groups • Recurse • 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 subvolume with closer intersection first
Intersection with BVH • Don't return intersection immediately if the other subvolume may have a closer intersection h b l h l i i
Questions?
Regular Grid
Create grid • Define grid resolution, not necessarily cubes il b Cell ( i, j ) grid y grid x id
Insert primitives into grid • Primitives that overlap multiple cells? • Insert bbx 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) ti (th b thi l )
Where do we start? • Intersect ray Cell ( i j ) Cell ( i, j ) with scene ith bounding box • Ray origin may be inside the scene bounding box t next h next_h t next_v t next_v t min t min t next_h t t t h
Is there a pattern to cell crossings? • Yes, the h horizontal i t l and vertical crossings i dt v = grid y / dir y have regular spacing spacing grid y dt = grid / dir dt h = grid x / dir x ( dir x , dir y ) grid x id
What's the next cell? if t next_v < t next_h Cell ( i+ 1 , j ) i + i += sign x i Cell ( i, j ) t min = t next_v t next_v += dt v d else t next h t next_h j += sign y t next_v t min = t next_h t min t i t next_h += dt h dt dt h dt v ( dir x , dir y ) if (dir > 0) sign = 1 else sign = -1 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 Di Dimensional Digital i l Di it l Difference Analyzer • We saw this again earlier, for line rasterization
Regular Grid Discussion • Advantages? – easy to construct – easy to traverse y • Disadvantages? Di d t ? – may be only sparsely filled – geometry may still be clumped
Questions?
Adaptive Grids • Subdivide until each cell contains no more than n elements, or maximum depth d is reached l t i d th d i h d N Nested Grids d G id O Octree/(Quadtree) /(Q d )
Primitives in an Adaptive Grid • Can live at intermediate levels, or b be pushed to lowest level of grid h d t l t l l f id O Octree/(Quadtree) /(Q d )
Top down traversal Split ray into sub-segments and traverse each segment recursively. i l
Bottom Up traversal Step from cell to cell. Intersect current cell and add an epsilon into the next cell. il i t th t ll Then search for the cell in the tree. tree. A naïve search starts from the root. Otherwise, try an intelligent guess…
Kd-trees vs. Quad-tree
Kd-trees vs. BSP-tree
Adaptive Spatial Subdivision • Disadvantages of uniform subdivision: – requires a lot of space – traversal of empty regions of space can be slow p y g p – not suitable for “teapot in a stadium” scenes • Solution: use a hierarchical adaptive spatial • Solution: use a hierarchical adaptive spatial subdivision data structure – octrees – BSP-trees • Given a ray, perform a depth-first traversal of the tree Again can stop once an intersection has tree. Again, can stop once an intersection has been found.
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
Uniform vs. Adaptive Subdivision
Macro-regions
Proximity Clouds
Parallel/Distributed RT • Two main approaches: – Each processor is in charge of tracing a subset of the rays. Requires a shared memory architecture, replication of the scene database, or transmission of objects between processors on demand. – Each processor is in charge of a subset of the scene (either in terms of space, or in terms of objects). ( p , j ) Requires processors to transmit rays among themselves.
Recommend
More recommend