A "Fast" Method for Culling of Oriented-Bounding
Boxes (OBBs) Against a Perspective Viewing Frustum
in Large "Walkthrough" Models
Kenny Hoff
5/23/96
Given the following preconditions:
- We are given a camera system defined in the world coordinate system
that includes the following:
- camera coordinate axes (view-up, viewplane normal, "horizon")
- camera origin in world coordinates (location of the camera)
- center-of-projection (COP) defined in camera coordinates (must be able
to accomodate "off-axis" COP for use in stereo displays)
- near and far planes that are parallel to the viewing plane and are
also defined in camera coordinates
- viewplane window extents (left, right, top, bottom) defined on camera
XY plane
- We have a convex polyhedron, called the perspective viewing frustum,
against which to cull the OBBs; this is formed from the pyramid with the
COP at the tip and the far plane at its base by truncating the top with
the near plane. The extents of the top and bottom of this truncated pyramid
are determined from the intersections with the near and far planes of the
projectors formed from the COP through the corners of the viewplane window.
Since this frustum is a convex polyhedra we can simply represent it as
a set of six planes in "point-normal" form.
- We have a list of OBBs defined in world coordinates (OBB relative-transformation
hierarchies must be decomposed so that all are in world coords). The OBBs
are tight-fitting, arbitrarily oriented bounding boxes that are defined
by an origin, a set of OBB-coordinate axes, and extents along these axes.
We can perform a fast overlap test of the OBB and the viewing frustum
by keeping a few simple guidelines in mind:
- If all vertices of the OBB are in the "outside" half-space
of any of the frustum's planes, then the OBB is trivially REJECTED.
- If any vertex of the OBB is determined to be inside the frustum (if
tested to be in the "inside" half-space of each of the frustum's
planes), then it is trivially ACCEPTED.
- If we cannot trivially reject or accept, then all of the vertices are
outside the frustum and only three possibilities remain: a corner
of the frustum protrudes through a face of the OBB, the OBB surrounds
the frustum, or the OBB does not overlap the frustum but happens to cross
the "corner planes".
- We are dealing specifically with the problem of speeding up "walkthrough"
models that are composed of hundreds of thousands of polygons that surround
the viewer at all times (the viewer is immersed into the model, not viewing
it from the outside). Given this, we can expect, on average, that a larger
number of OBBs will be trivially rejected rather than accepted; so, we
should go for this test first. In other words, first we will test each
vertex of the OBB against a single plane, rather than testing each
vertex against every plane (trivial reject vs. trivial accept).
- We should try to avoid any matrix transformations since they are too
expensive.
Now given a viewing-frustum (VF) and a single OBB here is the proposed
implementation:
- Calculate the eight vertices of the OBB using the OBB axes and extents
along these axes.
- Create a "in-out" 6-bit sequence (LRTBNF for left, right,
top, bottom, near, and far respectively) for each vertex that is used to
determine the vertex's location with respect to the six planes of the viewing-frustum
(a set bit means it is "outside" of that respective plane). Initialize
this sequence to zero for each vertex.
- Go for trivial rejection by repeating the following steps for
each plane in the viewing frustum or until rejected. Process the planes
in the following order: near, left, right, bottom, top, far (this
order can be chosen arbitrarily, but we must try to eliminate OBBs as early
as possible; it seems logical to proceed in this order for large models
in which the viewer is totally immersed):
- "encode" the eight vertices (by properly setting the appropriate
bit) as either "inside" or "outside" the current plane
being tested. This simply involves the evaluation of the plane equation
for each vertex (Ax+By+Cz+D : three multiplies and three adds), and we
only need to know the sign of the result.
- if the logical AND of all eight of the 6-bit sequences is not equal
to zero, then it is trivially REJECTED.
- By now, if the OBB was not trivially rejected, the 6-bit sequence should
be properly encoded with respect to all six planes (remembering not to
reset the sequence for each new plane being tested for in the trivial rejection
tests). If ANY of the sequences equals zero, we can trivially ACCEPT (we
must do so upon encountering the FIRST occurance).
- Now we must handle the three special cases:
- Test for frustum protrusion through an OBB face by checking each
edge in the frustum (12 edges) for intersection with a polygonal face of
the OBB. We can determine overlap upon the first occurance of an edge that
intersects a single face of the OBB. So take each frustum edge in turn
and check it against each face in the OBB. If all of the OBB faces
miss the edge move on to the next frustum edge. It is possible to determine
overlap, in best case, in one edge-face intersection test; and in worst
case, 12 x 6 = 72 tests.
- If the frustum protrusion fails, check for containment of the frustum
inside the OBB by just checking if the origin of the frustum (assuming
viewplane lies between near and far planes) is inside the OBB. If the frustum
is inside the OBB, then they most definitely overlap (ACCEPT). This requires
evaluation of the "in-out" test for each plane of the OBB (six
plane equation evaluations).
- If both of these test fail, REJECT the OBB because it does not
overlap the viewing-frustum.
The special cases are computationally expensive, but should only occur
for a small number of OBBs compared to the amount trivally rejected and
accepted. The early, most frequent tests are VERY inexpensive requiring
as little as 24 multiplies, 24 adds, and 7 logical operations (after computation
of vertices) for trivial rejection. One of the most attractive features
of this method is the fact that the frustum and OBB are left in their world
coordinate orientations, thus eliminating the need for expensive transformations
and projections.