i
i
i
i
i
i
i
i
5.7. Transparency, Alpha, and Compositing 137
the transparent surfaces to a separate buffer, i.e., without any opaque ob-
jects rendered first. This blending mode is called the under operator and is
used in volume rendering techniques [585]. For the special case where only
two transparent surfaces overlap and the alpha of both is 0.5, the blend
order does not matter, and so no sorting is needed [918].
Sorting individual objects by, say, their centroids does not guarantee
the correct sort order. Interpenetrating polygons also cause difficulties.
Drawing polygon meshes can cause sorting problems, as the GPU renders
the polygons in the order given, without sorting.
If sorting is not possible or is only partially done, it is often best to use
Z-buffer testing, but no z-depth replacement, for rendering the transparent
objects. In this way, all transparent objects will at least appear. Other
techniques can also help avoid artifacts, such as turning off culling, or
rendering transparent polygons twice, first rendering backfaces and then
frontfaces [918].
Other methods of correctly rendering transparency without the appli-
cation itself needing to sort are possible. An advantage to the A-buffer
multisampling method described on page 128 is that the fragments can be
combined in sorted order by hardware to obtain high quality transparency.
Normally, an alpha value for a fragment represents either transparency,
the coverage of a pixel cell, or both. A multisample fragment’s alpha rep-
resents purely the transparency of the sample, since it stores a separate
coverage mask.
Transparency can be computed using two or more depth buffers and
multiple passes [253, 643, 815]. First, a rendering pass is made so that the
opaque surfaces’ z-depths are in the first Z-buffer. Now the transparent
objects are rendered. On the second rendering pass, the depth test is
modified to accept the surface that is both closer than the depth of the
first buffer’s stored z-depth, and the farthest among such surfaces. Doing
so renders the backmost transparent object into the frame buffer and the z-
depths into a second Z-buffer. This Z-buffer is then used to derive the next-
closest transparent surface in the next pass, and so on. See Figure 5.37.
The pixel shader can be used to compare z-depths in this fashion and so
perform depth peeling, where each visible layer is found in turn [324, 815].
One initial problem with this approach was knowing how many passes were
sufficient to capture all the transparent layers. This problem is solved using
the pixel draw counter, which tells how many pixels were written during
rendering; when no pixels are rendered by a pass, rendering is done. Al-
ternatively, peeling could be cut short when the number of pixels rendered
by a pass falls below some minimum.
While depth peeling is effective, it can be slow, as each layer peeled
is a separate rendering pass of all transparent objects. Mark and Proud-
foot [817] discuss a hardware architecture extension they call the “F-buffer”