Graphics Reference
In-Depth Information
with the configurable nature of the stencil test, various possibilities can be specified in the
depth stencil state object. Different actions can be set for each of the following combina-
tions of the stencil and depth test results:
1. Stencil test fails.
2. Stencil test passes, but depth test fails.
3. Stencil test passes, and depth test passes.
The action to be taken can be chosen from one of the members of the D3D11_STENCIL_
OP enumeration, which is shown in Listing 3.29.
enum D3D11_STENCIL_0P {
D3D11_STENCIL_0P_KEEP,
D3D11_STENCIL_0P_ZER0,
D3D11_STENCIL_0P_REPLACE,
D3Dll_STENCIL_OP_INCR_SAT,
D3D11_STENCIL_0P_DECR_SAT,
D3D11_STENCIL_0P_INVERT,
D3D11_STENCIL_0P_INCR,
D3Dll_STENCIL_OP_DECR
}
Listing 3.29. The D3D11_STENCIL_0P enumeration.
These options determine what is done with the stencil buffer value after the tests
complete. There are options for keeping the existing stencil buffer value; clearing it to
zero; replacing it with the stencil reference value; and incrementing, decrementing, or in-
verting it. Once again, these options provide significant freedom in using the stencil buffer
for a variety of different algorithms, since different actions can be taken, depending on
the test results. One final operation is performed before the stencil value is written to the
stencil buffer. The value produced by the stencil operation is bitwise AND'ed with the
StencilWriteMask before being stored.
In this section, we have seen the configuration of a complete stencil test. However,
there are some additional configurations to discuss. All of the settings shown above can be
individually configured for front faces and back faces with the FrontFace and BackFace
members of the depth stencil state object. These members are actually structures that encap-
sulate one set of stencil test configurations (both the comparison function and the operations
to perform in each test result case). This lets special tests to be implemented that perform dif-
ferent options for front and back faces. The most common example of using different settings
Search WWH ::




Custom Search