Conscience is the inner voice that warns us that somebody is looking - H. L. Mencken Concept 3.2 : Fog Equations =========================== Idea: ===== Fog blends a fog color with an incoming fragment's color using a fog blending factor. This factor, 'f' is computed with one of three equations and then clamped to the range [0,1] Equations : =========== 1) f = [e ^ -(density.z)] (GL_EXP) 2) f = [e ^ ( -(density - z) ^ 2)] (GL_EXP2) 3) f = [(end - z) / (end - start)] (GL_LINEAR) In these three equations, z is the eye coordinate distance between the viewpoint and the fragment center. The values for density, start and end are all specified with glFog*(). The f factor is used differently depending on whether one is in RGBA mode or in color-index mode. Note how density affects only the exponential equations and the start and end points specified affect only the linear equation. The glFog*() function ===================== void glFog{if}(GLenum pname, TYPE param); Sets the parameters and function for calcuation of fog using one of the above equations. If pname is GL_FOG_MODE, then param is either GL_EXP GL_EXP2 or GL_LINEAR. If pname is GL_FOG_DENSITY, GL_FOG_START or GL_FOG_END, then pname is a value for density start or end in the equations respectively. In RGBA mode, pname can be GL_FOG_COLOR in which case params points to four values that specify the fog's RGBA color values. Once we know the fog factor f from one of the equations above, we plug it into another formula to get the final fogged color. In RGBA mode the final fogged color is given as shown below : C = fCi + (1 - f) Cf where Ci = incoming fragment's RGBA values and Cf = fog colorvalues assigned with GL_FOG_COLOR.