Game Development Reference
In-Depth Information
Even though we don't necessarily have to understand exactly how the
graphics hardware decides which pixels to render for a given triangle, we
do need to understand how it determines what to do with a single pixel.
Conceptually, five basic steps are performed:
1.
Interpolate.
Any quantities computed at the vertex level, such as
texture coordinates, colors, and normals, are interpolated across the
face. The interpolated values for each quantity must be computed for
the pixel before it can be shaded.
2.
Depth test.
We reject pixels by using the depth buffer (see
Sec-
by a closer pixel. Note that, in some circumstances, the pixel shader
is allowed to modify the depth value, in which case this test must be
deferred until after shading.
3.
Shade.
Pixel shading refers to the process of computing a color for
a pixel. On shader-based hardware, this is where your pixel shader
is executed. In a basic forward renderer pass, where we are actually
rendering objects into the frame buffer (as opposed to writing into a
shadow map, or doing some other lighting pass), the pixel is typically
first lit and then fogged if fogging is being used. The output of a pixel
shader consists of not only an RGB color, but also an alpha value,
which is usually interpreted as the “opacity” of the pixel, used for
blending. The next section shows several examples of pixel shaders.
4.
Alpha test.
This rejects pixels based on the alpha value of the pixel.
All sorts of different alpha tests can be used, but the most common
one is to reject pixels that are “too transparent.” Although such
invisible pixels may not cause any change the frame buffer were we
to write them, we do need to reject them so that they do not cause
us to write into the depth buffer.
5.
Write.
If the pixel passes the depth and alpha tests, then the frame
buffer and depth buffers are updated.
•
The depth buffer is updated simply by replacing the old depth
value with the new one.
•
The frame buffer update is more complicated. If blending is not
used, then the new pixel color replaces the old one. Otherwise,
the new pixel color is blended with the old one, with the relative
contributions of the old and new colors controlled by the alpha
value. Other mathematical operations, such as addition, sub-
traction, and multiplication, are also often available, depending
on the graphics hardware.
Search WWH ::
Custom Search