Graphics Reference
In-Depth Information
with the DepthFunc member of the depth stencil state object. Listing 3.30 provides all of
the available comparison functions.
enum D3D11_C0MPARIS0N_FUNC {
D3D11_C0MPARIS0N_NEVER,
D3D11_COMPARISON_LESS,
D3D11_COMPARISON_EQUAL,
D3D11_C0MPARIS0N_LESS_EQUAL,
D3D11_C0MPARIS0N_GREATER,
D3D11_C0MPARIS0N_N0T_EQUAL,
D3D11_C0MPARIS0N_GREATER_EQUAL,
D3D11_C0MPARIS0N_ALWAYS
}
Listing 3.30. The D3D11_COMPARISON_FUNC enumeration.
These comparisons are performed with the fragment depth value on the left side, and
the depth buffer value on the right side. If the comparison evaluates to true, then the depth
test has passed, and the fragment continues on in the process. If the comparison evalu-
ates to false, then the depth test is concluded, and the fragment is discarded. For example,
the standard comparison is to use D3Dll_COMPARISON_LESS, which provides functionality
similar to the original Z-buffer algorithm. If the fragment depth is less than the depth buffer
value, it will pass the depth buffer test. This indicates that the new fragment is closer to the
viewer, and should be visible.
If the depth test fails, the fragment is discarded. If it passes, it will be passed to the
blending functionality (which will be covered in the next section). The depth buffer may
be updated, depending on a few conditions. If both the depth test and the stencil test have
passed, the fate of the depth value depends on whether depth writes are enabled or not.
This is specified with the DepthWriteMask member of the depth stencil state. If the value
is set to D3D11_DEPTH_WRITE_MASK_ALL, then the depth value can be updated in the depth
buffer; otherwise, the depth value is discarded.
It may seem counterintuitive that the depth buffer could be used for depth testing, but
still have a configuration that allows it to not be written to. In fact, there are many situa-
tions where this is the preferred behavior in modern rendering schemes. It is quite common
for a first rendering pass to be used to fill the depth buffer with values using the standard
Z-buffer technique described above. Then, any subsequent passes would use the depth buf-
fer as it is, since all of the geometry has been rasterized before. In effect, the visibility has
already been determined, so there is no need to have depth writing enabled. A performance
benefit is available when the depth writing is disabled, since the depth buffer would only
need to be read from and never written to.
This "read-only depth buffer" concept can be taken a step further. You may recall that
in Chapter 2 we saw that a depth stencil view could be created with flags to indicate that
Search WWH ::




Custom Search