Microsoft DirectX 8.1 (Visual Basic)

Depth Buffering State

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.

Microsoft Visual Basic® applications update the depth-buffering state with the D3DRS_ZENABLE render state, using a member of the CONST_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 render state, specifying D3DZB_FALSE as the second parameter for the call to Direct3DDevice8.SetRenderState.

The following Visual Basic code example shows how the depth-buffer state is set to enable z-buffering.

' This code example assumes that d3dDevice contains a valid 
' reference to a Direct3DDevice8 object.
 
' Enable z-buffering.
Call 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).