Partager via


Fog

Adding fog to a 3-D scene can enhance realism, provide ambiance or set a mood, and obscure artifacts that are sometimes caused when distant geometry comes into view. Microsoft Direct3D supports two fog models, pixel fog and vertex fog, each with its own features and programming interface.

Essentially, fog is implemented by blending the color of objects in a scene with a chosen fog color, based on the depth of an object in a scene or its distance from the viewpoint. As objects grow more distant, their original color blends more and more with the chosen fog color, creating the illusion that the object is being increasingly obscured by tiny particles floating in the scene. The following illustration shows a scene rendered without fog, and a similar scene rendered with fog enabled.

Scene rendered without fog (left), and with fog (right)

In this illustration, the scene on the left has a clear horizon, beyond which no scenery is visible, even though it would be visible in the real world. The scene on the right obscures the horizon by using a fog color that is identical to the background color, making polygons appear to fade into the distance. By combining discrete fog effects with creative scene design, it is possible to add mood and soften the color of objects in a scene.

Direct3D provides two ways to add fog to a scene: pixel fog and vertex fog, named for the manner in which the fog effects are applied. For more information, see Pixel Fog and Vertex Fog. In short, pixel fog—also called table fog—is implemented in the device driver, and vertex fog is implemented in the Direct3D lighting engine. An application can implement both types of fog simultaneously if desired.

Note: Regardless of whether pixel or vertex fog is used, an application must provide a compliant projection matrix to ensure that fog effects are properly applied. This restriction applies even to applications that do not use the Direct3D transformation and lighting engine. For more information about how to provide an appropriate matrix, see A W-Friendly Projection Matrix.

The following topics introduce fog and present information about using various fog features in Direct3D applications.

Fog blending is controlled by render states; it is not part of the programmable pixel pipeline.