Graphics Reference
In-Depth Information
Figure 11.27. The results of the multiply without the color balancing (left) and with the
color balancing (right) operations on our sample images.
Darken and Lighten
The darken and lighten operations are very similar, so we discuss them together.
The darken operation on two images uses one image to darken the other. You
read a pixel from each image, and you take the smaller of the values of each
color component for each pixel. Some sample fragment shader code for this is
shown below.
The lighten operation is the converse of the darken operation above; you
read a pixel from each image, and you take the larger of the values for each
color component for each pixel. The fragment shader code for this is left as an
exercise. The result for both operations is shown in Figure 11.28.
uniform sampler2D uBeforeUnit, uAfterUnit;
in vec2 vST;
out vec4 fFragColor;
void main( )
{
vec3 brgb = texture( uBeforeUnit, vST ).rgb;
vec3 argb = texture( uAfterUnit, vST ).rgb;
vec3 target = min( argb, brgb ); // alternately max(...)
fFragColor = vec4( target, 1.);
}
Search WWH ::




Custom Search