Algorithm
The implemented algorithm takes a color
c,
a world-space upper Y value
upper_y, and a
world-space lower Y value
lower_y. It samples
the depth of each pixel in the current scene, and
reconstructs
the full eye-space position of the surface that produced the pixel in question. It
then transforms this position back to world-space using the scene's inverse
view matrix, yielding a Y component
y.
Then, a
fog factor r
is calculated by
fog_factor
[
FogFactorY.hs]:
The value of r is then used to interpolate
between the original color of the pixel and c.
Surfaces with y less than lower_y
are unaffected by fog. Surfaces with y greater than or equal to
upper_y are maximally affected by fog and will actually
have their color values completely replaced by c.
Surfaces with y values that fall between
lower_y
and upper_y will have differing amounts of fog applied
based on the type of fog progression selected.
The filter offers linear,
exponential, and logarithmic
fog progressions. With linear fog, the
r value linearly interpolates between the
original surface color and c. With
exponential fog, the value of
r * r is used to linearly interpolate
between the original surface color and c.
Finally, with logarithmic fog, the value of
sqrt(r) is used to linearly interpolate
between the original surface color and c.
If the upper_y value is greater than
the lower_y value, the fog will appear
to get thicker as the Y position decreases. This can be used to give the effect
of fog on the ground. Unfortunately, the illusion is somewhat ruined if the
viewer goes below the fog plane:
If the lower_y value
is greater than the upper_y value, the
fog will appear to get thicker as the Y position increases. This can be used
to give the effect of smoke accumulating at the top of an enclosed space.
Unfortunately, the illusion of both types of fog is ruined if the viewer
travels above the fog plane:
The simple-minded nature of the effect means that it should be used to
supplement some other simulation of fog. Rendering a simple opaque flat
plane the same color as the fog and then applying the fog effect would
be sufficient.