Nima Kalantari
CSCE 441 - Computer Graphics
Ray Tracing (Acceleration)
Some slides from Ren Ng
Ray Tracing – Performance Challenges
Ray Tracing – Performance Challenges
San Miguel Scene, 10.7M triangles
Jun Yan, Tracy Renderer
Ray Tracing – Performance Challenges
Plant Ecosystem, 20M triangles
Deussen et al; Pharr & Humphreys, PBRT
Outline
Bounding Volumes
Ray-Intersection With Box
Ray Intersection with Axis-Aligned Box
txmin
txmax
tymin
tymax
Note: tymin < 0
Intersections with y planes
Intersections with x planes
tmin
tmax
Final intersection result
How do we know when the ray misses the box?
Optimize Ray-Plane Intersection For Axis-Aligned Planes?
3 subtractions, 6 multiplies, 1 division
1 subtraction, 1 division
General
Perpendicular�to x-axis
Outline
Uniform Spatial Partitions (Grids)
Preprocess – Build Acceleration Grid
|
Preprocess – Build Acceleration Grid
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
Preprocess – Build Acceleration Grid
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
Ray-Scene Intersection
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
Step through grid in ray traversal order
For each grid cell test intersection with all objects stored at that cell
Grid Resolution?
One cell
|
Grid Resolution?
Too many cells
| | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | |
Careful! Objects Overlapping Multiple Cells
What goes wrong here?
Solution?
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
Uniform Grids – When They Work Well
Deussen et al; Pharr & Humphreys, PBRT
Grids work well on large collections of objects�that are distributed evenly in size and space
Uniform Grids – When They Fail
Jun Yan, Tracy Renderer
“Teapot in a stadium” problem
Outline
Spatial Hierarchies
| | ||||||
A
A
Spatial Hierarchies
B
A
| | ||||||
| |||||||
A
B
Spatial Hierarchies
4
5
D
3
2
C
| | ||||||
| | ||||||
| |||||||
A
B
C
D
1
2
3
4
5
1
B
A
Spatial Partitioning Variants
BSP-Tree
KD-Tree
Oct-Tree
KD-Tree Pre-Processing
| |||||||
| | ||||||
| | ||||||
| |||||||
A
B
C
D
KD-Tree Pre-Processing
| | ||||||
| | ||||||
| |||||||
4
5
D
3
2
C
A
B
C
D
1
B
A
Root
Internal Nodes
Leaf Nodes
Only leaf nodes store �references to geometry
1
2
3
4
5
KD-Tree Pre-Processing
Spatial Split (KD-Tree)
Spatial Midpoint
Spatial Split (KD-Tree)
Median Object
Top-Down Recursive In-Order Traversal
| | ||||||
| | ||||||
| |||||||
4
5
D
3
2
C
A
B
C
D
1
B
A
Top-Down Recursive In-Order Traversal
4
5
D
3
2
C
| | ||||||
| | ||||||
| |||||||
A
B
C
1
B
A
Internal node: split
D
Top-Down Recursive In-Order Traversal
4
5
D
3
2
C
| | ||||||
| | ||||||
| |||||||
B
C
1
B
A
Leaf node: intersect�all objects
D
A
Top-Down Recursive In-Order Traversal
4
5
D
3
2
C
| | ||||||
| | ||||||
| |||||||
B
C
1
B
A
Internal node: split
D
A
Top-Down Recursive In-Order Traversal
4
5
D
3
2
C
| | ||||||
| | ||||||
| |||||||
B
C
1
B
A
Leaf node: intersect�all objects
D
A
Top-Down Recursive In-Order Traversal
4
5
D
3
2
C
| | ||||||
| | ||||||
| |||||||
B
C
1
B
A
Internal node: split
D
A
Top-Down Recursive In-Order Traversal
4
5
D
3
2
C
| | ||||||
| | ||||||
| |||||||
B
C
1
B
A
A
Leaf node: intersect�all objects
D
Top-Down Recursive In-Order Traversal
4
5
D
3
2
C
| | ||||||
| | ||||||
| |||||||
B
C
D
1
B
A
Intersection found
A
Outline
Spatial vs Object Partitions
Bounding Volume Hierarchy (BVH)
Root
Bounding Volume Hierarchy (BVH)
Bounding Volume Hierarchy (BVH)
Bounding Volume Hierarchy (BVH)
C
D
B
A
A
B
C
D
Bounding Volume Hierarchy (BVH)
BVH Pre-Processing
BVH Pre-Processing
BVH Pre-Processing
BVH Pre-Processing
BVH Pre-Processing
BVH Recursive Traversal
Intersect (Ray ray, BVH node)
{
if (ray misses node.bbox) return;
if (node is a leaf node)
test intersection with all objs;
return closest intersection;
hit1 = Intersect (ray, node.child1);
hit2 = Intersect (ray, node.child2);
return closer of hit1, hit2;
}
node
child1
child2