O'Reilly logo

OpenGL 4 Shading Language Cookbook Second Edition by David Wolff

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 figure shows four teapots rendered with a fog effect produced by mixing the fog color in a linear relationship with distance.

Simulating fog

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required