Graphics Reference
In-Depth Information
out vec4 fFragColor;
void main( )
{
vec3 brgb = texture( uBeforeUnit, vST ).rgb;
vec3 argb = texture( uAfterUnit,vST).rgb;
vec3 target = 0.5 - 0.25*cos(PI*brgb) - 0.25*cos(PI*argb);
fFragColor = vec4( target, 1. );
}
Multiply
The multiply operation does exactly as the name suggests. You read a pixel
from each image and multiply the color components together to get the final
color of the pixel. In this way, one image is being used as a subtractive filter
for the other.
Since all the color components are less than or equal to one, the final
image will likely be darker than either original. In order to account for that,
you can balance the colors by computing the luminance of the original colors,
argb , brgb , and target , and adjusting the final output color of each pixel so its
luminance is the average of the two input pixels' colors. Some sample frag-
ment shader code for this is shown below. The result, both without and with
the color balancing, is shown in Figure 11.27.
const vec3 W = vec3(0.2125, 0.7154, 0.0721)
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 = argb * brgb;
float alum = dot( argb, W );
float blum = dot( brgb, W );
float tlum = dot( target, W );
target = (alum + blum)/(2.*tlum);
fFragColor = vec4( target, 1.);
}
Search WWH ::




Custom Search