Graphics Reference
In-Depth Information
vec3 target = vec3(0.,0.,0.);
target += 1.*(im1m1+ip1m1+ip1p1+im1p1); //apply blur filter
target += 2.*(im10+ip10+i0m1+i0p1);
target += 4.*(i00);
target /= 16.;
fFragColor = vec4( target, 1. );
}
Chromakey Images
Chromakey image manipulation is used in “green
screen” or “blue screen” image replacement. This lets
you take any image and replace any regions that have
the same color as the key color or are very near the key
color with a background texture or portions of another
image. The chromakey replacement effect is shown in
Figure 11.6.
For chromakey computation, two textures are
required, an “image texture” and a “before texture.”
The “image texture” is the one that may contain pixels
in the color key that would need to be replaced, and
the “before texture” is the one that would replace any
color-keyed pixels. The process then is relatively simple:
read the image texture, and for each pixel, either keep
this pixel, or if the pixel color is sufficiently near the key
color, replace the pixel with the corresponding pixel in
the before texture. The code fragment below uses pure
green as the color key, simulating a green-screen pro-
cess. The value of uT is a tolerance, or a measure of how
near a color must be to the color key before its pixel will
be replaced. This is typically very small, so that only col-
ors very near green, vec3(0., 1., 0.) , will pass the
limit test and will be replaced by the “before” texture
color.
A fragment shader for this process is shown below,
with uniform slider variables uT and uAlpha from a GLIB
file. The foreground image comes from the BeforeUnit
and the background image is from the AfterUnit . The
uAlpha variable controls the alpha value for the fore-
ground image as seen in the figure.
Figure 11.6. A synthetic image (top)
and the result of green-screen chro-
makey processing to replace the green
color and blend the foreground image
with a background with an alpha value
of 0.7 (botom).
Search WWH ::




Custom Search