Fog

Fog is a useful effect for realistic large-scale scenes.

It provides an additional depth cue for distant objects - aerial perspective.

It can also be used to hide the edges of a 3D world.






glFog

OpenGL fog mixes the color of a fragment with the color of the fog. The degree of mixing is a function of the distance from the camera to the fragment.

finalColor = (1-f) * polyColor + f * fogColor

Example:

    glEnable(GL_FOG)
    glFogi(GL_FOG_MODE, GL_LINEAR)
    glFogfv(GL_FOG_COLOR, [1, 1, 1, 1])
    glFogf(GL_FOG_START, 5.0)
    glFogf(GL_FOG_END, 40.0)





Fog Mode

There are three different fog modes:

glFogi(GL_FOG_MODE, GL_LINEAR)
Fog ranges from none at near distance (GL_FOG_NEAR) to full at far distance (GL_FOG_FAR)

glFogi(GL_FOG_MODE, GL_EXP)
glFogi(GL_FOG_MODE, GL_EXP2)
Fog density is an exponential function of the distance. The density is varied by the GL_FOG_DENSITY parameter.





Interpolation


Linear: P = C1t + C0
C1 = P1 - P0       C0 = P0

Cubic: P = C3t3 + C2t2 + C1t + C0





Bezier Spline

Defined by 4 points.
Connects the first and last points; middle points control direction.

P(t) = (1 - t)3p0 + 3t(1 - t)2p1 + 3t2(1 - t)p2 + t3p3






Hermite Spline

Defined by 2 points, and tangents at those points

P(t) = (2t3 - 3t2 + 1)p0 + (t3 - 2t2 + t)m0 + (-2t3 + 3t2)p1 + (t3 - t2)m1






Catmull-Rom Spline

Defined by 4 points.
Curve passes through middle 2 points.


P = C3t3 + C2t2 + C1t + C0

C3 = -0.5 * P0 + 1.5 * P1 - 1.5 * P2 + 0.5 * P3
C2 = P0 - 2.5 * P1 + 2.0 * P2 - 0.5 * P3
C1 = -0.5 * P0 + 0.5 * P2
C0 = P1




Longer Paths

Linear interpolation & cubic curves generally connect only two points.

Often, we have many points that we want to connect with a single path






Piecewise Interpolation

A longer curve can be broken up into multiple pieces

Each piece is a line or curve connecting 2 points

For a Catmull-Rom curve, use the 4 surrounding points as control points






Piecewise Interpolation

The curve parameter (t) is a measure of how far along we are in the particular segment currently being interpolated

i.e. t=0 at the beginning point (P1)
     t=1 at the end point (P2)






Keyframe Animation

Keyframe animation uses a small sequence of key frames to define motion - all in-between frames are filled in based on the keys.

In computer animation, in-betweening is done by interpolation (linear or cubic)

Positions, rotation angles, scales, and other parameters can be interpolated.



Creative Commons License
This document is by Dave Pape, and is released under a Creative Commons License.