i
i
i
i
i
i
i
i
654 14. Acceleration Algorithms
(or front to back). This is in comparison to the axis-aligned BSP tree,
which normally gives only a rough sorted order. Determine on which side
of the root plane the camera is located. The set of polygons on the far side
of this plane is then beyond the near side’s set. Now with the far side’s set,
take the next level’s dividing plane and determine which side the camera
is on. The subset on the far side is again the subset farthest away from the
camera. By continuing recursively, this process establishes a strict back-
to-front order, and a painter’s algorithm can be used to render the scene.
The painter’s algorithm does not need a Z-buffer; if all objects are drawn
in a back-to-front order, each closer object is drawn in front of whatever is
behind it, and so no z-depth comparisons are required.
For example, consider what is seen by a viewer v in Figure 14.4. Re-
gardless of the viewing direction and frustum, v is to the left of the splitting
plane formed by A. So C, F, and G are behind B, D, and E. Comparing
v to the splitting plane of C, we find G to be on the opposite side of this
plane, so it is displayed first. A test of B’s plane determines that E should
be displayed before D. The back-to-front order is then G, C, F, A, E, B,
D. Note that this order does not guarantee that one object is closer to the
viewer than another; rather it provides a strict occlusion order, a subtle
difference. For example, polygon F is closer to v than polygon E, even
though it is farther back in occlusion order.
Other uses for polygon-aligned BSP trees are intersection testing (see
Chapter 16), and collision detection (see Section 17.2).
14.1.3 Octrees
The octree is similar to the axis-aligned BSP tree. A box is split simulta-
neously along all three axes, and the split point must be the center of the
box. This creates eight new boxes—hence the name octree.Thismakesthe
structure regular, which can make some queries more efficient.
An octree is constructed by enclosing the entire scene in a minimal
axis-aligned box. The rest of the procedure is recursive in nature and ends
when a stopping criterion is fulfilled. As with axis-aligned BSP trees, these
criteria can include reaching a maximum recursion depth, or obtaining a
certain number of primitives in a box [1098, 1099]. If a criterion is met,
the algorithm binds the primitives to the box and terminates the recursion.
Otherwise, it subdivides the box along its main axes using three planes,
thereby forming eight equal-sized boxes. Each new box is tested and pos-
sibly subdivided again into 2 × 2 × 2 smaller boxes. This is illustrated
in two dimensions, where the data structure is called a quadtree,inFig-
ure 14.5. Quadtrees are the two-dimensional equivalent of octrees, with a
third axis being ignored. They can be useful in situations where there is
little advantage to categorizing the data along all three axes.