Graphics Reference
In-Depth Information
##OpenGL GLIB
Noise3D 128
Ortho -1. 1. -1. 1.
Texture 6 cherries.bmp
Texture 7 Hong.village.bmp
Vertex transition.vert
Fragment transition.frag
Program Transition uBeforeUnit 6 uAfterUnit 7
QuadXY .2 5.
Figure 11.32. A break-through tran-
sition with the Hong village image
replacing the cherry blossom image
under the control of a noise function.
The vertex shader adds an input variable, the familiar
MCposition , that holds the model coordinates for each ver-
tex in the initial quad and, when it is interpolated across
the quad, will hold the model coordinates for each pixel in
the display.
out vec3 vMCposition;
out vec2 vST;
void main( )
{
vMCposition = vec3(aVertex);
vST = aTexCoord0.st;
gl_Position = uModelViewProjectionMatrix * aVertex;
}
Finally, the fragment shader gets the pixel colors for each image as usual,
but then gets a noise value (the variable nv ) for the pixel by querying the 3D
sampler function Noise3 at a position determined by the pixel's model coordi-
nates. Since the original quad was 10 units across, we divide the model coordi-
nates by 10 to get the actual texture coordinate for the pixel. The octaves of the
noise value are then used to compute a numeric value whose fractional value
is used for the comparison that selects the image.
uniform float uT;
uniform sampler3D Noise3;
uniform sampler2D uBeforeUnit, uAfterUnit;
in vec3 vMCposition;
in vec2 vST;
Search WWH ::




Custom Search