Microsoft DirectX 8.0 (Visual Basic)

Using Pixel Fog

Use the following steps to enable pixel fog in your application.

To enable pixel fog in a Visual Basic application

  1. Enable fog blending by setting the D3DRS_FOGENABLE render state to True.
  2. Set the desired fog color in the D3DRS_FOGCOLOR render state.
  3. Choose the fog formula to use by setting the D3DRS_FOGTABLEMODE render state to the corresponding member of the CONST_D3DFOGMODE enumeration.
  4. Set the fog parameters as desired for the selected fog mode in the associated render states. This includes the start and end distances for linear fog, and fog density for exponential fog mode.

The following example shows what these steps might look like in code.

' For brevity, error values in this example are not checked
' after each call. A real-world application should check
' these values appropriately.
'
' For the purposes of this example, d3dDevice is a valid
' reference to a Direct3DDevice8 object.
Sub SetupPixelFog(Color As Long, Mode As CONST_D3DFOGMODE)
    Dim StartFog As Single, _
        EndFog As Single, _
        Density As Single
    
    ' For linear mode
    StartFog = 0.5: EndFog = 0.8
    
    ' For exponential mode
    Density = 0.66
 
    ' Enable fog blending.
    Call d3dDevice.SetRenderState(D3DRS_FOGENABLE, True)
 
    ' Set the fog color.
    Call d3dDevice.SetRenderState(D3DRS_FOGCOLOR, Color)
    
    ' Set fog parameters.
    If Mode = D3DFOG_LINEAR Then
        Call d3dDevice.SetRenderState(D3DRS_FOGTABLEMODE, Mode)
        Call d3dDevice.SetRenderState(D3DRS_FOGSTART, StartFog)
        Call d3dDevice.SetRenderState(D3DRS_FOGEND, EndFog)
    Else
        Call d3dDevice.SetRenderState(D3DRS_FOGTABLEMODE, Mode)
        Call d3dDevice.SetRenderState(D3DRS_FOGDENSITY, Density)
    End If
End Sub