Graphics Reference
In-Depth Information
uniform float uT;
uniform float uAlpha;
uniform sampler2D uBeforeUnit, uAfterUnit;
in vec2 vST;
out vec4 fFragColor;
void main( )
{
vec3 brgb = texture( uBeforeUnit, vST ).rgb;
vec3 argb = texture( uAfterUnit, vST ).rgb;
vec4 color;
float r = brgb.r;
float g = brgb.g;
float b = brgb.b;
color = vec4( brgb, 1. );
float rlimit = uT;
float glimit = 1. - uT;
float blimit = uT;
if( r <= rlimit && g >= glimit && b <= blimit )
color = vec4( argb, 1. );
else
color = vec4( uAlpha*brgb + (1.-uAlpha)*argb, 1. );
fFragColor = color;
}
Stereo Anaglyphs
A very interesting and fun use for image-based fragment shaders is to produce
stereo anaglyphs . These have long been used in comic books and movies, and
are still popular today. These are sometimes called “red-blue stereo,” although
today most glasses are actually red-cyan, with the convention that the red filter
is over the left eye and the cyan filter is on the right.
Before writing the shader, we need to see how the glasses actually work.
Our shader will produce a composite image that incorporates both the left and
right eye views. When the composite image is viewed through the red filter,
we want to see just the left eye image. The right eye image needs to be blocked,
or in image terms, it needs to be blacked out. Similarly, when the compos-
ite image is viewed through the cyan filter, we want to see just the right eye
image, so the left eye needs to be blocked. Since a red filter passes red light and
blocks cyan light, this means that the left eye image needs to be coded in red
Search WWH ::




Custom Search