Using Z-Bias


Polygons that are coplanar in 3-D space can be made to appear as if they are not coplanar by adding a z-bias to each one. This is a technique commonly used to ensure that shadows in a scene are displayed properly. For instance, a shadow on a wall will likely have the same depth value as the wall does. If the wall is rendered before the shadow, the shadow might not be visible, or depth artifacts might be visible. The order in which the coplanar objects are rendered can be reversed in hopes of reversing the effect, but depth artifacts are still likely.

A C# application can help ensure that coplanar polygons are rendered properly by adding a bias to the z-values that the system uses when it renders the sets of coplanar polygons. To add a z-bias to a set of polygons, set the RenderStateManager.DepthBias property of the Device.RenderState property to a value between 0 and 16, inclusive. A higher z-bias value increases the likelihood that the rendered polygons will be visible when displayed with other coplanar polygons.

The following C# code example demonstrates how to set the z-bias value.

          [C#]
          
using System; using Microsoft.DirectX.Direct3D; // Declare a rendering device. Device device = null; // Initialize the device. . . . // Get the device's render state object. RenderStates rs = device.RenderState; // Set the depth bias value. rs.DepthBias = 7.0f; // Render the scene. . . . // Change the depth bias value // (note the different syntax; both forms are acceptable) device.RenderState.DepthBias = 3.0f;

Send comments about this topic to Microsoft. © Microsoft Corporation. All rights reserved.

Feedback? Please provide us with your comments on this topic.
For more help, visit the DirectX Developer Center