Fog:
The amount of the fog color mixed with the geometry varies with the distance of the geometry from the camera origin.
glEnable(GL_FOG);
glFogfv(GL_FOG_COLOR, fogColor);
// GL_FOG_START and GL_FOG_END only for GL_LINEAR.
glFogf(GL_FOG_START, 5.0f);
glFogf(GL_FOG_END, 30.0f);
glFogi(GL_FOG_MODE, GL_LINEAR); // Which fog equation to use.
glHint(GL_FOG_HINT, GL_NICEST); // 计算方式.
// GL_EXP, GL_EXP2: 需要fog density
glFogF(GL_FOG_DENSITY, 0.5f);
d: fog density.
c: (z) the distance in eye coordinates from origin to fragment being fogged.
c: is the distance of the fragment from the eye plane.
Density: 0.5f
The parameter GL_FOG_START specifies how far away from the eye fogging begins to take effect, and GL_FOG_END is the distance from the eye where the fog color completely over- powers the color of the object(如果再远, 物体完全被fog color给遮盖).
Regardless of the fog mode, f is clamped to the range [0,1] after it is computed. Then, if the GL is in RGBA color mode, the fragment's color Cr is replaced by
Fog Coordinates: For example, you want to elevation to play a role, lending to volumetric fog effects.
void glFogCoordf(GLfloat fFogDistance);
glFogi(GL_FOG_COORD_SRC, GL_FOG_COORD);
return to OpenGL-drived fog effects:
glFogi(GL_FOG_COORD_SRC, GL_FRAGMENT_DEPTH);