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.
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)
There are three different fog modes:
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
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
Defined by 4 points.
Curve passes through middle 2 points.
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
Linear interpolation & cubic curves generally connect only two points.
Often, we have many points that we want to connect with a single path
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
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 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.