Graphics Reference
In-Depth Information
formats that can be used for such a resource typically contain one portion for storing the
current depth value, and another portion for storing the current stencil value. One example
of such a format is DXGI_F0RMAT_D24_UN0RM_S8_UINT, where 24 bits are dedicated to
holding the depth value, and 8 bits are dedicated to holding the stencil value. There are
some formats that contain only depth values, with no data dedicated as a stencil buffer. In
these cases, the stencil test is disabled and will always pass. We will see how each of these
quantities is used in its respective visibility determination tests.
When enabled, the depth test and stencil test are performed for every fragment sent
to the output merger. If MSAA is enabled, the tests are performed for every subsample
produced by the pipeline. This lets the visibility tests be performed with the same granular-
ity that the rasterizer stage uses, and improves the image quality at geometry intersection
areas.
Stencil test. The first visibility test we will consider is the stencil test. This test allows an
application to perform a masking operation on a render target to control when a particular
fragment is written to the destination render target. The test itself is quite configurable, with
a relatively large number of possible configurations. There are two components to this test.
The first is the actual test itself, and the second is an update mechanism used to update the
stencil buffer. To understand how the test works, we will first define the equation that the
stencil test implements. Equation (3.6) provides the pseudocode for the stencil test.
(StencilRef & StencilMask) CompFunc (StencilBufferValue & StencilMask)
(3.6)
Equation (3.6) evaluates to either true or false, where a true result indicates that the
test has passed, and a false result indicates that it has failed. The individual arguments
of the stencil test are a combination of the configurable states discussed in the "Output
Merger State Configuration" section, and we will review each of them here. Starting on
the left side of the equation, we have the stencil reference value, which is bitwise-ANDed
with the stencil mask. The stencil reference value is an unsigned integer value provided
by the application in the ID3DllDeviceContext::OMSetDepthStencilState() method,
while the stencil masks are set as the StencilReadMask member of the depth stencil state
description.
If we take a moment to consider what this equation represents, we see an argument on
the left side based on a parameter that can be configured with a device context method. On
the right side is an argument based on the current stencil buffer value. Both arguments are
masked to allow selecting a subset of the bits contained within their source variables. These
two arguments are then compared with one of several comparison functions provided by
the API. Thus, all three major portions of this equation are configurable, allowing for a
wide variety of possible tests.
Search WWH ::




Custom Search