spatial partitioning data structuresa quick calculation number of pixels on screen (1080p): • 1920...
TRANSCRIPT
![Page 1: Spatial Partitioning Data StructuresA Quick Calculation Number of pixels on screen (1080P): • 1920 x 1080 = 2,073,600 Number of triangles • ~millions Number of ray-triangle intersections:](https://reader036.vdocuments.net/reader036/viewer/2022072902/5f2eb0a75cc4432b8f1af676/html5/thumbnails/1.jpg)
Spatial Partitioning Data Structures
![Page 2: Spatial Partitioning Data StructuresA Quick Calculation Number of pixels on screen (1080P): • 1920 x 1080 = 2,073,600 Number of triangles • ~millions Number of ray-triangle intersections:](https://reader036.vdocuments.net/reader036/viewer/2022072902/5f2eb0a75cc4432b8f1af676/html5/thumbnails/2.jpg)
A Quick Calculation
Number of pixels on screen (1080P):
• 1920 x 1080 = 2,073,600
![Page 3: Spatial Partitioning Data StructuresA Quick Calculation Number of pixels on screen (1080P): • 1920 x 1080 = 2,073,600 Number of triangles • ~millions Number of ray-triangle intersections:](https://reader036.vdocuments.net/reader036/viewer/2022072902/5f2eb0a75cc4432b8f1af676/html5/thumbnails/3.jpg)
A Quick Calculation
Number of pixels on screen (1080P):
• 1920 x 1080 = 2,073,600
Number of triangles
• ~millions
Number of ray-triangle intersections:
• ~10^12 intersections per frame
![Page 4: Spatial Partitioning Data StructuresA Quick Calculation Number of pixels on screen (1080P): • 1920 x 1080 = 2,073,600 Number of triangles • ~millions Number of ray-triangle intersections:](https://reader036.vdocuments.net/reader036/viewer/2022072902/5f2eb0a75cc4432b8f1af676/html5/thumbnails/4.jpg)
A Quick Calculation
Number of pixels on screen (1080P):
• 1920 x 1080 = 2,073,600
Number of triangles
• ~millions
Number of ray-triangle intersections:
• ~10^12 intersections per frame
Now add antialiasing, shadow rays, reflection rays, ……
![Page 5: Spatial Partitioning Data StructuresA Quick Calculation Number of pixels on screen (1080P): • 1920 x 1080 = 2,073,600 Number of triangles • ~millions Number of ray-triangle intersections:](https://reader036.vdocuments.net/reader036/viewer/2022072902/5f2eb0a75cc4432b8f1af676/html5/thumbnails/5.jpg)
Bounding Boxes
Fit boxes around objects
![Page 6: Spatial Partitioning Data StructuresA Quick Calculation Number of pixels on screen (1080P): • 1920 x 1080 = 2,073,600 Number of triangles • ~millions Number of ray-triangle intersections:](https://reader036.vdocuments.net/reader036/viewer/2022072902/5f2eb0a75cc4432b8f1af676/html5/thumbnails/6.jpg)
Bounding Boxes
Fit boxes around objects
Check ray-box first
![Page 7: Spatial Partitioning Data StructuresA Quick Calculation Number of pixels on screen (1080P): • 1920 x 1080 = 2,073,600 Number of triangles • ~millions Number of ray-triangle intersections:](https://reader036.vdocuments.net/reader036/viewer/2022072902/5f2eb0a75cc4432b8f1af676/html5/thumbnails/7.jpg)
Bounding Boxes
Fit boxes around objects
Check ray-box first
Then check objects
![Page 8: Spatial Partitioning Data StructuresA Quick Calculation Number of pixels on screen (1080P): • 1920 x 1080 = 2,073,600 Number of triangles • ~millions Number of ray-triangle intersections:](https://reader036.vdocuments.net/reader036/viewer/2022072902/5f2eb0a75cc4432b8f1af676/html5/thumbnails/8.jpg)
Bounding Boxes
What if we have a single complex object?
Cut into pieces, treat as separate?
![Page 9: Spatial Partitioning Data StructuresA Quick Calculation Number of pixels on screen (1080P): • 1920 x 1080 = 2,073,600 Number of triangles • ~millions Number of ray-triangle intersections:](https://reader036.vdocuments.net/reader036/viewer/2022072902/5f2eb0a75cc4432b8f1af676/html5/thumbnails/9.jpg)
Bounding Volume Hierarchy
For points:root
![Page 10: Spatial Partitioning Data StructuresA Quick Calculation Number of pixels on screen (1080P): • 1920 x 1080 = 2,073,600 Number of triangles • ~millions Number of ray-triangle intersections:](https://reader036.vdocuments.net/reader036/viewer/2022072902/5f2eb0a75cc4432b8f1af676/html5/thumbnails/10.jpg)
Bounding Volume Hierarchy
For points:root
![Page 11: Spatial Partitioning Data StructuresA Quick Calculation Number of pixels on screen (1080P): • 1920 x 1080 = 2,073,600 Number of triangles • ~millions Number of ray-triangle intersections:](https://reader036.vdocuments.net/reader036/viewer/2022072902/5f2eb0a75cc4432b8f1af676/html5/thumbnails/11.jpg)
Bounding Volume Hierarchy
For points:root
![Page 12: Spatial Partitioning Data StructuresA Quick Calculation Number of pixels on screen (1080P): • 1920 x 1080 = 2,073,600 Number of triangles • ~millions Number of ray-triangle intersections:](https://reader036.vdocuments.net/reader036/viewer/2022072902/5f2eb0a75cc4432b8f1af676/html5/thumbnails/12.jpg)
Bounding Volume Hierarchy
For points:root
![Page 13: Spatial Partitioning Data StructuresA Quick Calculation Number of pixels on screen (1080P): • 1920 x 1080 = 2,073,600 Number of triangles • ~millions Number of ray-triangle intersections:](https://reader036.vdocuments.net/reader036/viewer/2022072902/5f2eb0a75cc4432b8f1af676/html5/thumbnails/13.jpg)
Bounding Volume Hierarchy
Top-down approach:
BuildBVH(points P)
if P contains one point
return leaf;
compute bounding box
find longest axis
split points into groups {L, R} along this axis
return { BuildBVH(L), BuildBVH(R) };
![Page 14: Spatial Partitioning Data StructuresA Quick Calculation Number of pixels on screen (1080P): • 1920 x 1080 = 2,073,600 Number of triangles • ~millions Number of ray-triangle intersections:](https://reader036.vdocuments.net/reader036/viewer/2022072902/5f2eb0a75cc4432b8f1af676/html5/thumbnails/14.jpg)
Bounding Volume Hierarchy
Bottom-up approach (faster, harder):
• sort along space-fillingfractal (z-order curve)
• implement using bitfiddling (Morton codes)
![Page 15: Spatial Partitioning Data StructuresA Quick Calculation Number of pixels on screen (1080P): • 1920 x 1080 = 2,073,600 Number of triangles • ~millions Number of ray-triangle intersections:](https://reader036.vdocuments.net/reader036/viewer/2022072902/5f2eb0a75cc4432b8f1af676/html5/thumbnails/15.jpg)
BVH Traversal
For points:root
![Page 16: Spatial Partitioning Data StructuresA Quick Calculation Number of pixels on screen (1080P): • 1920 x 1080 = 2,073,600 Number of triangles • ~millions Number of ray-triangle intersections:](https://reader036.vdocuments.net/reader036/viewer/2022072902/5f2eb0a75cc4432b8f1af676/html5/thumbnails/16.jpg)
BVH Traversal
For points:root
![Page 17: Spatial Partitioning Data StructuresA Quick Calculation Number of pixels on screen (1080P): • 1920 x 1080 = 2,073,600 Number of triangles • ~millions Number of ray-triangle intersections:](https://reader036.vdocuments.net/reader036/viewer/2022072902/5f2eb0a75cc4432b8f1af676/html5/thumbnails/17.jpg)
BVH Traversal
For points:root
![Page 18: Spatial Partitioning Data StructuresA Quick Calculation Number of pixels on screen (1080P): • 1920 x 1080 = 2,073,600 Number of triangles • ~millions Number of ray-triangle intersections:](https://reader036.vdocuments.net/reader036/viewer/2022072902/5f2eb0a75cc4432b8f1af676/html5/thumbnails/18.jpg)
BVH Traversal
For points:root
![Page 19: Spatial Partitioning Data StructuresA Quick Calculation Number of pixels on screen (1080P): • 1920 x 1080 = 2,073,600 Number of triangles • ~millions Number of ray-triangle intersections:](https://reader036.vdocuments.net/reader036/viewer/2022072902/5f2eb0a75cc4432b8f1af676/html5/thumbnails/19.jpg)
BVH Traversal
For points:root
![Page 20: Spatial Partitioning Data StructuresA Quick Calculation Number of pixels on screen (1080P): • 1920 x 1080 = 2,073,600 Number of triangles • ~millions Number of ray-triangle intersections:](https://reader036.vdocuments.net/reader036/viewer/2022072902/5f2eb0a75cc4432b8f1af676/html5/thumbnails/20.jpg)
BVH Traversal
For points:root
![Page 21: Spatial Partitioning Data StructuresA Quick Calculation Number of pixels on screen (1080P): • 1920 x 1080 = 2,073,600 Number of triangles • ~millions Number of ray-triangle intersections:](https://reader036.vdocuments.net/reader036/viewer/2022072902/5f2eb0a75cc4432b8f1af676/html5/thumbnails/21.jpg)
BVH Analysis
Build time: O(N log^2 N) (top-down)
Traverse time:
![Page 22: Spatial Partitioning Data StructuresA Quick Calculation Number of pixels on screen (1080P): • 1920 x 1080 = 2,073,600 Number of triangles • ~millions Number of ray-triangle intersections:](https://reader036.vdocuments.net/reader036/viewer/2022072902/5f2eb0a75cc4432b8f1af676/html5/thumbnails/22.jpg)
BVH Analysis
Build time: O(N log^2 N) (top-down)
Traverse time:
• worst case: O(N)
• typical case: O(log N)
Advanced traversal strategies possible
![Page 23: Spatial Partitioning Data StructuresA Quick Calculation Number of pixels on screen (1080P): • 1920 x 1080 = 2,073,600 Number of triangles • ~millions Number of ray-triangle intersections:](https://reader036.vdocuments.net/reader036/viewer/2022072902/5f2eb0a75cc4432b8f1af676/html5/thumbnails/23.jpg)
BVH in Practice
Build around triangle primitives
leaves are individual triangles
when building, sort by e.g.triangle center
note: nodes can overlap
![Page 24: Spatial Partitioning Data StructuresA Quick Calculation Number of pixels on screen (1080P): • 1920 x 1080 = 2,073,600 Number of triangles • ~millions Number of ray-triangle intersections:](https://reader036.vdocuments.net/reader036/viewer/2022072902/5f2eb0a75cc4432b8f1af676/html5/thumbnails/24.jpg)
BVH Node Types
Most typical: AABBs
• “axis-aligned bounding boxes”
Other options possible:
![Page 25: Spatial Partitioning Data StructuresA Quick Calculation Number of pixels on screen (1080P): • 1920 x 1080 = 2,073,600 Number of triangles • ~millions Number of ray-triangle intersections:](https://reader036.vdocuments.net/reader036/viewer/2022072902/5f2eb0a75cc4432b8f1af676/html5/thumbnails/25.jpg)
BVH Node Types
Most typical: AABBs
• “axis-aligned bounding boxes”
Other options possible:
• sphere trees
• OBBs (oriented bounding boxes)
![Page 26: Spatial Partitioning Data StructuresA Quick Calculation Number of pixels on screen (1080P): • 1920 x 1080 = 2,073,600 Number of triangles • ~millions Number of ray-triangle intersections:](https://reader036.vdocuments.net/reader036/viewer/2022072902/5f2eb0a75cc4432b8f1af676/html5/thumbnails/26.jpg)
BVH Node Types
Most typical: AABBs
• “axis-aligned bounding boxes”
Other options possible:
• sphere trees
• OBBs
• k-DOPs
![Page 27: Spatial Partitioning Data StructuresA Quick Calculation Number of pixels on screen (1080P): • 1920 x 1080 = 2,073,600 Number of triangles • ~millions Number of ray-triangle intersections:](https://reader036.vdocuments.net/reader036/viewer/2022072902/5f2eb0a75cc4432b8f1af676/html5/thumbnails/27.jpg)
BVH Node Types
Most typical: AABBs
• “axis-aligned bounding boxes”
Other options possible
Complex tradeoff between
• tightness of fit
• traverse cost
• build cost
• memory usage
![Page 28: Spatial Partitioning Data StructuresA Quick Calculation Number of pixels on screen (1080P): • 1920 x 1080 = 2,073,600 Number of triangles • ~millions Number of ray-triangle intersections:](https://reader036.vdocuments.net/reader036/viewer/2022072902/5f2eb0a75cc4432b8f1af676/html5/thumbnails/28.jpg)
BVH Visualized
![Page 29: Spatial Partitioning Data StructuresA Quick Calculation Number of pixels on screen (1080P): • 1920 x 1080 = 2,073,600 Number of triangles • ~millions Number of ray-triangle intersections:](https://reader036.vdocuments.net/reader036/viewer/2022072902/5f2eb0a75cc4432b8f1af676/html5/thumbnails/29.jpg)
Spatial Hashing
Divide space into coarse grid
Each grid cell stores its contents
![Page 30: Spatial Partitioning Data StructuresA Quick Calculation Number of pixels on screen (1080P): • 1920 x 1080 = 2,073,600 Number of triangles • ~millions Number of ray-triangle intersections:](https://reader036.vdocuments.net/reader036/viewer/2022072902/5f2eb0a75cc4432b8f1af676/html5/thumbnails/30.jpg)
Spatial Hashing
Divide space into coarse grid
Each grid cell stores its contents
How to build?
![Page 31: Spatial Partitioning Data StructuresA Quick Calculation Number of pixels on screen (1080P): • 1920 x 1080 = 2,073,600 Number of triangles • ~millions Number of ray-triangle intersections:](https://reader036.vdocuments.net/reader036/viewer/2022072902/5f2eb0a75cc4432b8f1af676/html5/thumbnails/31.jpg)
Spatial Hashing
Divide space into coarse grid
Each grid cell stores its contents
How to build?
• hash function maps points to their cell
• usually very fast (bit twiddling)
Why useful?
![Page 32: Spatial Partitioning Data StructuresA Quick Calculation Number of pixels on screen (1080P): • 1920 x 1080 = 2,073,600 Number of triangles • ~millions Number of ray-triangle intersections:](https://reader036.vdocuments.net/reader036/viewer/2022072902/5f2eb0a75cc4432b8f1af676/html5/thumbnails/32.jpg)
What if primitives aren’t point?
Spatial Hashing
![Page 33: Spatial Partitioning Data StructuresA Quick Calculation Number of pixels on screen (1080P): • 1920 x 1080 = 2,073,600 Number of triangles • ~millions Number of ray-triangle intersections:](https://reader036.vdocuments.net/reader036/viewer/2022072902/5f2eb0a75cc4432b8f1af676/html5/thumbnails/33.jpg)
What if primitives aren’t point?
Spatial Hashing
must rasterizeobjects to grid
object overlapsmultiple cells--> multiple refs
![Page 34: Spatial Partitioning Data StructuresA Quick Calculation Number of pixels on screen (1080P): • 1920 x 1080 = 2,073,600 Number of triangles • ~millions Number of ray-triangle intersections:](https://reader036.vdocuments.net/reader036/viewer/2022072902/5f2eb0a75cc4432b8f1af676/html5/thumbnails/34.jpg)
Spatial Hashing
Pros:
• (relatively) simple to build
• simple data structure (array of pointers)
Cons:
• must pick a good cell size
• works poorly on heterogeneous object distributions
![Page 35: Spatial Partitioning Data StructuresA Quick Calculation Number of pixels on screen (1080P): • 1920 x 1080 = 2,073,600 Number of triangles • ~millions Number of ray-triangle intersections:](https://reader036.vdocuments.net/reader036/viewer/2022072902/5f2eb0a75cc4432b8f1af676/html5/thumbnails/35.jpg)
Quadtree
Start with spatial hash
Split crowded cells into child squares
![Page 36: Spatial Partitioning Data StructuresA Quick Calculation Number of pixels on screen (1080P): • 1920 x 1080 = 2,073,600 Number of triangles • ~millions Number of ray-triangle intersections:](https://reader036.vdocuments.net/reader036/viewer/2022072902/5f2eb0a75cc4432b8f1af676/html5/thumbnails/36.jpg)
Quadtree
Works also for non-point primitives
Danger – must pick maximum depth
![Page 37: Spatial Partitioning Data StructuresA Quick Calculation Number of pixels on screen (1080P): • 1920 x 1080 = 2,073,600 Number of triangles • ~millions Number of ray-triangle intersections:](https://reader036.vdocuments.net/reader036/viewer/2022072902/5f2eb0a75cc4432b8f1af676/html5/thumbnails/37.jpg)
Quadtree
Pros:
• very space-efficient even for heterogeneous object distributions
• simple to build and traverse (bit tricks often used)
Cons:
• must pick max tree depth
• tree not balanced
![Page 38: Spatial Partitioning Data StructuresA Quick Calculation Number of pixels on screen (1080P): • 1920 x 1080 = 2,073,600 Number of triangles • ~millions Number of ray-triangle intersections:](https://reader036.vdocuments.net/reader036/viewer/2022072902/5f2eb0a75cc4432b8f1af676/html5/thumbnails/38.jpg)
Octree
3D version of quadtree
![Page 39: Spatial Partitioning Data StructuresA Quick Calculation Number of pixels on screen (1080P): • 1920 x 1080 = 2,073,600 Number of triangles • ~millions Number of ray-triangle intersections:](https://reader036.vdocuments.net/reader036/viewer/2022072902/5f2eb0a75cc4432b8f1af676/html5/thumbnails/39.jpg)
![Page 40: Spatial Partitioning Data StructuresA Quick Calculation Number of pixels on screen (1080P): • 1920 x 1080 = 2,073,600 Number of triangles • ~millions Number of ray-triangle intersections:](https://reader036.vdocuments.net/reader036/viewer/2022072902/5f2eb0a75cc4432b8f1af676/html5/thumbnails/40.jpg)
Binary Space Partition
Recursively split space using planes
![Page 41: Spatial Partitioning Data StructuresA Quick Calculation Number of pixels on screen (1080P): • 1920 x 1080 = 2,073,600 Number of triangles • ~millions Number of ray-triangle intersections:](https://reader036.vdocuments.net/reader036/viewer/2022072902/5f2eb0a75cc4432b8f1af676/html5/thumbnails/41.jpg)
Binary Space Partition
Recursively split space using planes
Each node stores splitting plane
Each leaf stores object references
![Page 42: Spatial Partitioning Data StructuresA Quick Calculation Number of pixels on screen (1080P): • 1920 x 1080 = 2,073,600 Number of triangles • ~millions Number of ray-triangle intersections:](https://reader036.vdocuments.net/reader036/viewer/2022072902/5f2eb0a75cc4432b8f1af676/html5/thumbnails/42.jpg)
Binary Space Partition
Recursively split space using planes
Each node stores splitting plane
Each leaf stores object references
How to pick good splitting plane?
![Page 43: Spatial Partitioning Data StructuresA Quick Calculation Number of pixels on screen (1080P): • 1920 x 1080 = 2,073,600 Number of triangles • ~millions Number of ray-triangle intersections:](https://reader036.vdocuments.net/reader036/viewer/2022072902/5f2eb0a75cc4432b8f1af676/html5/thumbnails/43.jpg)
Binary Space Partition
Recursively split space using planes
Each node stores splitting plane
Each leaf stores object references
How to pick good splitting plane?
• heuristics / black magic
• good partitioning vs good balance
• special case: axis-aligned planes
![Page 44: Spatial Partitioning Data StructuresA Quick Calculation Number of pixels on screen (1080P): • 1920 x 1080 = 2,073,600 Number of triangles • ~millions Number of ray-triangle intersections:](https://reader036.vdocuments.net/reader036/viewer/2022072902/5f2eb0a75cc4432b8f1af676/html5/thumbnails/44.jpg)
kD Tree
“k-Dimensional Tree”
BSP where each node is vertical or horizontal plane
![Page 45: Spatial Partitioning Data StructuresA Quick Calculation Number of pixels on screen (1080P): • 1920 x 1080 = 2,073,600 Number of triangles • ~millions Number of ray-triangle intersections:](https://reader036.vdocuments.net/reader036/viewer/2022072902/5f2eb0a75cc4432b8f1af676/html5/thumbnails/45.jpg)
kD Tree
How to pick splitting plane?
Goals:
• balance area of two children
• balance number of objects in children
• avoid splitting objects
![Page 46: Spatial Partitioning Data StructuresA Quick Calculation Number of pixels on screen (1080P): • 1920 x 1080 = 2,073,600 Number of triangles • ~millions Number of ray-triangle intersections:](https://reader036.vdocuments.net/reader036/viewer/2022072902/5f2eb0a75cc4432b8f1af676/html5/thumbnails/46.jpg)
kD Tree
How to pick splitting plane?
Common strategy: split next to medianobject along longest direction
![Page 47: Spatial Partitioning Data StructuresA Quick Calculation Number of pixels on screen (1080P): • 1920 x 1080 = 2,073,600 Number of triangles • ~millions Number of ray-triangle intersections:](https://reader036.vdocuments.net/reader036/viewer/2022072902/5f2eb0a75cc4432b8f1af676/html5/thumbnails/47.jpg)
3D Tree
![Page 48: Spatial Partitioning Data StructuresA Quick Calculation Number of pixels on screen (1080P): • 1920 x 1080 = 2,073,600 Number of triangles • ~millions Number of ray-triangle intersections:](https://reader036.vdocuments.net/reader036/viewer/2022072902/5f2eb0a75cc4432b8f1af676/html5/thumbnails/48.jpg)
kD Tree
Pros:
• can tailor cell shape to fit objects
• balanced tree
Cons:
• cells not uniformly placed or shaped
• must pick good max tree depth
![Page 49: Spatial Partitioning Data StructuresA Quick Calculation Number of pixels on screen (1080P): • 1920 x 1080 = 2,073,600 Number of triangles • ~millions Number of ray-triangle intersections:](https://reader036.vdocuments.net/reader036/viewer/2022072902/5f2eb0a75cc4432b8f1af676/html5/thumbnails/49.jpg)
Devils Lurk in the Details
Building the leaves:
• what is the bounding box? (AABBs)
• is my object inside, outside, or crossing a grid cell? (spatial hash/octree)
• is my object on the left, right, or both sides of the split plane? (BSP/kD tree)
• how do I duplicate object referencescorrectly? (all but BVHs)
![Page 50: Spatial Partitioning Data StructuresA Quick Calculation Number of pixels on screen (1080P): • 1920 x 1080 = 2,073,600 Number of triangles • ~millions Number of ray-triangle intersections:](https://reader036.vdocuments.net/reader036/viewer/2022072902/5f2eb0a75cc4432b8f1af676/html5/thumbnails/50.jpg)
Devils Lurk in the Details
Traversing the tree:
• how exactly do I do ray-node intersection?
• ray/box (AABBs, octree)
• ray/plane (BSP and kD trees)
![Page 51: Spatial Partitioning Data StructuresA Quick Calculation Number of pixels on screen (1080P): • 1920 x 1080 = 2,073,600 Number of triangles • ~millions Number of ray-triangle intersections:](https://reader036.vdocuments.net/reader036/viewer/2022072902/5f2eb0a75cc4432b8f1af676/html5/thumbnails/51.jpg)
Devils Lurk in the Details
Traversing the tree:
• how exactly do I do ray-node intersection?
• how do I do it efficiently?
• what if my ray starts inside the scene?
![Page 52: Spatial Partitioning Data StructuresA Quick Calculation Number of pixels on screen (1080P): • 1920 x 1080 = 2,073,600 Number of triangles • ~millions Number of ray-triangle intersections:](https://reader036.vdocuments.net/reader036/viewer/2022072902/5f2eb0a75cc4432b8f1af676/html5/thumbnails/52.jpg)
Kinetic Data Structures
During animation, objects move slowly
Cumulatively update data structures instead of rebuilding every frame
![Page 53: Spatial Partitioning Data StructuresA Quick Calculation Number of pixels on screen (1080P): • 1920 x 1080 = 2,073,600 Number of triangles • ~millions Number of ray-triangle intersections:](https://reader036.vdocuments.net/reader036/viewer/2022072902/5f2eb0a75cc4432b8f1af676/html5/thumbnails/53.jpg)
Kinetic Data Structures
During animation, objects move slowly
Cumulatively update data structures instead of rebuilding every frame
Easy:
• spatial hash
• octree
Annoying:
• BSP trees (kD trees)