Microsoft DirectX 8.1 (C++) |
Depth buffering is a method of removing hidden lines and surfaces. By default, Microsoft® Direct3D® does not use depth buffering.
For a conceptual overview of depth buffers, see Depth Buffers.
C++ applications update the depth-buffering state with the D3DRS_ZENABLE render state, using a member of the D3DZBUFFERTYPE enumeration to specify the new state value.
If your application needs to prevent Direct3D from writing to the depth buffer, it can use the D3DRS_ZWRITEENABLE enumerated value, specifying D3DZB_FALSE as the second parameter for the call to IDirect3DDevice8::SetRenderState.
The following code example shows how the depth-buffer state is set to enable z-buffering.
// This code example assumes that d3dDevice is a // valid pointer to an IDirect3DDevice8 interface. // Enable z-buffering. d3dDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE);
Your application can also use the D3DRS_ZFUNC render state to control the comparison function that Direct3D uses when performing depth buffering.
Z-biasing is a method of displaying one surface in front of another, even if their depth values are the same. You can use this technique for a variety of effects. A common example is rendering shadows on walls. Both the shadow and the wall have the same depth value. However, you want your application to show the shadow on the wall. Giving a z-bias to the shadow makes Direct3D display them properly (see D3DRS_ZBIAS).