Acceleration Data Structures for Ray Tracing MIT EECS

  • Slides: 62
Download presentation
Acceleration Data Structures for Ray Tracing MIT EECS 6. 837, Durand Cutler

Acceleration Data Structures for Ray Tracing MIT EECS 6. 837, Durand Cutler

Today • • • Review & Schedule Motivation – Distribution Ray Tracing Bounding Boxes

Today • • • Review & Schedule Motivation – Distribution Ray Tracing Bounding Boxes Spatial Acceleration Data Structures Flattening the transformation hierarchy MIT EECS 6. 837, Durand Cutler

Cool results from Assignment 2 seantek koi MIT EECS 6. 837, Durand Cutler

Cool results from Assignment 2 seantek koi MIT EECS 6. 837, Durand Cutler

Last Week: • Ray Tracing – Shadows – Reflection – Refraction • Local Illumination

Last Week: • Ray Tracing – Shadows – Reflection – Refraction • Local Illumination – Bidirectional Reflectance Distribution Function (BRDF) – Phong Model MIT EECS 6. 837, Durand Cutler r i i r

Schedule • Wednesday October 1 st: Assignment 3 (Ray Tracing & Phong Materials) due

Schedule • Wednesday October 1 st: Assignment 3 (Ray Tracing & Phong Materials) due • Sunday October 5 th, 5 -7 PM, Room TBA: Review Session for Quiz 1 • Tuesday October 7 th: Quiz 1: In class • Wednesday October 15 th: Assignment 4 (Grid Acceleration) due MIT EECS 6. 837, Durand Cutler

Questions? MIT EECS 6. 837, Durand Cutler

Questions? MIT EECS 6. 837, Durand Cutler

Today • • • Review & Schedule Motivation – Distribution Ray Tracing Bounding Boxes

Today • • • Review & Schedule Motivation – Distribution Ray Tracing Bounding Boxes Spatial Acceleration Data Structures Flattening the transformation hierarchy MIT EECS 6. 837, Durand Cutler

Extra rays needed for these effects: • Distribution Ray Tracing – Soft shadows –

Extra rays needed for these effects: • Distribution Ray Tracing – Soft shadows – Anti-aliasing (getting rid of jaggies) – Glossy reflection – Motion blur – Depth of field (focus) MIT EECS 6. 837, Durand Cutler

Shadows • one shadow ray per intersection per point light source no shadow rays

Shadows • one shadow ray per intersection per point light source no shadow rays one shadow ray MIT EECS 6. 837, Durand Cutler

Soft Shadows • multiple shadow rays to sample area light source one shadow ray

Soft Shadows • multiple shadow rays to sample area light source one shadow ray lots of shadow rays MIT EECS 6. 837, Durand Cutler

Antialiasing – Supersampling • multiple rays per pixel jaggies point light area light MIT

Antialiasing – Supersampling • multiple rays per pixel jaggies point light area light MIT EECS 6. 837, Durand Cutler w/ antialiasing

Reflection • one reflection ray per intersection θ θ MIT EECS 6. 837, Durand

Reflection • one reflection ray per intersection θ θ MIT EECS 6. 837, Durand Cutler perfect mirror

Glossy Reflection • multiple reflection rays Justin Legakis θ θ MIT EECS 6. 837,

Glossy Reflection • multiple reflection rays Justin Legakis θ θ MIT EECS 6. 837, Durand Cutler polished surface

Motion Blur • Sample objects temporally Rob Cook MIT EECS 6. 837, Durand Cutler

Motion Blur • Sample objects temporally Rob Cook MIT EECS 6. 837, Durand Cutler

Depth of Field • multiple rays per pixel film focal length MIT EECS 6.

Depth of Field • multiple rays per pixel film focal length MIT EECS 6. 837, Durand Cutler Justin Legakis

Algorithm Analysis • • Ray casting Lots of primitives Recursive Distributed Ray Tracing Effects

Algorithm Analysis • • 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 * num shadow rays * supersampling * num glossy rays * num temporal samples * max recursion depth *. . . can we reduce this? MIT EECS 6. 837, Durand Cutler

Questions? MIT EECS 6. 837, Durand Cutler

Questions? MIT EECS 6. 837, Durand Cutler

Today • Review & Schedule • Motivation – Distribution Ray Tracing • Bounding Boxes

Today • Review & Schedule • Motivation – Distribution Ray Tracing • Bounding Boxes – of each primitive – of groups – of transformed primitives • Spatial Acceleration Data Structures • Flattening the transformation hierarchy MIT EECS 6. 837, Durand Cutler

Acceleration of Ray Casting • Goal: Reduce the number of ray/primitive intersections MIT EECS

Acceleration of Ray Casting • Goal: Reduce the number of ray/primitive intersections MIT EECS 6. 837, Durand Cutler

Conservative Bounding Region • First check for an intersection with a conservative bounding region

Conservative Bounding Region • First check for an intersection with a conservative bounding region • Early reject MIT EECS 6. 837, Durand Cutler

Conservative Bounding Regions • tight → avoid false positives bounding sphere • fast to

Conservative Bounding Regions • tight → avoid false positives bounding sphere • fast to intersect non-aligned bounding box axis-aligned bounding box arbitrary convex region (bounding half-spaces) MIT EECS 6. 837, Durand Cutler

Intersection with Axis-Aligned Box From Lecture 3, Ray Casting II t 2 x tfar

Intersection with Axis-Aligned Box From Lecture 3, Ray Casting II t 2 x tfar y=Y 2 t 2 y tnear t 1 x y=Y 1 t 1 y x=X 1 x=X 2 • For all 3 axes, calculate the intersection distances t 1 and t 2 • tnear = max (t 1 x, t 1 y, t 1 z) tfar = min (t 2 x, t 2 y, t 2 z) • If tnear> tfar, box is missed • If tfar< tmin, box is behind • If box survived tests, report intersection at tnear MIT EECS 6. 837, Durand Cutler

Bounding Box of a Triangle (x 0, y 0, z 0) (x 1, y

Bounding Box of a Triangle (x 0, y 0, z 0) (x 1, y 1, z 1) (xmin, ymin, zmin) (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)) MIT EECS 6. 837, Durand Cutler (xmax, ymax, zmax) = (max(x 0, x 1, x 2), max(y 0, y 1, y 2), max(z 0, z 1, z 2))

Bounding Box of a Sphere (xmax, ymax, zmax) = (x+r, y+r, z+r) r (x,

Bounding Box of a Sphere (xmax, ymax, zmax) = (x+r, y+r, z+r) r (x, y, z) (xmin, ymin, zmin) = (x-r, y-r, z-r) MIT EECS 6. 837, Durand Cutler

Bounding Box of a Plane (xmax, ymax, zmax) = (+∞, +∞)* n = (a,

Bounding Box of a Plane (xmax, ymax, zmax) = (+∞, +∞)* n = (a, b, c) ax + by + cz = d (xmin, ymin, zmin) = (-∞, -∞)* * unless n is exactly perpendicular to an axis MIT EECS 6. 837, Durand Cutler

Bounding Box of a Group (xmax_a, ymax_a, zmax_a) (xmax_b, ymax_b, zmax_b) (xmin_b, ymin_b, zmin_b)

Bounding Box of a Group (xmax_a, ymax_a, zmax_a) (xmax_b, ymax_b, zmax_b) (xmin_b, ymin_b, zmin_b) (xmin_a, ymin_a, zmin_a) (xmin, ymin, zmin) = (min(xmin_a, xmin_b), min(ymin_a, ymin_b), min(zmin_a, zmin_b)) MIT EECS 6. 837, Durand Cutler (xmax, ymax, zmax) = (max(xmax_a, xmax_b), max(ymax_a, ymax_b), max(zmax_a, zmax_b))

Bounding Box of a Transform (x'max, y'max, z'max) = (max(x 0, x 1, x

Bounding Box of a Transform (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)) (xmax, ymax, zmax) M (x 3, y 3, z 3) = M (xmax, ymax, zmin) (x 2, y 2, z 2) = M (xmin, ymax, zmin) (xmin, ymin, zmin) (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)) MIT EECS 6. 837, Durand Cutler (x 1, y 1, z 1) = M (xmax, ymin, zmin) (x 0, y 0, z 0) = M (xmin, ymin, zmin)

Special Case: Transformed Triangle Can we do better? M MIT EECS 6. 837, Durand

Special Case: Transformed Triangle Can we do better? M MIT EECS 6. 837, Durand Cutler

Special Case: Transformed Triangle (xmax, ymax, zmax) = (max(x'0, x'1, x'2), max(y'0, y'1, y'2),

Special Case: Transformed Triangle (xmax, ymax, zmax) = (max(x'0, x'1, x'2), max(y'0, y'1, y'2), max(z'0, z'1, z'2)) (x 0, y 0, z 0) (x 1, y 1, z 1) M (x'0, y'0, z'0) = M (x 0, y 0, z 0) (x'1, y'1, z'1) = M (x 1, y 1, z 1) (x 2, y 2, z 2) (xmin, ymin, zmin) = (min(x'0, x'1, x'2), min(y'0, y'1, y'2), min(z'0, z'1, z'2)) MIT EECS 6. 837, Durand Cutler (x'2, y'2, z'2) = M (x 2, y 2, z 2)

Questions? MIT EECS 6. 837, Durand Cutler

Questions? MIT EECS 6. 837, Durand Cutler

Today • • Review & Schedule Motivation – Distribution Ray Tracing Bounding Boxes Spatial

Today • • Review & Schedule Motivation – Distribution Ray Tracing Bounding Boxes Spatial Acceleration Data Structures – Regular Grid – Adaptive Grids – Hierarchical Bounding Volumes • Flattening the transformation hierarchy MIT EECS 6. 837, Durand Cutler

Regular Grid MIT EECS 6. 837, Durand Cutler

Regular Grid MIT EECS 6. 837, Durand Cutler

Create grid • Find bounding box of scene • Choose grid spacing • gridx

Create grid • Find bounding box of scene • Choose grid spacing • gridx need not = gridy Cell (i, j) gridy gridx MIT EECS 6. 837, Durand Cutler

Insert primitives into grid • Primitives that overlap multiple cells? • Insert into multiple

Insert primitives into grid • Primitives that overlap multiple cells? • Insert into multiple cells (use pointers) MIT EECS 6. 837, Durand Cutler

For each cell along a ray • Does the cell contain an intersection? •

For each cell along a ray • Does the cell contain an intersection? • Yes: return closest intersection • No: continue MIT EECS 6. 837, Durand Cutler

Preventing repeated computation • Perform the computation once, "mark" the object • Don't re-intersect

Preventing repeated computation • Perform the computation once, "mark" the object • Don't re-intersect marked objects MIT EECS 6. 837, Durand Cutler

Don't return distant intersections • If intersection t is not within the cell range,

Don't return distant intersections • If intersection t is not within the cell range, continue (there may be something closer) MIT EECS 6. 837, Durand Cutler

Where do we start? • Intersect ray with scene bounding box • Ray origin

Where do we start? • Intersect ray with scene bounding box • Ray origin may be inside the scene bounding box Cell (i, j) tnext_v tmin tnext_h MIT EECS 6. 837, Durand Cutler

Is there a pattern to cell crossings? • Yes, the horizontal and vertical crossings

Is there a pattern to cell crossings? • Yes, the horizontal and vertical crossings have regular spacing (dirx, diry) dtv = gridy / diry gridy dth = gridx / dirx gridx MIT EECS 6. 837, Durand Cutler

What's the next cell? if tnext_v < tnext_h Cell (i+1, j) i += signx

What's the next cell? if tnext_v < tnext_h Cell (i+1, j) i += signx Cell (i, j) tmin = tnext_v += dtv else tnext_h j += signy tmin = tnext_h tmin tnext_h += dth (dirx, diry) tnext_v dth if (dirx > 0) signx = 1 else signx = -1 if (dir signy =and 1 Cutler else signy = -1 y > 0) MIT EECS 6. 837, Durand dtv

What's the next cell? • 3 DDDA – Three Dimensional Digital Difference Analyzer •

What's the next cell? • 3 DDDA – Three Dimensional Digital Difference Analyzer • We'll see this again later, for line rasterization MIT EECS 6. 837, Durand Cutler

Pseudo-code create grid insert primitives into grid for each ray r find initial cell

Pseudo-code create grid insert primitives into grid for each ray r find initial cell c(i, j), tmin, tnext_v & tnext_h compute dtv, dth, signx and signy while c != NULL for each primitive p in c intersect r with p if intersection in range found return c = find next cell MIT EECS 6. 837, Durand Cutler

Regular Grid Discussion • Advantages? – easy to construct – easy to traverse •

Regular Grid Discussion • Advantages? – easy to construct – easy to traverse • Disadvantages? – may be only sparsely filled – geometry may still be clumped MIT EECS 6. 837, Durand Cutler

Questions? MIT EECS 6. 837, Durand Cutler

Questions? MIT EECS 6. 837, Durand Cutler

Today • • Review & Schedule Motivation – Distribution Ray Tracing Bounding Boxes Spatial

Today • • Review & Schedule Motivation – Distribution Ray Tracing Bounding Boxes Spatial Acceleration Data Structures – Regular Grid – Adaptive Grids – Hierarchical Bounding Volumes • Flattening the transformation hierarchy MIT EECS 6. 837, Durand Cutler

Adaptive Grids • Subdivide until each cell contains no more than n elements, or

Adaptive Grids • Subdivide until each cell contains no more than n elements, or maximum depth d is reached Nested Grids Octree/(Quadtree) MIT EECS 6. 837, Durand Cutler

Primitives in an Adaptive Grid • Can live at intermediate levels, or be pushed

Primitives in an Adaptive Grid • Can live at intermediate levels, or be pushed to lowest level of grid Octree/(Quadtree) MIT EECS 6. 837, Durand Cutler

Adaptive Grid Discussion • Advantages? – grid complexity matches geometric density • Disadvantages? –

Adaptive Grid Discussion • Advantages? – grid complexity matches geometric density • Disadvantages? – more expensive to traverse (especially octree) MIT EECS 6. 837, Durand Cutler

Bounding Volume Hierarchy • Find bounding box of objects • Split objects into two

Bounding Volume Hierarchy • Find bounding box of objects • Split objects into two groups • Recurse MIT EECS 6. 837, Durand Cutler

Bounding Volume Hierarchy • Find bounding box of objects • Split objects into two

Bounding Volume Hierarchy • Find bounding box of objects • Split objects into two groups • Recurse MIT EECS 6. 837, Durand Cutler

Bounding Volume Hierarchy • Find bounding box of objects • Split objects into two

Bounding Volume Hierarchy • Find bounding box of objects • Split objects into two groups • Recurse MIT EECS 6. 837, Durand Cutler

Bounding Volume Hierarchy • Find bounding box of objects • Split objects into two

Bounding Volume Hierarchy • Find bounding box of objects • Split objects into two groups • Recurse MIT EECS 6. 837, Durand Cutler

Bounding Volume Hierarchy • Find bounding box of objects • Split objects into two

Bounding Volume Hierarchy • Find bounding box of objects • Split objects into two groups • Recurse MIT EECS 6. 837, Durand Cutler

Where to split objects? • At midpoint OR • Sort, and put half of

Where to split objects? • At midpoint OR • Sort, and put half of the objects on each side OR • Use modeling hierarchy MIT EECS 6. 837, Durand Cutler

Intersection with BVH • Check subvolume with closer intersection first MIT EECS 6. 837,

Intersection with BVH • Check subvolume with closer intersection first MIT EECS 6. 837, Durand Cutler

Intersection with BVH • Don't return intersection immediately if the other subvolume may have

Intersection with BVH • Don't return intersection immediately if the other subvolume may have a closer intersection MIT EECS 6. 837, Durand Cutler

Bounding Volume Hierarchy Discussion • Advantages – easy to construct – easy to traverse

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 MIT EECS 6. 837, Durand Cutler

Today • • • Review & Schedule Motivation – Distribution Ray Tracing Bounding Boxes

Today • • • Review & Schedule Motivation – Distribution Ray Tracing Bounding Boxes Spatial Acceleration Data Structures Flattening the transformation hierarchy MIT EECS 6. 837, Durand Cutler

Transformation Hierarchy • Group & Transformation hierarchy may not be a good spatial hierarchy

Transformation Hierarchy • Group & Transformation hierarchy may not be a good spatial hierarchy group transform A transform C transform B group Flatten transform AB transform D transform E MIT EECS 6. 837, Durand Cutler transform CD transform CE

Questions? MIT EECS 6. 837, Durand Cutler

Questions? MIT EECS 6. 837, Durand Cutler

Assignment 4 (due Oct 15 th) • • Bounding boxes for primitives Regular grid

Assignment 4 (due Oct 15 th) • • Bounding boxes for primitives Regular grid acceleration data structure Flatten the transformation hierarchy Collect statistics – Average # of rays per pixel – Average # of ray/primitive intersections per pixel • Extra Credit: Distribution Ray Tracing (and anything else from past weeks) MIT EECS 6. 837, Durand Cutler

Next Time: Curves & Surfaces MIT EECS 6. 837, Durand Cutler

Next Time: Curves & Surfaces MIT EECS 6. 837, Durand Cutler