Game Development Reference
the fragment shader to use data, computed in the vertex shader. Each varying variable is
interpolated for each fragment from the nearby vertices.
The shader in the preceding example also uses the Model*View*Projection matrix to cal-
culate the position of the vertex in screen space. The fragment shader is where the magic
There are a lot of uniforms in the ripple fragment shader to enable us to use it in different
configurations from outside. We need the uTexture sampler to get the colors from the
sprite's texture. uPositionFreq determines how steep the rippling effect is for neigh-
boring pixels. uStrength controls the magnitude of the effect on the y-axis and
uSpeed controls the speed of the ripple. Finally, uTime represents the elapsed time. All
we do to produce the ripple effect is to calculate a coef function, which depends on the
current fragment position and all of our uniforms. We use that offset to calculate the final
texture coordinate for the current fragment. This texture coordinate is used to find out the
color of the texel of uTextue at the current location.
This is what the code which uses that shader looks like: