Graphics Reference
In-Depth Information
Again, the .glib file and vertex shader are essentially the same as previ-
ous ones, and the fragment shader is shown below.
uniform float uT;
uniform sampler2D uBeforeUnit, uAfterUnit;
in vec2 vST;
out vec4 fFragColor;
void main( )
{
vec3 brgb = texture( uBeforeUnit, vST ).rgb;
vec3 argb = texture( uAfterUnit, vST ).rgb;
vec3 color;
if ( (argb.r + argb.g + argb.b)/3. < uT )
color = argb;
else
color = brgb;
fFragColor = vec4( color, 1.);
}
There is even less computation in this fragment shader; the average of
the After color components is calculated and compared with the parameter
uT , and the After color is used instead of the Before color when the color values
are low (that is, when the colors are dark). As the value of uT moves from 0.
to 1., more and more of the texels in the After image satisfy the condition and
become part of the final display.
Break-Through
What if we had some other way for the After image to replace the Before
image over time? What if, for example, we generated a random texture with
a Noise( ) function and used the values of that random texture to determine
whether the Before or After image is used for each pixel? An example of this
kind of transition is shown in Figure 11.32. This is something like the burn-
through transition, but the image that controls the pixel selection is hidden
and there is no apparent relation between this intermediate image and either
of the two original images.
Because this process uses noise operations, the .glib and vertex shader are
somewhat different from the ones we have seen before in this chapter. The .glib
file simply selects a 3D noise texture and proceeds as in previous examples.
Search WWH ::




Custom Search