ray tracing, part 2
DESCRIPTION
Christian Lauterbach COMP 770, 2/16/2009. Ray Tracing, Part 2. Overview. Acceleration structures Spatial hierarchies Object hierarchies Interactive Ray Tracing techniques Ray packets Optimized hierarchy construction. Last lecture. Ray Tracing For each pixel: generate ray - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Ray Tracing, Part 2](https://reader030.vdocuments.site/reader030/viewer/2022033108/568162a0550346895dd318b6/html5/thumbnails/1.jpg)
Ray Tracing, Part 2
Christian Lauterbach
COMP 770, 2/16/2009
![Page 2: Ray Tracing, Part 2](https://reader030.vdocuments.site/reader030/viewer/2022033108/568162a0550346895dd318b6/html5/thumbnails/2.jpg)
Overview
Acceleration structures Spatial hierarchies Object hierarchies
Interactive Ray Tracing techniques Ray packets Optimized hierarchy construction
![Page 3: Ray Tracing, Part 2](https://reader030.vdocuments.site/reader030/viewer/2022033108/568162a0550346895dd318b6/html5/thumbnails/3.jpg)
Last lecture
Ray Tracing For each pixel: generate ray
For each primitive: Does ray hit primitive?
Yes: Test depth / write color
That means linear time complexity in number of primitives!
![Page 4: Ray Tracing, Part 2](https://reader030.vdocuments.site/reader030/viewer/2022033108/568162a0550346895dd318b6/html5/thumbnails/4.jpg)
Acceleration structures
Goal: fast search operation for ray that returns all intersecting primitives Then test only against those Operation should take sub-linear time
In practice: conservative superset
![Page 5: Ray Tracing, Part 2](https://reader030.vdocuments.site/reader030/viewer/2022033108/568162a0550346895dd318b6/html5/thumbnails/5.jpg)
Acceleration structures
Broad classification: Spatial hierarchies
Grids Octrees Kd-trees, BSP trees
Object hierarchies Bounding volume hierarchies Spatial kd-trees
![Page 6: Ray Tracing, Part 2](https://reader030.vdocuments.site/reader030/viewer/2022033108/568162a0550346895dd318b6/html5/thumbnails/6.jpg)
Spatial hierarchies: grids
Regular subdivision of space into cells Cells almost always cubes Each object is referenced in
each cell it overlaps Nested grids also possible Ray tracing with the grid:
Find entry cell of ray For each cell:
Intersect with all objects in cell. If hit, terminate.
Otherwise, walk to next cell ray can hit
![Page 7: Ray Tracing, Part 2](https://reader030.vdocuments.site/reader030/viewer/2022033108/568162a0550346895dd318b6/html5/thumbnails/7.jpg)
Spatial hierarchies: kd-trees Binary tree of space subdivisions
Each is axis-aligned plane x
y y
![Page 8: Ray Tracing, Part 2](https://reader030.vdocuments.site/reader030/viewer/2022033108/568162a0550346895dd318b6/html5/thumbnails/8.jpg)
Spatial hierarchies: kd-trees Traversing a kd-tree: recursive
Start at root node For current node:
If inner node: Find intersection of ray with plane If ray intersects both children, recurse on
near side, then far side Otherwise, recurse on side it intersects
If leaf node: Intersect with all object. If hit, terminate.
![Page 9: Ray Tracing, Part 2](https://reader030.vdocuments.site/reader030/viewer/2022033108/568162a0550346895dd318b6/html5/thumbnails/9.jpg)
RT with the kd-tree (2)
ray 1
ray 2
ray 3
split plane
'near' node 'far' node
what can the ray possibly hit?
![Page 10: Ray Tracing, Part 2](https://reader030.vdocuments.site/reader030/viewer/2022033108/568162a0550346895dd318b6/html5/thumbnails/10.jpg)
RT with the kd-tree (3)
three cases: hitpoint above split: far node only hitpoint below split: near node only otherwise: near, then far
'above' and 'below' rather vague use distance t along ray
ray = origin + t *direction
![Page 11: Ray Tracing, Part 2](https://reader030.vdocuments.site/reader030/viewer/2022033108/568162a0550346895dd318b6/html5/thumbnails/11.jpg)
RT with the kd-tree (4)
when does the ray intersect?split plane
'near' node 'far' node
t_min
t_max
t_split
![Page 12: Ray Tracing, Part 2](https://reader030.vdocuments.site/reader030/viewer/2022033108/568162a0550346895dd318b6/html5/thumbnails/12.jpg)
Kd-tree traversal
Simple and fast implementation In practice: using stack, not recursion Very quick intersection test (couple
FLOPS + tests)
Overall: logarithmic complexity for each ray
![Page 13: Ray Tracing, Part 2](https://reader030.vdocuments.site/reader030/viewer/2022033108/568162a0550346895dd318b6/html5/thumbnails/13.jpg)
Object hierarchies: BVHs
Different approach: subdivide objects, not space Hierarchical clustering of objects Each cluster represented by bounding volume
Binary tree Each parent node fully contains children
![Page 14: Ray Tracing, Part 2](https://reader030.vdocuments.site/reader030/viewer/2022033108/568162a0550346895dd318b6/html5/thumbnails/14.jpg)
Bounding volumes
Practically anything can be bounding volume Just need ray intersection method
Typical choices: Spheres Axis-aligned bounding boxes (AABBs) Oriented bounding boxes (OBBs) k-DOPs
Trade-off between intersection speed and how closely the BV encloses the geometry
![Page 15: Ray Tracing, Part 2](https://reader030.vdocuments.site/reader030/viewer/2022033108/568162a0550346895dd318b6/html5/thumbnails/15.jpg)
BVH traversal
Recursive algorithm: Start with root node For current node:
Does ray intersect node’s BV? If no, return Is inner node?
Yes, recurse on children Is leaf node?
Intersect with object(s) in node, store intersection results
Note: can’t return after first intersection!
![Page 16: Ray Tracing, Part 2](https://reader030.vdocuments.site/reader030/viewer/2022033108/568162a0550346895dd318b6/html5/thumbnails/16.jpg)
Choosing a structure
There is no ‘best’ acceleration structure All have pros and cons
Grid:+ fast construction- bad for high local detail (teapot/stadium)
![Page 17: Ray Tracing, Part 2](https://reader030.vdocuments.site/reader030/viewer/2022033108/568162a0550346895dd318b6/html5/thumbnails/17.jpg)
Choosing a structure
There is no ‘best’ acceleration structure All have pros and cons
kd-tree:+ fast traversal- expensive build, only static scenes
![Page 18: Ray Tracing, Part 2](https://reader030.vdocuments.site/reader030/viewer/2022033108/568162a0550346895dd318b6/html5/thumbnails/18.jpg)
Choosing a structure
There is no ‘best’ acceleration structure All have pros and cons
BVH:+ can be updated for dynamic scenes- traversal more expensive than kd-tree
![Page 19: Ray Tracing, Part 2](https://reader030.vdocuments.site/reader030/viewer/2022033108/568162a0550346895dd318b6/html5/thumbnails/19.jpg)
Overview
Acceleration structures Spatial hierarchies Object hierarchies
Interactive Ray Tracing techniques Ray packets Optimized hierarchy construction
![Page 20: Ray Tracing, Part 2](https://reader030.vdocuments.site/reader030/viewer/2022033108/568162a0550346895dd318b6/html5/thumbnails/20.jpg)
Ray Packets
Often have large set of rays close together
Idea:trace rays in coherent groups (ray packets)
Viewer Screen
![Page 21: Ray Tracing, Part 2](https://reader030.vdocuments.site/reader030/viewer/2022033108/568162a0550346895dd318b6/html5/thumbnails/21.jpg)
Ray coherence
How does this change tracing? Traversal and object intersection
work on group of rays at a time Also generate secondary (shadow, …)
rays in packets General idea:
If one ray intersects, all are intersected
![Page 22: Ray Tracing, Part 2](https://reader030.vdocuments.site/reader030/viewer/2022033108/568162a0550346895dd318b6/html5/thumbnails/22.jpg)
BVH traversal
Recursive algorithm: Start with root node For current node:
Does ray intersect node’s BV? If no, return Is inner node?
Yes, recurse on children Is leaf node?
Intersect ray with all object(s) in node, store intersection results
![Page 23: Ray Tracing, Part 2](https://reader030.vdocuments.site/reader030/viewer/2022033108/568162a0550346895dd318b6/html5/thumbnails/23.jpg)
BVH packet traversal
Recursive algorithm: Start with root node For current node:
Does any ray intersect node’s BV? If no, return
Is inner node? Yes, recurse on children
Is leaf node? Intersect all rays with all object(s) in node,
store intersection results
![Page 24: Ray Tracing, Part 2](https://reader030.vdocuments.site/reader030/viewer/2022033108/568162a0550346895dd318b6/html5/thumbnails/24.jpg)
Ray packet advantages
Why does this make things faster? Less memory bandwidth: nodes/objects
only loaded once for rays in packet Allows data parallel processing!
Current CPUs: e.g. Intel SSE All GPUs
Disadvantage: Rays can be intersected with
objects/nodes they would never hit!
![Page 25: Ray Tracing, Part 2](https://reader030.vdocuments.site/reader030/viewer/2022033108/568162a0550346895dd318b6/html5/thumbnails/25.jpg)
Data parallelism
Essentially vector operations (SIMD)
Operations work on all elements in parallel
v1 v2 v3 v4 v5 v6 v7 v8
v1 v2 v3 v4 v5 v6 v7 v8
w1 w2 w3 w4 w5 w6 w7 w8+
=v1+w1 v2+w2 v3+w3 v4+w4 v5+w5 v6+w6 v7+w7 v8+w8
![Page 26: Ray Tracing, Part 2](https://reader030.vdocuments.site/reader030/viewer/2022033108/568162a0550346895dd318b6/html5/thumbnails/26.jpg)
Data parallelism
Vector operations usually as fast as a single scalar operation Intel SSE: 4-wide vectors GPUs: 8-32 wide Cell: 4-wide Vector processors: up to 64,000!
![Page 27: Ray Tracing, Part 2](https://reader030.vdocuments.site/reader030/viewer/2022033108/568162a0550346895dd318b6/html5/thumbnails/27.jpg)
SIMD ray processing
Can use SIMD units to parallelize for rays Each vector has one component from
one ray Thus, can process small group at same
speed as one ray!ray1
ray2
ray3
ray4
ray5
ray6
ray7
ray8
trii trii trii trii trii trii trii trii
trii
![Page 28: Ray Tracing, Part 2](https://reader030.vdocuments.site/reader030/viewer/2022033108/568162a0550346895dd318b6/html5/thumbnails/28.jpg)
Optimized hierarchy construction The way the hierarchy is constructed
has high impact on traversal performance