DirectX SDK

Fog States

Fog effects can give a 3-D scene greater realism. Fog effects can be used for more than simulating fog. They can also be used to decrease the clarity of a scene with distance. This mirrors what happens in the real world. As objects get more distant from the viewer, their detail becomes less distinct. For more information about using fog in your application, see Fog.

[C++]

A C++ application controls fog through device rendering states. The D3DRENDERSTATETYPE enumerated type includes states to control whether pixel (table) or vertex fog is used, what color it is, the fog formula the system applies, and the parameters to the formula.

You enable fog by setting the D3DRENDERSTATE_FOGENABLE render state to TRUE. The fog color can be set to any D3DCOLOR value (the alpha component of the fog color is ignored). See D3DRENDERSTATE_FOGCOLOR.

The D3DRENDERSTATE_FOGTABLEMODE and D3DRENDERSTATE_FOGVERTEXMODE render states control the fog formula applied for fog calculations, and indirectly control which type of fog is applied at all. Both render states can be set to one of the members of the D3DFOGMODE enumerated type. Setting either render state to D3DFOG_NONE disables pixel or vertex fog, respectively. If both render states are set to valid modes, the system will apply only pixel fog effects.

The D3DRENDERSTATE_FOGSTART and D3DRENDERSTATE_FOGEND render states control fog formula parameters for the D3DFOG_LINEAR mode. The D3DRENDERSTATE_FOGDENSITY render state controls fog density in the exponential fog modes.

For more information, see Fog Parameters.

[Visual Basic]

In Visual Basic, applications control fog through device rendering states. The CONST_D3DRENDERSTATETYPE enumerated type includes states to control whether pixel (table) or vertex fog is used, what color it is, the fog formula the system applies, and the parameters to that formula.

You enable fog by setting the D3DRENDERSTATE_FOGENABLE render state to True. The fog color can be set to any value of type Long returned by the DirectX7.CreateColorRGB method. See D3DRENDERSTATE_FOGCOLOR.

The D3DRENDERSTATE_FOGTABLEMODE and D3DRENDERSTATE_FOGVERTEXMODE render states control the fog formula that the system applies for fog calculations, and indirectly control which type of fog is applied at all. Both render states can be set to one of the members of the CONST_D3DFOGMODE enumeration. Setting either render state to D3DFOG_NONE disables pixel or vertex fog, respectively. If both render states are set to valid modes, the system will apply only pixel fog effects.

The D3DRENDERSTATE_FOGSTART and D3DRENDERSTATE_FOGEND render states control fog formula parameters for the D3DFOG_LINEAR mode. The D3DRENDERSTATE_FOGDENSITY render state controls fog density in the exponential fog modes.

For more information, see Fog Parameters.