# Why is fog in games exponential and has a start distance?

In most tutorials I see on how to achieve fog with shaders the fog is exponential and has a minimum / start distance from the camera. Why? Both seem counterintuitive, especially the minimum distance. Is this an artistic / design choice or is this how our eyes see fog in real life?

• Does not seem counter-intuitive to me. In fog you see pretty clearly just in front of you, then in becomes a bit foggy and not far after that you cannot see much anymore – realUser404 Jan 23 '17 at 14:45

## 1 Answer

This is a legacy from fixed pipeline fog equations, where you typically had one of three options available:

• Linear blended between a start distance and an end distance.
• Exponential based on density.
• Exponential-squared based on density.

For example, the documentation for glFog and for Direct3D 9 fog equations.

A sample tutorial making reference to these three equations (you can cross-check with the documentation and determine that they are the same).

Using shaders you are of course not restricted to these equations, and you can adapt them, modify them, or write your own as you see fit. However, tutorial material does tend to either emulate the older equations or take them as a starting point, because they are a familiar reference (and early versions of GLSL even provided access to glFog parameters via built-in uniforms). You see the very same with lighting, where tutorials typically follow the old fixed pipeline lighting models too (and likewise early versions of GLSL provided access to lighting state too).

(Interesting aside: fixed-pipeline fog did not support specifying a start distance with exponential fog which suggests that some tutorial authors may not have paid as close attention to the documentation as they could have).

• Fog formula use an exponential because exponential is close to the physics of what happen in real life. Tho, with shaders and powerful GPU, we can do better simulations of the atmospheric haze and light scattering in homogeneous media :) – galop1n Feb 1 '17 at 19:25