next up previous
Next: Intersection Rays versus Shadow Up: Optimizations for Bounding Volume Previous: Optimizations for Bounding Volume


Bounding Box Intersections

Intersecting rays with bounding volumes usually accounts for most of the time spent casting rays. This makes bounding volume intersection tests an ideal candidate for optimization. The first issue is what sort of bounding volumes to use. Most of the environments I work with are architectural and have many axis-aligned planar surfaces. This makes axis-aligned bounding boxes ideal. Spheres tend not to work very well for this type of environment.

There are many ways to represent and intersect an axis-aligned bounding box. I have seen bounding box code that computed the intersection point of the ray with the box. If there was an intersection point, the ray hits the box, and if not, the ray misses. There are optimizations that can be made to this approach, such as making sure you only check faces that are oriented towards the ray, and taking advantage of the fact that the planes are axis aligned [11]. Still, the approach is too slow. The first hint of this is that the algorithm computes an intersection point. We don't care about that, we just want a yes or no answer. Kay [8] represented bounding volumes as the intersection of a set of slabs (parallel planes). A slab is stored as a direction, Ds, and an interval, Is, representing the minimum and maximum value in that direction, effectively as two plane equations. The set of slab directions is fixed in advance. In my experience, this approach is most effective when there are three, axis aligned, slab directions. This is just another way of storing a bounding box, we store minimum and maximum values along each axis.

Figure 2: Pseudocode for intersecting a ray with a box represented as axis aligned slabs.
\begin{figure}
\center
\begin{pseudocode}
\par\PCBegin{bool \PCFunction{RaySlabs...
...PCEnd{\PCKey{for}}
\PC \PCKey{return true}
\PCEnd{}
\end{pseudocode}\end{figure}

Given this representation, we can intersect a bounding box fairly efficiently. We show this in pseudocode in Figure 2. This code isn't as simple as it looks due to the comparisons of the IsEmpty and Intersection functions and the need to reverse the min and max values of the interval when dividing by a negative number, but it is still much faster than computing the intersection point with the box.

One important thing to notice about this representation and this intersection code is that it gives the right answer when the ray direction is 0 for a particular component. In this case the ray is parallel to the planes of the slab. The divide by zero gives either $[-\infty,-\infty]$ or $[+\infty,+\infty]$ when the ray is outside the slab and $[-\infty,+\infty]$ when the ray is inside. This saves additional checks on the ray direction.


next up previous
Next: Intersection Rays versus Shadow Up: Optimizations for Bounding Volume Previous: Optimizations for Bounding Volume
Comments: Brian Smits
1999-02-19