Graphics Reference
In-Depth Information
Color Negative
The color negative models the way photographic negatives work. A photo-
graphic negative blocks the complement of a color from geting to photo-
graphic paper, so the negative of an image is computed by subtracting the
color of each pixel from white:
vec3(1.0, 1.0, 1.0) - color.rgb
If you use that negative as the base image, you get an image that looks
just like the photographic negative, as shown in Figure 11.20.
The following code for the negative fragment shader sets up a color and
its negative so you can blend between them with the variable uT . At uT = 0
you have the original image, and at uT = 1 you have the negative.
uniform sampler2D uImageUnit;
uniform float uT;
in vec2 vST;
out vec4 fFragColor;
void main( )
{
vec3 irgb = texture( uImageUnit, vST ).rgb;
vec3 neg = vec3(1.,1.,1.) - irgb;
fFragColor = vec4( mix( irgb, neg, uT ), 1. );
}
Figure 11.20. An image (left) and its color negative (right).
Search WWH ::




Custom Search