Changing Depth Buffer Comparison Functions

By default, when depth testing is performed on a rendering surface, the Microsoft Direct3D system updates the render target surface if the corresponding depth value (z or w) for each point is less than the value in the depth buffer. In a C# application, changes to how the system performs comparisons on depth values are made by setting the RenderStateManager.ZBufferFunction property of the Device.RenderState property to a value of the Compare enumerated type. This is illustrated in the following C# code example.

          [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 ZBuffer comparison function.
    rs.ZBufferFunction = Compare.Greater;
    
    // Render the scene.
    .
    .
    .
    
    // Change the comparison function to some other value
    // (note the different syntax; both forms are acceptable)
    device.RenderState.ZBufferFunction = Compare.LessEqual;