Range-Based Fog

Sometimes, using fog can introduce graphic artifacts that cause objects to be blended with the fog color in non-intuitive ways. For example, imagine a scene in which there are two visible objects, one distant enough to be affected by fog, and the other near enough to be unaffected. If the viewing area rotates in place, the apparent fog effects can change, even if the objects are stationary. The following illustration shows a top-down view of such a situation.

Range-based fog is another, more accurate, way to determine the fog effects. In range-based fog, Direct3D uses the actual distance from the viewpoint to a vertex for its fog calculations, increasing the effects of fog as the distance between the two points increases, rather than the depth of the vertex within in the scene, thereby avoiding rotational artifacts.

If the current device supports range-based fog, it will set the D3DPRASTERCAPS_FOGRANGE capability flag in the dwRasterCaps member of the D3DPRIMCAPS structure when you call the IDirect3DDevice3::GetCaps method. To enable range-based fog, set the D3DRENDERSTATE_RANGEFOGENABLE render state to TRUE.

Range-based fog is computed by Direct3D during transformation and lighting. As discussed in About Vertex Fog, applications that don't use the Direct3D transformation and lighting engine must also perform their own vertex fog calculations. In this case, provide the range-based fog factor in the alpha component of the specular component for each vertex.

Note  No hardware currently exists that supports per-pixel range-based fog. As a result, Direct3D performs range-based fog only when using vertex fog with the Direct3D transformation and lighting engine. If your application performs its own transformation and lighting it must perform its own fog calculations, range-based or otherwise.