Graphics Reference
In-Depth Information
square of the pixel space. The process of manipulating the image by applying
a function to the pixel address space is called image warping [46] and has many
potential uses.
In most image warping applications, the effect of the function can vary
quite a bit if different parameter values are used in the function. Fortunately,
glman is easy to set up so you can create uniform slider variables for these
parameters. For example, if we consider the image warping with the function
x = x + t * sin(π * x ) applied to both coordinates of the texel, we see in Fig-
ure 11.16 the effect of two different values of the parameter t for this warping
on both the grid above and on the cherry blossom image.
The fragment shader that defines this effect is shown below.
const float PI = 3.14159265;
uniform sampler2D uImageUnit;
uniform float uT;
in vec2 vST;
out vec4 fFragColor;
void main( )
{
vec2 st = vST;
vec2 xy = st;
xy = 2. * xy - 1.; // map to [-1,1] square
xy += uT * sin(PI*xy);
st = (xy + 1.)/2.; // map back to [0,1] square
vec3 irgb = texture( uImageUnit, st ).rgb;
fFragColor = vec4( irgb, 1. );
}
Other kinds of image warping apply more complex kinds of operations
to pixel coordinates. The twirl transformation is one example, and others are
explored in the exercises. For the twirl transformation, we work in pixel coor-
dinates, so we start by transforming texture coordinates to pixel coordinates,
apply the twirl transformation, and then come back to texture coordinates to
select the actual pixel colors.
The twirl transformation rotates the image around a given anchor point
( x c   , y c ) by an angle that varies across the space from a value α at the center,
decreasing linearly with the radial distance as it proceeds toward a limiting
radius r max . The image remains unchanged outside the radius r max . The nota-
tion has ( x ′, y ′) as the original pixel coordinates and ( x , y ) as the coordinates
Search WWH ::




Custom Search