Microsoft DirectX 8.1 (Visual Basic)

Alpha Testing State

Applications written in Microsoft® Visual Basic® use alpha testing to control when pixels are written to the render-target surface. By using the D3DRS_ALPHATESTENABLE render state, your application sets the current Microsoft® Direct3D® device so that it tests each pixel according to an alpha test function. If the test succeeds, the pixel is written to the surface. If it does not, Direct3D ignores the pixel. Select the alpha test function with the D3DRS_ALPHAFUNC render state. Your application can set a reference alpha value for all pixels to compare against by using the D3DRS_ALPHAREF render state.

The most common use for alpha testing is to improve performance when rasterizing objects that are nearly transparent. If the color data being rasterized is more opaque than the color at a given pixel (D3DPCMPCAPS_GREATEREQUAL), then the pixel is written. Otherwise, the rasterizer ignores the pixel altogether, saving the processing required to blend the two colors. The following code example checks if a given comparison function is supported and, if so, it sets the comparison function parameters required to improve performance during rendering.

' This example assumes that Caps is a
' D3DCAPS8 type that was filled with a 
' previous call to Direct3D8.GetDeviceCaps.
If (Caps.AlphaCmpCaps And D3DPCMPCAPS_GREATEREQUAL) Then
    Call dev.SetRenderState(D3DRS_ALPHAREF, &H1)
    Call dev.SetRenderState(D3DRS_ALPHATESTENABLE, 1)
    Call dev.SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL)
End If