Click or drag to resize
DigitalRuneFog

A fog effect blends the normal scene color with a fog color. The blend factor is proportional to the distance from the camera. Fog can be used to simulate haze and aerial perspective. It can also be used to hide objects beyond a certain distance.

This topic contains the following sections:

Defining fog

To add a fog effect to a scene, a FogNode must be added. The FogNode references a Fog instance which defines the fog settings. Fog affects the whole scene.

DigitalRune.Graphics (Fog)

The fog can be configured to create a distance-based fog:

Distance Fog

The fog can also depend on the height:

Height Fog

The y-position of the FogNode defines the "base level" of the fog layer. The y-position of the node can be changed to move the height-based fog up/down.

You can add more than one FogNode to a scene to combine fog effects.

Rendering fog

In forward rendering, the fog is applied when the models are rendered. That means, the models use a single effect which computes the shading and applies the fog color. For example, the XNA stock effects support distance-based fog (but they do not support height-based fog or more than one fog effect per scene).

In deferred rendering, the fog can be applied in a separate rendering step using the FogRenderer. The advantage is that the effects used to render the meshes do not need to handle fog, but this does not work for alpha-blended meshes.

The FogRenderer is a SceneNodeRenderer which handles FogNodes. The FogRenderer works only if a valid depth buffer is set in the render context (property GBuffer0).

The FogRenderer is usually rendered after all opaque objects:

C#
// Render opaque objects...

// Render fog.
fogRenderer.Render(fogNodes, context);

// Render alpha-blended objects...