next up previous contents index
Next: 3.10 Antialiasing Application Up: 3 Rasterization Previous: 3.8.6 Texture Application

3.9 Fog

 

If enabled, fog blends a fog color with a rasterized fragment's post-texturing color using a blending factor f. Fog is enabled and disabled with the Enable  and Disable  commands using the symbolic constant FOG.

This factor f is computed according to one of three equations:

 

 

 

(z is the eye-coordinate distance from the eye, in eye coordinates, to the fragment center). The equation, along with either d or e and s, is specified with

void Fog[if] ( enum pname, T param ) ;
void Fog[if]v ( enum pname, T params ) ;

If pname is FOG_MODE, then param must be, or params must point to an integer that is one of the symbolic constants EXP, EXP2, or LINEAR, in which case equation 3.16, 3.17, or 3.18, respectively, is selected for the fog calculation (if, when 3.18 is selected, e = s, results are undefined). If pname is FOG_DENSITY, FOG_START, or FOG_END, then param is or params points to a value that is d, s, or e, respectively. If d is specified less than zero, the error INVALID_VALUE results.

An implementation may choose to approximate the eye-coordinate distance from the eye to each fragment center by . Further, f need not be computed at each fragment, but may be computed at each vertex and interpolated as other data are.

No matter which equation and approximation is used to compute f, the result is clamped to to obtain the final f.

f is used differently depending on whether the GL is in RGBA or color index mode. In RGBA mode, if represents a rasterized fragment's R, G, or B value, then the corresponding value produced by fog is

(The rasterized fragment's A value is not changed by fog blending.) The R, G, B, and A values of are specified by calling Fog  with pname equal to FOG_COLOR; in this case params points to four values comprising . If these are not floating-point values, then they are converted to floating-point using the conversion given in Table 2.6 for signed integers. Each component of is clamped to when specified. If is a color index, then a single value specifies . Its integer part is masked with , where n is the number of bits in a color index framebuffer.

In color index mode, the formula for fog blending is

where is the rasterized fragment's color index and is a single-precision floating-point value. is rounded to the nearest fixed-point value with the same number of bits to the right of the binary point as . In this case, is set by calling Fog  with pname set to FOG_INDEX and param being or params pointing to the single floating-point value that is . Finally, the integer portion of I is masked (bitwise ANDed) with , where n is the number of bits in a color in the color index buffer (buffers are discussed in chapter 4).

The state required for fog consists of a three valued integer to select the fog equation, three floating-point values d, e, and s, an RGBA fog color and a fog color index, and a single bit to indicate whether or not fog is enabled. In the initial state, fog is disabled, FOG_MODE is EXP, , , and ; and .



next up previous contents index
Next: 3.10 Antialiasing Application Up: 3 Rasterization Previous: 3.8.6 Texture Application



David Blythe
Sat Mar 29 02:23:21 PST 1997