2.28
Filter: Fog

- 2.28.1. Overview
- 2.28.2. Algorithm
- 2.28.3. Types

2.28.1
Overview
1
The fog effect is a simple effect that is intended to simulate atmospheric fog within a scene.
2.28.1.2 Fog
2.28.2
Algorithm
1
The algorithm is trivial:
2.28.2.2 Algorithm

1. For each pixel p at (x, y)
   1. Sample the scene's depth d at (x, y)
   2. Determine the positive eye-space Z value z of p
   3. Mix between the global fog color d and p using a mix function fog(z)

3
The mix function fog(z) is selectable. The r2 package provides linear, quadratic, and inverse quadratic fog. The definitions of the available mix functions are as follows:
2.28.2.4 Fog functions

    module FogFactorZ where

    clamp :: Float -> (Float, Float) -> Float
    clamp x (lower, upper) = max (min x upper) lower

    fogLinear :: Float -> (Float, Float) -> Float
    fogLinear z (near, far) =
      let r = (z - near) / (far - near) in
        clamp r (0.0, 1.0)

    fogQuadratic :: Float -> (Float, Float) -> Float
    fogQuadratic z (near, far) =
      let q = fogLinear z (near, far) in q * q

    fogQuadraticInverse :: Float -> (Float, Float) -> Float
    fogQuadraticInverse z (near, far) =
      let q = fogLinear z (near, far) in sqrt(q)

2.28.2.5 Linear Fog
2.28.2.6 Quadratic Fog
2.28.2.7 Inverse Quadratic Fog
2.28.3
Types
1
In the r2 package, the fog effect is provided by the R2FilterFogDepth type.