rt06 conferencevlastimil havran on the fast construction of spatial hierarchies for ray tracing...
TRANSCRIPT
RT06 conference Vlastimil Havran
On the Fast Construction of Spatial On the Fast Construction of Spatial Hierarchies for Ray TracingHierarchies for Ray Tracing
Vlastimil HavranVlastimil Havran1,21,2
Robert HerzogRobert Herzog11 Hans-Peter Seidel Hans-Peter Seidel11
1 1 MPI InformatikMPI Informatik, , Saarbruecken, GermanySaarbruecken, Germany2 2 Czech Technical University in PragueCzech Technical University in Prague
RT06 conference Vlastimil Havran
Talk OutlineTalk OutlineTalk OutlineTalk Outline
• Previous work
• H-trees
• AH-trees
• Performance results
RT06 conference Vlastimil Havran
Previous WorkPrevious WorkPrevious WorkPrevious Work
RT06 conference Vlastimil Havran
Previous WorkPrevious WorkPrevious WorkPrevious Work
• Kd-trees in O(N log N)
• Bounding volume hierarchies BVH in O(N log N)
• Two-level data structures for hierarchical motion (Wald et al. 03)
• Parallel tree traversal (Szecsi et al. 03)
+ Concurrent papers this year (EGSR’06, EG’06, RT06)
RT06 conference Vlastimil Havran
Approaches to Animated ScenesApproaches to Animated ScenesApproaches to Animated ScenesApproaches to Animated Scenes
• Set of frames, planned motion or not ?
• Some objects are moving (1%, 50%, or 100%?)
Two Approaches
• Rebuild data structures from scratch for every frame
• Update data structures for new object positions
RT06 conference Vlastimil Havran
Most Objects Are Moving ….Most Objects Are Moving ….Most Objects Are Moving ….Most Objects Are Moving ….
• Rebuild from scratch? Why possibly better?
• High quality of data structures for ray tracing
• Fast rebuild from scratch is useful in general, also for larger static scenes
• Fast rebuild from scratch has not been addressed well in CG publications
RT06 conference Vlastimil Havran
Spatial SortingSpatial SortingSpatial SortingSpatial Sorting
• Spatial sorting is a base of ray tracing, it is an extension to quicksort.
• Clearly, sorting is O(N log N)
• Why then radix-sort is O(N) ?
• Project goal: could we make faster spatial sorting in radix-sort like manner?
RT06 conference Vlastimil Havran
Some Other IssuesSome Other IssuesSome Other IssuesSome Other Issues
• Definition: object – 3D geometric primitive, which defines a bounding box, and operation ray-object intersection (point + normal)
• Binary-Interpolation Search: search over the monotonically increasing values in array, using two phases
– interpolation search O(log log N)
– binary search O(log N)
RT06 conference Vlastimil Havran
Intro to Spatial KD-trees (SKD-trees)Intro to Spatial KD-trees (SKD-trees)Intro to Spatial KD-trees (SKD-trees)Intro to Spatial KD-trees (SKD-trees)
• Using two splitting planes
• Proposed by Ooi et al. in 1987 as spatial index for objects as extension to kd-trees
Overlapping Configuration
Disjoint Configuration
RT06 conference Vlastimil Havran
Spatial KD-trees PropertiesSpatial KD-trees PropertiesSpatial KD-trees PropertiesSpatial KD-trees Properties
• Each object is referenced just once
• It is not a spatial subdivision (spatial regions can overlap)
• More memory efficient than BVH (only two planes in a node, not six planes)
• Interesting candidate for ray tracing
RT06 conference Vlastimil Havran
Cost Model for Ray TracingCost Model for Ray TracingCost Model for Ray TracingCost Model for Ray Tracing
• C_T … cost of traversing interior nodes
• C_L … cost of incidence operation in leaves
• C_R … cost of accessing the data from internal or external memory
Typical cost model for a spatial hierarchy:
C = C_T + C_L + C_R
C = C_TS * N_TS + C_LO * N_LO + C_Access * N_Access
RT06 conference Vlastimil Havran
Cost Model Based ConstructionCost Model Based ConstructionCost Model Based ConstructionCost Model Based Construction
• It is also referred to as SAH (surface area heuristics)
• Local greedy decision, where to put splitting planes + recursion + stopping criteria
• Cost = N_L * Prob_L + N_R * Prob_R
• Probability given by surface area of the box of the left and on the right child node
• Problem is evaluation of N_L and N_R
RT06 conference Vlastimil Havran
Normalized Cost Function Normalized Cost Function for Many Objectsfor Many Objects
Normalized Cost Function Normalized Cost Function for Many Objectsfor Many Objects
RT06 conference Vlastimil Havran
SKD-tree + Cost ModelSKD-tree + Cost ModelSKD-tree + Cost ModelSKD-tree + Cost Model
• Using buckets to find out minimum of the cost (at most 100 buckets)
• Objects are put to buckets according to their centroids
• Recording also minima and maxima of object boxes in buckets
• Sweep-plane algorithm to compute tight left and right bounding boxes
RT06 conference Vlastimil Havran
Performance of Pure SKD-treesPerformance of Pure SKD-treesPerformance of Pure SKD-treesPerformance of Pure SKD-trees
• It is rather low, not competitive with kd-trees
• Low performance means: too many traversal steps and ray-object intersections
• Need for better bounding of objects
• A hybrid data structures using bounding primitives and SKD-tree nodes
RT06 conference Vlastimil Havran
How Many Bounding Volume Primitives How Many Bounding Volume Primitives in 3D ?in 3D ?How Many Bounding Volume Primitives How Many Bounding Volume Primitives in 3D ?in 3D ?
• Assumption: axis-aligned bounding planes
• In total 63 possibilities:
– 1 plane, 6 cases – corresponds to kd-tree
– 2 planes, 15 cases – we use only parallel planes (3 cases in 3D)
– 3 planes, 20 cases
– 4 planes, 15 cases
– 5 planes, 6 cases
– 6 planes, 1 case – corresponds to BVH
RT06 conference Vlastimil Havran
H-trees: SKD-trees + H-trees: SKD-trees + Bounding Volumes Primitives Bounding Volumes PrimitivesH-trees: SKD-trees + H-trees: SKD-trees + Bounding Volumes Primitives Bounding Volumes Primitives
Seven types of internal nodes
3 types (x,y,z axis)
3 types (x,y,z axis)
1 type (6 planes)
RT06 conference Vlastimil Havran
H-trees: Construction AlgorithmH-trees: Construction AlgorithmH-trees: Construction AlgorithmH-trees: Construction Algorithm
• Select an axis (X, or Y, or Z)
• Decide if to put an bounding node based on the cost (details in the paper)
• Select the number of buckets N (-,10,100)
• Distribute the objects to the buckets - keep minima and maxima in 3 axis in the bucket
• By sweep-plane compute cost function for all N buckets, select minimum cost
• Distribute the objects into left and right child
• Recurse until having one object in a node (leaf)
RT06 conference Vlastimil Havran
H-trees: ResultsH-trees: ResultsH-trees: ResultsH-trees: Results
• Tests on SPD scenes (30 scenes) by Eric Haines + other 12 scenes of different distributions
• Used by recursive ray tracing and also only ray casting (primary rays)
• In paper results for only 9 scenes.
RT06 conference Vlastimil Havran
Reference: kd-treesReference: kd-treesReference: kd-treesReference: kd-trees
• Termination criteria: 4 objects in a leaf
• No split clipping operation
• O(N log N) complexity
• Highly optimized C++ code (but no SSE, no multithreading)
• Construction: about 1,0 seconds for 100,000 objects for 3.5 leaf references per object on a PC
• Ray tracing: about 300,000 rays per second for completely random rays (= incoherent rays)
RT06 conference Vlastimil Havran
H-trees: ResultsH-trees: ResultsH-trees: ResultsH-trees: Results
• Parts of the cost model
– N_TS … number of traversal steps
– N_LO … number of ray object intersection tests
– N_Access … number of memory accesses
• Timings for H-trees construction
– 2.4 to 12 times faster than kd-trees
• Timings for tracing rays
– Comparable with kd-trees
RT06 conference Vlastimil Havran
AH-trees: MotivationAH-trees: MotivationAH-trees: MotivationAH-trees: Motivation
• Avoid resorting
• Modification of method Reif and Tate, 1998, for a set of points in 3D, achieving time complexity O(N log log N)
• Mimic radix-sort and hence possibly decrease complexity
• Use cost model based on SAH
• Use H-trees nodes
RT06 conference Vlastimil Havran
AH-trees: Avoiding ResortingAH-trees: Avoiding ResortingAH-trees: Avoiding ResortingAH-trees: Avoiding Resorting
• Use buckets in 3D = uniform grid in 3D
• Classify objects as “small” and “oversize”
“Small object” allows to limit the object extent by a box if we know about the presence of an object in a grid cell
RT06 conference Vlastimil Havran
AH-trees: Construction AlgorithmAH-trees: Construction AlgorithmAH-trees: Construction AlgorithmAH-trees: Construction Algorithm
• Select a grid resolution, construct grid
• Classify objects as “small” and “oversize”
• Construct H-trees over “small” objects in predefined position given by 3D grid, in leaves– Recurse by AH-trees construction algorithm
– Recurse by H-trees construction algorithm
– Create references to a leaf
• Decide to which level belong oversize objects
• Create ternary child nodes processing oversize objects, creating AH-trees or H-trees
RT06 conference Vlastimil Havran
AH-trees: Ternary child exampleAH-trees: Ternary child exampleAH-trees: Ternary child exampleAH-trees: Ternary child example
Ternary child
RT06 conference Vlastimil Havran
AH-trees: ResultsAH-trees: ResultsAH-trees: ResultsAH-trees: Results
• Parts of the cost model– N_TS … number of traversal steps
– N_LO … number of ray object intersection tests
– N_Access … number of memory accesses
• Timings for AH-trees construction– 4 to 20 times faster than kd-trees
• Timings for tracing rays– Up to 4 times slower than kd-trees for skewed object
distribution
– Comparable to kd-trees for moderately uniform object distribution
RT06 conference Vlastimil Havran
AH-trees: ConsiderationAH-trees: ConsiderationAH-trees: ConsiderationAH-trees: Consideration
• The deeper in the hierarchy in a single grid, the resolution of cost function evaluation is smaller
• The spatial sorting is approximate using the object centroids
• There is a tradeoff between time complexity for construction and ray tracing performance
• For limited object size O(N log log N)
RT06 conference Vlastimil Havran
Ray Traversal AlgorithmRay Traversal AlgorithmRay Traversal AlgorithmRay Traversal Algorithm
• C/C++ switch for more node types (no problem, CPU branch prediction fails anyway)
• Interval-based technique similar to kd-trees (but overlapping intervals)
• The source code is straightforward
• For AH-trees the ternary child subtrees are traversed first
RT06 conference Vlastimil Havran
ConclusionConclusionConclusionConclusion
• Hybrid spatial hierarchy
• H-trees introduced as SKD-tree nodes + bounding volume nodes
• AH-trees as way of approximate sorting for H-trees, achieving smaller construction time and worse performance (tradeoff)
• Performance results in the paper
RT06 conference Vlastimil Havran
Future WorkFuture WorkFuture WorkFuture Work
• Implementation work: ray packets for H-trees
• Research work: tuning between construction time and performance for AH-trees
• Hybrid trees with more types of nodes
RT06 conference Vlastimil Havran
Take Home MessageTake Home MessageTake Home MessageTake Home Message
• Efficient ray tracing =
Efficient spatial hierarchy (tree)
• Efficient = performance = cost model
• Efficient spatial hierarchy
– top-down construction
– cost-based model decision (with SAH)
– termination criteria
• State of the art ?
RT06 conference Vlastimil Havran
Popper’s model of natural sciencesPopper’s model of natural sciencesPopper’s model of natural sciencesPopper’s model of natural sciences
real inputs
experimentsdesign
analysis implementation
Falsifiable hypothesis
Asymptotic bounds
induction
deduction
deduction
Karl Popper, 1934
(The Logic of Scientific Discovery)