Graphics Reference
In-Depth Information
uniform float uT; //0. <= uT <= 1.
uniform sampler2D uBeforeUnit, uAfterUnit;
in vec2 vST;
out vec4 fFragColor;
void main( )
{
vec2 st = vST;
vec3 brgb = texture( uBeforeUnit, st ).rgb;
vec3 argb = texture( uAfterUnit, st ).rgb;
vec3 color;
if ( st.x < uT )
{
st = vec2( st.x/uT, st.y );
vec3 thisrgb = texture( AfterUnit, st ).rgb;
color = thisrgb;
}
else
{
st = vec2( (st.x-uT)/(1.-uT), st.y );
vec3 thatrgb = texture( BeforeUnit, st ).rgb;
color = thatrgb;
}
fFragColor = vec4( color, 1.);
}
Here the two halves of the if statement repre-
sent the two halves of the display: the side where the
s -component of the texture coordinate is less than
uT and the side where it is greater than uT . For each
pixel coordinate, the s -component of the appropri-
ate image (i.e., texture) is calculated by a propor-
tional computation, and the resulting texture coor-
dinate is used to select the texel to be displayed.
As uT goes from 0. to 1., the effect in this
example is to create the transition from the Before
image to the After image over that same period.
No static figure can capture the full effect; an exer-
cise invites you to create your own transition and
see it work.
Figure 11.29. The Hong village image
replacing the cherry blossom image.
Search WWH ::




Custom Search