Fog
Notations
Scattering
$ \sigma(x):scattering coefficient(often denoted by $ \sigma_s in many places)
$ \alpha(x): absorption coefficient (often denoted by $ \sigma_a in many places)
$ \kappa(x):=\sigma(x) + \alpha(x): extinction coefficient (often denoted by $ \sigma_t in many places)
$ \tau(x,y):= \int_x^y \kappa(p) \|dp\| = \int_0^{\|x - y\|}\kappa(x_t) dt with $ x_t := x + t \frac{y-x}{\|y -x \|}: optiocal depth
$ T(x,y):= \exp(- \tau(x,y)): transmittance (Beer–Lambert law)
Scene
$ p: surface position (what we want to render)
$ c: camera position
$ d := \| p - c\|: depth
$ v := (c-p)/d: view vector
$ x_t:= p + t v
Then
$ L_i(c, -v) = T(c,p) L_o(p, v) +\int_p^c T(x,c) L_s(x,v)\sigma(x) ||dx\|,
where
$ L_s(x,v) := \int_{S^2} \beta(v, w)L_i(x,w) dw with a phase function $ \beta (may vary with $ x).
constant$ L_s
Note that $ \frac{d \tau(x_t, c)}{dt} = \kappa(x_t) and $ \frac{d T(x_t,c)}{dt} = - T(x_t, c) \kappa(x_t).
The inscattering term is
$ - \int_0^d (T(x_t, c))' \frac{\sigma(x_t)}{\kappa(x_t)} L_s(x) dt = \int_0^d T(x_t, c) \frac{ d}{dt}\left( \frac{\sigma(x_t)}{\kappa(x_t)} L_s(x) \right) dt - [T(x_t,c) \frac{\sigma(x_t)}{\kappa(x_t)} L_s(x_t, v))]_0^d
If $ \frac{\sigma(x_t)}{\kappa(x_t)} L_s(x_t, v)does not depend on $ t, then $ \frac{ d}{dt} \frac{\sigma(x_t)}{\kappa(x_t)} L_s(x_t,v) = 0
so the in-scattering term equals to$ (1 - T(p, c)) L_s(p,v) holds.
Split-sum approximation (not verified)
$ - \int_0^d (T(x_t,c))'\frac{\sigma(x_t)}{\kappa(x_t)} L_s(x,v)dt \approx - \int_0^d (T(x_t,c))' dt \frac{1}{d} \int_0^d \frac{\sigma(x_t)}{\kappa(x_t)} L_s(x_t,v)dt
$ = (1 - T(p,c)) \frac{1}{d} \int_0^d \frac{\sigma(x_t)}{\kappa(x_t)} L_s(x_t,v)dt
Exponential fog
assumption
$ \alpha = 0 so that $ \sigma = \kappa,
$ \sigma does not depend on $ x (homogeneous medium),
then
$ \tau(x,y) = \|x - y\| \sigma and
$ T(x,y) = \exp(- \|x- y\| \sigma) = e^{-d \sigma}.
Further assume
$ \beta is uniform, that is, $ \beta = 1/4\pi and
$ L_i in $ L_{\mathrm{scat}} is constant, say $ c_{\mathrm{fog}}.
or $ L_i is given by some punctual light (e.g., directional ight)
Then
$ L_{\mathrm{scat}}(x,v) = c_{\mathrm{fog}}
and $ L_\mathrm{is}(p,v) = (1 - T(p,c)) c_\mathrm{fog}
$ \leadsto $ L_i(c, -v) = e^{-d \sigma}L_o(p,v) + (1 - e^{-d\sigma})c_{\mathrm{fog}}
In-Scattering for point lights
by Miles Macklin
Assumption:
consider only single scattering
$ \alpha, \sigma, \kappa are constant (homogeneous medium)
$ \beta = 1/4\pi (phase function is uniform)
$ L_i in$ L_{\mathrm{scat}}: given by a point light
at $ s
with intensity$ I
that is$ L_{\mathrm{scat}}(x,v) = \pi I/\|x - s\|^2, so the in-scattering term is
$ \int_0^d T(x_t,c) L_{s}(x_t,v)\sigma(x_t) dt = \int_0^d \frac{\pi I}{\|x_t - s\|^2} \sigma dt.
Note$ T(x_t, c) is omitted because we consider only single scattering.
The computation of the integral is done as follows:
$ \sigma \pi I \int_0^d \frac{1}{t^2 + 2 ((p-s)\cdot v)t + \|p-s\|^2} dt
Putting $ b = (p-s)\cdot v and $ c = \|p-s\|^2, the integral can be computed as:
$ =\sigma \pi I \int_0^d \frac{dt}{t^2 + 2bt + c}
$ = \sigma \pi I \int_0^d \frac{dt}{(t+b)^2 + (c-b^2)}
$ = \sigma \pi I \int_b^{b+d} \frac{du}{u^2+v^2} = \frac{\sigma \pi I}{v}(\tan^{-1} \frac{x-y}{1+xy})
with $ u = t + b, v = \sqrt{c-b^2}, x = \frac{d+b}{v} and $ y = \frac{b}{v}.
Exponential height fog
Wenzel, Real-time Atmospheric Effects in Games
$ f \geq 0 falloff (constant)
$ h_0: base height
$ h(x):= \max(0, x_y - h_0): height function
$ a\in[0,1] : density
$ \sigma(x) := a \exp(- f h(x)): exponential height fog
Assume $ \alpha =0for simplicty (maybe not essential).
$ \tau(c,p) = \int_p^c \sigma(x)||dx|| = \int_0^d a \exp(-f h(x_t)) dt = a \int_0^d e^{- f \max(0, (p + tv)_y - h_0)} dt
Assume $ (x_t)_y \geq h_0 holds for all $ t. Then
$ \tau(c,p) = a \int_0^d e^{-f (p_y + t v_y - h_0)} dt = \frac{a}{-fv_y}(e^{-f(p_y + d v_y - h_0)} - e^{-f (p_y - h_0)}) = \frac{a}{f v_y} e^{fh_0} (e^{- fp_y} - e^{-f c_y })
$ = \frac{a}{f (c - p)_y} d e^{-f(p_y - h_0)}(1 - e^{-f(c-p)_y})
When p is at infintiy (e.g., skybox), it is useful to use the expression $ x_t = c - tv without $ p.