π± π, πβ² = π(π, πβ²) π π, πβ² +
π»
π π, πβ², πβ²β² π± πβ², πβ²β² ππβ²β²
INFOMAGR β Advanced Graphics
Jacco Bikker - February β April 2016
Welcome! , = (, ) , + , , - - PowerPoint PPT Presentation
INFOMAGR Advanced Graphics Jacco Bikker - February April 2016 Welcome! , = (, ) , + , , , Todays Agenda:
π± π, πβ² = π(π, πβ²) π π, πβ² +
π»
π π, πβ², πβ²β² π± πβ², πβ²β² ππβ²β²
Jacco Bikker - February β April 2016
Advanced Graphics β Acceleration Structures 3 Just Cause 3
Avalanche Studios, 2015
World War Z
Paramount Pictures, 2013
Characteristics
Rasterization:
Ray Tracing:
Advanced Graphics β Acceleration Structures 4
Heaven7, Exceed, 2000 LOTR: The Return of the King, 2003 Mirrorβs Edge, DICE, 2008 Crysis, 2007
Characteristics
Reality:
Advanced Graphics β Acceleration Structures 5
Crysis, 2007
Cost Breakdown for Ray Tracing:
Mind scalability as well as constant cost. Example: scene consisting of 1k spheres and 4 light sources, diffuse materials, rendered to 1M pixels: 1π Γ 5 Γ 1π = 5 β 109 ray/prim intersections. (multiply by desired framerate for realtime)
Optimizing Ray Tracing
Options:
Note for option 1: At 5 billion ray/primitive intersections, we will have to bring down the cost of a single intersection to 1 cycle on a 5Ghz CPU β if we want one frame per second.
Advanced Graphics β Acceleration Structures 6
Crysis, 2007
Complex Primitives
More expressive than a triangle:
*: Benthin et al., Packet-based Ray Tracing of Catmull-Clark Subdivision Surfaces. 2007. **: Knoll et al., Interactive Ray Tracing of Arbitrary Implicits with SIMD Interval Arithmetic. RTβ07 Proceedings, Pages 11-18 ***: Hart et al., Ray Tracing Deterministic 3-D Fractals. In Proceedings of SIGGRAPH β89, pages 289-296.
Advanced Graphics β Acceleration Structures 8
Utah Teapot, Martin Newell, 1975 Meet the Robinsons, Disney, 2007
Rubin & Whitted*
βHierarchically Structured Subspacesβ Proposed scheme:
A transformation matrix allows efficient Intersection of the skewed / rotated boxes, which can tightly enclose actual geometry.
*: S. M. Rubin and T. Whitted. A 3-Dimensional Representation for Fast Rendering of Complex Scenes. In: Proceedings of SIGGRAPH β80, pages 110β116.
Advanced Graphics β Acceleration Structures 9
Amanatides & Woo*
β3DDDA of a regular gridβ The grid can be automatically generated. Considerations:
grid cell
tests
*: J. Amanatides and A. Woo. A Fast Voxel Traversal Algorithm for Ray
Advanced Graphics β Acceleration Structures 10
Glassner*
βHierarchical spatial subdivisionβ Like the grid, octrees can be automatically generated. Advantages over grids:
Disadvantage compared to grids:
*: A. S. Glassner. Space Subdivision for Fast Ray Tracing. IEEE Computer Graphics and Applications, 4:15β22, 1984.
Advanced Graphics β Acceleration Structures 11
BSP Trees
Advanced Graphics β Acceleration Structures 12 root
BSP Tree*
βBinary Space Partitioningβ Split planes are chosen from the geometry. A good split plane:
The BSP tends to suffer from numerical instability (splinter polygons).
*: K. Sung, P. Shirley. Ray Tracing with the BSP Tree. In: Graphics Gems III, Pages 271-274. Academic Press, 1992.
Advanced Graphics β Acceleration Structures 13
Advanced Graphics β Acceleration Structures 14
kD-Tree*
βAxis-aligned BSP treeβ
*: V. Havran, Heuristic Ray Shooting Algorithms. PhD thesis, 2000.
Advanced Graphics β Acceleration Structures 15
kD-Tree Construction*
Given a scene π consisting of π primitives: A kd-tree over π is a binary tree that recursively subdivides the space covered by π.
perpendicular to the coordinate axis;
corresponding voxel.
*: On building fast kD-trees for ray tracing, and on doing that in O(N log N), Wald & Havran, 2006
Advanced Graphics β Acceleration Structures 16
function Build( triangles π, voxel π ) { if (Terminate( π, π )) return new LeafNode( π ) π = FindPlane( π, π ) π
π, π π = Split π with π
ππ = π’ β π (π’ π
π) β 0
ππ = π’ β π (π’ π
π) β 0
return new InteriorNode( p, Build( ππ, π
π ),
Build( ππ, π
π )
) } Function BuildKDTree( triangles π ) { π = πππ£πππ‘ π return Build( π, π ) }
Advanced Graphics β Acceleration Structures 17
Considerations
minimum primitive count, maximum recursion depth
primitives may end up in multiple voxels: required storage hard to predict
empty space reduces probability of having to intersect primitives
good solutions exist β will be discussed later.
Advanced Graphics β Acceleration Structures 18
Traversal*
If intersections are found:
Note: step 2 traverses the tree repeatedly β inefficient.
*: Space-Tracing: a Constant Time Ray-Tracer, Kaplan, 1994
Advanced Graphics β Acceleration Structures 19
Traversal β Alternative Method*
For interior nodes:
If only one child node intersects the ray:
Else (both child nodes intersect the ray):
For leaf nodes:
*: Data Structures for Ray Tracing, Jansen, 1986.
Advanced Graphics β Acceleration Structures 20
kD-Tree Traversal
Traversing a kD-tree is done in a strict order. Ordered traversal means we can stop as soon as we find a valid intersection.
Acceleration Structures
Advanced Graphics β Acceleration Structures 21
Partitioning
space space space space
space
Construction
O(n) O(n log n) O(n2) O(n log n) O(n log n) ? O(n log n)
Quality
low medium good good good low medium
Advanced Graphics β Acceleration Structures 23
Automatic Construction of Bounding Volume Hierarchies
BVH: tree structure, with:
Advanced Graphics β Acceleration Structures 24
Automatic Construction of Bounding Volume Hierarchies
BVH: tree structure, with:
struct BVHNode { AABB bounds; bool isLeaf; BVHNode*[] child; Primitive*[] primitive; };
Advanced Graphics β Acceleration Structures 25
Automatic Construction of Bounding Volume Hierarchies
root left right top bottom top bottom
Advanced Graphics β Acceleration Structures 26
Automatic Construction of Bounding Volume Hierarchies
1. Determine AABB for primitives in array 2. Determine split axis and position 3. Partition 4. Repeat steps 1-3 for each partition Note: Step 3 can be done βin placeβ. This process is identical to QuickSort: the split plane is The βpivotβ.
Advanced Graphics β Acceleration Structures 27
Automatic Construction of Bounding Volume Hierarchies
struct BVHNode { AABB bounds; bool isLeaf; BVHNode* left, *right; Primitive** primList; }; // 24 bytes // 4 bytes // 8 or 16 bytes // ? bytes 12
Advanced Graphics β Acceleration Structures 28
Automatic Construction of Bounding Volume Hierarchies
struct BVHNode { AABB bounds; bool isLeaf; BVHNode* left, *right; int first, count; }; // 24 bytes // 4 bytes // 8 or 16 bytes // 8 bytes 12 primitives primitive indices 1 2 3 4 5 6 7 8 9 10 11 12
Advanced Graphics β Acceleration Structures 29
Automatic Construction of Bounding Volume Hierarchies
void BVH::ConstructBVH( Primitive* primitives ) { // create index array indices = new uint[N]; for( int i = 0; i < N; i++ ) indices[i] = i; // allocate BVH root node root = new BVHNode(); // subdivide root node root->first = 0; root->count = N; root->bounds = CalculateBounds( primitives, root->first, root->count ); root->Subdivide(); } void BVHNode::Subdivide() { if (count < 3) return; this.left = new BVHNode(); this.right = new BVHNode(); Partition(); this.left->Subdivide(); this.right->Subdivide(); this.isLeaf = false; }
Advanced Graphics β Acceleration Structures 30
Automatic Construction of Bounding Volume Hierarchies
void BVH::ConstructBVH( Primitive* primitives ) { // create index array indices = new uint[N]; for( int i = 0; i < N; i++ ) indices[i] = i; // allocate BVH root node pool = new BVHNode( N * 2 β 1 ); root = pool[0]; poolPtr = 2; // subdivide root node root->first = 0; root->count = N; root->bounds = CalculateBounds( primitives, root->first, root->count ); root->Subdivide(); } void BVHNode::Subdivide() { if (count < 3) return; this.left = pool[poolPtr++]; this.right = pool[poolPtr++]; Partition(); this.left->Subdivide(); this.right->Subdivide(); this.isLeaf = false; }
Advanced Graphics β Acceleration Structures 31
Automatic Construction of Bounding Volume Hierarchies
struct BVHNode { AABB bounds; bool isLeaf; int left, right; int first, count; }; // 24 bytes // 4 bytes // 8 bytes // 8 bytes, total 44 bytes 12 primitives primitive indices 1 2 3 4 5 6 7 8 9 10 11 12 BVH nodes
Advanced Graphics β Acceleration Structures 32
Automatic Construction of Bounding Volume Hierarchies
struct BVHNode { AABB bounds; int left; int first, count; }; // 24 bytes // 4 bytes // 8 bytes, total 36 12 primitives primitive indices 1 2 3 4 5 6 7 8 9 10 11 12 BVH nodes
Advanced Graphics β Acceleration Structures 33
Automatic Construction of Bounding Volume Hierarchies
struct BVHNode { AABB bounds; int leftFirst; int count; }; // 24 bytes // 4 bytes // 4 bytes, total 32 ο 12 primitives primitive indices 1 2 3 4 5 6 7 8 9 10 11 12 BVH nodes
Advanced Graphics β Acceleration Structures 34
Automatic Construction of Bounding Volume Hierarchies
Optimal BVH representation:
Note: the BVH is now βrelocatableβ and thus βserializableβ.
Advanced Graphics β Acceleration Structures 35
BVH Traversal
root left right top bottom top bottom
Advanced Graphics β Acceleration Structures 36
BVH Traversal
Basic process:
BVHNode::Traverse( Ray r ) { if (!r.Intersects( bounds )) return; if (isleaf()) { IntersectPrimitives(); } else { pool[left].Traverse( r ); pool[left + 1].Traverse( r ); } }
Ray: vec3 O, D float t
Advanced Graphics β Acceleration Structures 37
BVH Traversal
Ordered traversal, option 1:
Ordered traversal, option 2:
Ordered traversal, option 3:
Advanced Graphics β Acceleration Structures 38
BVH Traversal
Ordered traversal of a BVH is approximative.
And:
However:
intersection distance.
Jacco Bikker - February β April 2016
next lecture: βThe Perfect BVHβ