Bounding volume hierarchy (BVH) is an advanced data structure widely used in computer graphics, especially in ray tracing algorithms. The primary function of BVH is to effectively organize geometric data, such as polygons or triangles that compose a 3D model, to accelerate the process of ray-object intersection tests.
A bounding volume hierarchy is a tree data structure on a set of geometric objects.
All geometric objects are wrapped in bounding volumes that form the tree's nodes.
These nodes are then grouped as small sets and enclosed within the larger bounding volumes, forming the hierarchy of the tree.
A bounding volume can take various forms, such as a sphere, a box (AABB - Axis Aligned Bounding Box), or an oriented bounding box (OBB), depending on the application's specific requirements.
The choice of bounding volume can impact the efficiency of the BVH and is often chosen based on a trade-off between precision and computational speed.
The major purpose of using a bounding volume hierarchy is to minimize the number of ray-object intersection tests required in ray tracing algorithms.
Instead of testing each ray against every object in the scene, BVH allows the algorithm to test the ray against a bounding volume.
If the ray does not intersect the bounding volume, all objects within that volume are automatically discarded, leading to significant computational savings.
The process of constructing a bounding volume hierarchy is explained below.
Object partitioning: It involves partitioning the objects in the scene into two groups. Several strategies to do this include a median or a surface area heuristic (SAH).
Bounding volume creation: After partitioning, a bounding volume is created for each group, encapsulating all the objects within.
Recursive splitting: The process is repeated recursively, further splitting each group and creating bounding volumes until each group contains only one object.
Here,
Slide 1: It shows a polygon with
Suppose that the polygon is made of 6000 triangles.
The ray-object intersection test with the
Slide 2: It shows a polygon with the bounding volume (a square).
We need to check for intersection with the simple shape first.
Since, only
Note:
Wrap things that are hard to check for intersection in things that are easy to check.
Always check for intersection with the simple shape first.
The number of ray-object intersection tests can be a significant factor affecting the performance of a ray tracing algorithm.
You can quantify the tests by using the approach explained below.
Total rays: The total number of rays can be calculated based on the size of the image and the number of rays per pixel.
Each pixel in the image represents one primary ray sent from the camera into the scene.
If multiple rays are cast per pixel, the number is multiplied by the rays per pixel.
Number of ray-object intersection tests: The number of tests can be calculated by multiplying the total number of rays with the number of triangles (or other geometric form that the object is composed of) in the object.
Note: The above formula assumes a brute force approach where each ray is tested against every triangle in the object.
Let's consider an example.
Size of an image
Rays per pixel
Number of triangles
Calculate the total rays as follows:
Then, we calculate the number of ray-object intersection tests:
In this example, the ray tracer must perform over 8 billion ray-triangle intersection tests. It clearly illustrates the need for efficient data structures like bounding volume hierarchies to reduce the number of intersection tests and improve overall performance.
In terms of efficiency, it is important to balance the cost of testing rays against the bounding volumes and the cost of intersecting the objects within.
The formula to calculate the cost is given below.
Where,
The cost here serves as a measure to compare different BVH structures or split strategies during the BVH construction process.
There are many ways to build a tree for bounding volume hierarchy.
Sort the surfaces along the axis before dividing into two boxes
Carefully choose axis each time
Choose axis that minimizes the sum of volumes
Bounding volume hierarchies work well with:
Binary trees
Roughly balanced trees
Boxes of sibling trees not overlapping too much