The Glide Utilities Library includes three routines that generate fog tables with different characteristics.
void guFogGenerateExp(GrFog_t fogTable[GR_FOG_TABLE_SIZE], float density)
guFogGenerateExp() generates an exponential fog table according to the equation:
e–density·w where w is the eye-space w coordinate associated with the fog table entry. The resulting fog table is copied into fogTable. The fog table is normalized (scaled) such that the last entry is maximum fog (255).
void guFogGenerateExp2(GrFog_t fogTable[GR_FOG_TABLE_SIZE], float density)
guFogGenerateExp2() generates an exponentially squared fog table according to the equation:
e–(density·w) (density·w) where w is the eye-space w coordinate associated with the fog table entry. The resulting fog table is copied into fogTable. The fog table is normalized (scaled) such that the last entry is maximum fog (255).
void guFogGenerateLinear(GrFog_t fogTable[GR_FOG_TABLE_SIZE], float nearW, float farW)
guFogGenerateLinear() generates a linear (in eye-space) fog table according to the equation
(w – nearW)/( farW – nearW)
where w is the eye-space w coordinate associated with the fog table entry. The resulting fog table is copied into fogTable. The fog table is clamped so that all values are between minimum fog (0) and maximum fog (255). Note that guFogGenerateLinear() fog is linear in eye-space w, not in screen-space.
3Multi-Pass Fog
Special actions must be taken when applying fog to pixels generated with multi-pass techniques. Recall from Figure 1.2 that the fog unit is sandwiched between the color combine unit and the alpha blending unit in the pixel pipeline. This ordering facilitates anti-aliasing but may result in repeated fogging of intermediate values in multi-pass alpha blending applications. Special modes for the fog unit and a special alpha blending function have been provided to identify and handle this situation.
The GR_FOG_ADD2 and GR_FOG_MULT2 modes, passed as arguments to grFogMode(), suppress the first and second terms, respectively, of the fog equation. In GR_FOG_ADD2 mode, the first term of the fog equation is suppressed, resulting in a fog equation shown below:
cout = (1-f )cin and no fog is applied. In GR_FOG_MULT2 mode, the second term is suppressed, making the fog equation effectively:
cout = fcfog leaving only the scaled fog color.
In the grAlphaBlendFunction() routine, presented in Chapter 6, the GR_BLEND_PREFOG_COLOR factor selects the pre-fogged value of the pixel as the destination RGBA blending factor.
The following sections present recipes for correctly applying fog to common multi-pass rendering applications. The generalized fog and blending equations are tailored to the specific situations and are the starting point for the derivations presented in the text. In case you’ve forgotten, the general fog equation is
Fog(cin) = fcfog + (1-f)cin where cin is the pre-fogged color, and the blending equation is
cdst = fsrc · Fog(cin) + fdst · cdst where cdst is the value stored in the frame buffer and fsrc and fdst are the source and destination blending factors.
Table Special Effects.2 summarizes the required fog mode and blending factor settings for the multi-pass fog scenarios presented here. Detailed discussion follows.
Table Special Effects.2 Configuring the fog and alpha blending units for multi-pass fog generation.
The table below describes the proper settings for the fog mode and source and destination alpha blending factors for three different multi-pass fogging applications. If the fog mode is specified as mode, either GR_FOg_WITH_TABLE or GR_FOG_WITH_ITERATED_ALPHA may be used.