Game Development Reference
In-Depth Information
Suppose that we want to draw the teapot with a level of transparency
so that we could see the background crate through the teapot (see Fig-
ure 7.2).
Figure 7.2: A transpar-
ent teapot
How would we accomplish this? As we are rasterizing the teapot's tri-
angles on top of the crate, we need to combine the pixel colors being
computed for the teapot with the pixel colors of the crate in such a way
that the crate shows through the teapot. The idea of combining the
pixel values that are currently being computed (source pixel) with the
pixel values previously written (destination pixel) is called blending .
Note that the effect of blending is not limited to ordinary glass-like
transparency. We have a variety of options that specify how the colors
are combined, as seen in section 7.2.
It is important to realize that the triangles currently being
rasterized are blended with the pixels that were previously written to
the back buffer. In the example figures, the crate image is drawn first so
that the crate's pixels are on the back buffer. We then draw the teapot
so that the teapot's pixels are blended with the crate's pixels. Thus, the
following rule should be followed when using blending:
Rule: Draw objects that do not use blending first. Then sort the
objects that use blending by their distance from the camera; this is
most efficiently done if the objects are in view space so that you can
sort simply by the z-component. Finally, draw the objects that use
blending in a back-to-front order.
The following formula is used to blend two pixel values:
OutputPixel = SourcePixel
SourceBlendFactor + DestPixel
DestBlendFactor
Search WWH ::




Custom Search