Graphics Reference
In-Depth Information
in this manner is the shadow volumes algorithm. 3 8
In addition to the ability to use differ-
ent configurations for front and back faces, the overall test can also be enabled or disabled
with the StencilEnable Boolean parameter. If the stencil test is disabled, it is always
considered to have passed, and the fragment will never be culled because of the stencil test.
Depth test. While the stencil test is being performed, the depth test is also carried out. This
test essentially implements a classical Z-buffer algorithm (Williams, 1978) for performing
a visibility test. The basic concept is to keep a second buffer that is the same size as the in-
tended render target. However, when a primitive is rasterized, it stores the Z-component of
the normalized device coordinates of each fragment, instead of storing the rasterized color
values in the buffer. This produces a buffer that contains the post-divide Z-component of
the fragment position with values in the range of [0.0,1.0]. In the output merger stage, this
Z-buffer is implemented as the depth portion of the depth stencil buffer, and is typically
referred to as a depth buffer, since the Z-component represents a measure of the distance
from the viewer.
When these depth values are stored, any additional primitives that are rasterized to
create fragments can compare their own depth value with the one stored in the depth buffer.
If the depth value stored in the buffer is smaller (closer to the viewer) than the value for the
new fragment, then the new fragment can be discarded, since it is located behind another
object in the scene. If the stored depth buffer value is larger than the new fragment (farther
from the viewer), then the new fragment's color value is passed to the rest of the pipeline,
and the Z-buffer value is updated to represent the new visibility information. In this way,
the Z-buffer provides per-pixel (or per-sample if MSAA is used) visibility determination.
The output merger implements the Z-buffer algorithm with several additional config-
urations for preparing the depth value, as well as actually performing the depth comparison
and writing the result to the Z-buffer. These configurations are primarily contained within
the depth stencil state object, with the exception of the viewport. We will follow a fragment
through the depth test in the same fashion as we have done for the stencil test, to gain a
better understanding of how the process works.
The depth test can be enabled or disabled with the DepthEnable member of the depth
stencil state object. This parameter only determines if the depth test is performed; it does
not control if the depth writing functionality is enabled or disabled. The depth value is
received either directly from the rasterizer stage, or if the pixel shader program modifies
the depth value then it is received from the pixel shader stage. The value is then clamped
to the min and max depth values specified in the viewport structure that was used to
generate the fragment. This clamping is performed in a depth buffer format appropriate
way. After the depth range is clamped, the depth value is read from the depth stencil buf-
fer, and the two values are compared with a selectable depth-comparison function, selected
3 8
This algorithm was first described in the "Rasterizer" section of this chapter.
Search WWH ::




Custom Search