Presentation Description

121 Views

Download Presentation
## 2 . 6. Bounding Volume Hierarchies

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -

**2.6.Bounding Volume Hierarchies**Overview of different forms of bounding volume hierarchy**Bounding Volume Hierarchies**Exploration of different types of bounding volume hierarchy**Bounding Volume Hierarchies**Given a total of n objects, a simple brute force approach towards producing a list of intersecting objects is to consider all object pairings (i.e. n2/2 comparisons). Assuming each object can be described in terms of one of more bounding volumes, by arranging the object’s bounding volumes into a tree-based hierarchy (known as a bounding volume hierarchy), a logarithmic order time complexity can be obtained.**BVH Design Issues: Desirable Characteristics**Desirable characteristics of a game-oriented BVH are likely to include: The nodes contained in any given sub-tree should be spatially ‘close’ to each other. Each node in the hierarchy should be of minimal volume. Pruning a node near the root of the tree should remove more objects from further consideration than removal of a deeper node. The volume of overlap between sibling nodes should be minimal. The hierarchy should be balanced with respect to both its node structure and its content. The worst-case time for queries should not be much worse than the average-case query time. • Aside: BVH differ from spatial partitioning schemes (explored next lecture) in that two BVH volumes can cover the same space and objects are typically only found in a single volume. Spatial partitioning schemes typically require non-overlapping regions but permit objects to be in two or more partitions.**BVH Building Strategies**As the number of possible BVH trees grows exponentially as the number of objects increase it is not possible to use an exhaustive (optimal) search. Instead, heuristic rules are used to direct the BVH construction (selecting the best option from a small number of hopefully near optimal options at each step). There are three main categories of tree construction methods: top-down bottom-up insertion**BVH Building Strategies**• Top-down and bottom-up are off-line methods as they require all primitives to be available before construction starts. Insertion construction is considered on-line as it can be used at game run-time. Top-down: partitioning input set into two (or more) subsets, introduce bounds, and recursing over bounded subsets (typically does not produce best trees, but is easy to implement and hence popular). Bottom-up: start with leaves of the tree, group two (or more) to form a bounding node, progressively grouping bounded volumes until a single node is reached (typically produces best quality BVH, but more difficult to implement). Insertion: incrementally insert an object into the tree so as to minimize some insertion cost measurement**Forms of BVH Construction**Consult the recommended course text for full details of the following approaches: Top-down Construction Bottom-up Construction Incremental (Insertion) Construction Top-down construction is explored next by way of an example.**Top-Down Construction**Top-down construction of a bounding volume hierarchy**Top-down Construction of a BVH**void BuildTopDownBVH(BVHNodetreeNode, ArrayList objects) { Node newNode = new Node(); treeNode.add(newNode); newNode.BoundingVolume = ComputeBoundingVolume(objects); if( objects.Count <= MIN_OBJECTS_PER_LEAF ) { newNode.Type = LEAF; newNode. Objects = objects; } else { newNode.Type = NODE; intsplitIdx = RearrangeAndPartitionObjects(objects); BuildTopDownBVH( newNode.LeftTree, objects.Subset(0,splitIdx)); BuildTopDownBVH( newNode.RightTree, objects.Subset(splitIdx,objects.Count); } } The process of top-down construction can be algorithmically described as: Create an empty node and add to the tree Build a suitable bounding volume around the specified object list If needed, simply store the object list within this node Sort and split the objects into two partitions Recursively build the BVH along the defined left and right sub-trees**Top-down partitioning strategy**Other than selecting which bounding volume to use, the top-down strategy need only define how an input set of objects can be partitioned into two subsets. Typically the input set is divided using a splitting hyperplane. Any primitives intersected by the splitting plane are commonly assigned to the subset within which its centroid belongs, alongside extending subset bounding volume by half the width of the primitive (thereby fully enclosing the primitive and minimising overlap between sibling bounding volumes).**Top-down partitioning strategy**A number of different partitioning strategies might be adopted (depending upon the performance/memory needs, etc. of the application), including: Minimize the sum of the volumes (or surface areas) of the child volumes. Minimize the volume (surface area) of the intersection of the child volumes. Maximize the separation of child volumes. Divide primitives equally between the child volumes (known as a median-cut algorithm, and tends to produced balanced trees) Combinations of above strategies. Assuming spherical bounding volumes Minimal child volume, but high overlap volume Larger child volume, but smaller overlap volume**Top-down partitioning: Halting recursion**The recursive partitioning stops (thereby forming a leaf node) when some termination condition is reached. This can include: The node contains less than some k primitives. The volume of the bounding volume falls below a cut-off limit. The depth of the node has reached a predefined cut-off depth. Partitioning might also fail because: All primitives fall on one side of the split plane. One or both child volumes end up with as many (or nearly as many) primitives as the parent volume. Both child volumes are (almost) as large as the parent volume. In these cases, it is reasonable to try other partitioning criteria before terminating the recursion.**Top-down partitioning: Choice of axis**The choice of which separating axis to use is often restricted to the following: Local x, y, and z coordinate axes (easy to use, also form orthogonal set, i.e. good coverage). Axes from some aligned bounding volume (e.g. from a reference k-DOP). Axes of the parent bounding volume Axis along which variance is greatest (using the dimension with largest spread serves to minimise the size of the child volumes).**Top-down partitioning: Choice of split point**The choice of which split point to use is (also) often restricted to the following: Object median: splitting at the middle object (thereby evenly distributing the primitives and providing a balanced tree). Object mean: splitting at the mean object offset (e.g. along the axis with greatest variance). Bounding volume median: splitting at the middle of the bounding volume (thereby splitting into two equal parts). (a) Splits at object median, (b) splits at object mean, (c) splits at spatial median**Hierarchy Traversal**Approaches to traversing bounding volumes hierarchies**Hierarchy Traversal**Given two BVHs a descent rule is used to determine overlap status when the top-level volumes overlap. Approaches include breadth-first (BFS) and depth-first (DFS) searches. BFS explores all nodes at a given depth before descending. DFS descends down into the tree, backtracking up once a leaf is hit. A decent method is blind (or uninformed) if it only uses the tree structure to select the next node. Informed methods examine node data (e.g. using heuristics) to select the next node (e.g. a best-first search maintains a list of best-scoring moves). For collision detection systems, DFS (possibly a simple heuristic – i.e. basically a best-first approach) is typically favoured over BFS.**Descent Rules**Given two BVHs the following descent strategies might be adopted: Descend A before B (or vice versa). Fully descend into the leaves of A before starting to descend into B. This will be very expensive if B’s root bound fully contains A and/or if A contains lots of nodes. Descend the larger volume. Dynamically determine which BVH node is currently larger and descend into (avoiding the problems of Approach 1). Descend A and B simultaneously. Similar to Approach 2 but without any cost evaluation overhead (but it may not prune space as efficiently). Descend based on overlap. Similar to Approach 2, priortise descent on degree of overlap between BVH regions. • Which type of traversal is most effective depends entirely on the structure of the data, as indicated by the refinery example.**Generic Informed Depth-first traversal**CollisionResult is assumed to store relevant collision detection/contact information An example informed depth-first traversal algorithm is: void BVHInformedDFS(CollisionResult r, BVHNode a, BVHNode b) { if (!BVOverlap(a, b)) return; if (IsLeaf(a) && IsLeaf(b)) { CollidePrimitives(r, a, b); } else { if (DescendA(a, b)) { BVHInformedDFS (r, a->left, b); BVHInformedDFS (r, a->right, b); } else { BVHInformedDFS (r, a, b->left); BVHInformedDFS (r, ,a, b->right); } } } If the bounding volumes do not overlap then simply return If two leaf nodes are found, then perform collision detection on the primitives Descent rule to determine which BVH to follow boolDescendA(BVHNode a, BVHNode b) { return IsLeaf(b) || (!IsLeaf(a) && (SizeOfBV(a) >= SizeOfBV(b))); } Descend into the larger volume**Descent Rules**See the source text book for: A non-recursive, faster, implementation of the generic informed depth-first traversal Simultaneous depth-first traversal algorithm Optimised leaf-directed depth-first traversal**Directed**reading Directed Reading Directed mathematical reading**Directed reading**Read Chapter 6 of Real Time Collision Detection (pp235-284) Related papers can be found from: http://realtimecollisiondetection.net/books/rtcd/references/ Directed reading**Summary**Today we explored: • Bounding volume hierarchies • Overview of top-down construction approaches To do: • Read the directed material • After reading the directed material, have a ponder if this is the type of material you would like to explore within a project.