Sunday, October 28, 2012

Rendering fog without washing out colors close to the camera

Game devs: when rendering fog, you can avoid putting a haze all over your nice colors by using an equation like this one.  (If you look close at the curve, there is a small dip at the start.  If you take x as the distance from the object to the camera, and the height in y as the amount of fog, the dip at the start means that objects that are very close to the camera won't have too much fog applied and have their colors washed out.)  It works well in practice and gives you a nice range of darks and saturateds up close and ramps up smoothly without looking weird.  (Curve originally from John Hable's Uncharted 2 tone mapping presentation.)