Simulating fog
A simple fog effect can be achieved by mixing the color of each fragment with a constant fog color. The amount of influence of the fog color is determined by the distance from the camera. We could use either a linear relationship between the distance and the amount of fog color, or we could use a non-linear relationship such as an exponential one.
The following image shows four teapots rendered with a fog effect produced by mixing the fog color in a linear relationship with distance.
To define this linear relationship we can use the following equation:
In the preceding equation, dmin is the distance from the eye where the fog is minimal (no fog contribution), and dmax is the distance where the fog color obscures all other colors in the scene. The variable z represents the distance from the eye. The value f is the fog factor . A fog factor of zero represents 100% fog, and a factor of one represents no fog. Since fog typically looks thickest at large distances, the fog factor is...