Graphics Reference
In-Depth Information
Fragment anaglyph.frag
Program Anaglyph \
uOffsetS <-.25 0. .25> \
uOffsetT <-.25 0. .25> \
uRed <0. 1. 5.> \
uGreen <0. 1. 5.> \
uBlue <0. 1. 5.> \
uLeftUnit 5 uRightUnit 6
QuadXY .2 5.
Like the other examples in this chapter, most of the work is in the frag-
ment shader:
uniform sampler2D uLeftUnit, uRightUnit;
uniform float uOffsetS, uOffsetT;
uniform float uRed, uGreen, uBlue;
in vec2 vST;
out vec4 fFragColor;
void main( )
{
vec4 left = texture(uLeftUnit, vST );
vec4 right = texture(uRightUnit,vST+vec2(uOffsetS,
uOffsetT));
vec3 color = vec3( left.r, right.gb );
color *= vec3( uRed, uGreen, uBlue );
color = clamp( color, 0., 1. );
fFragColor = vec4( color, 1. );
}
Notice that the fragment shader uses five uniform slider variables that
are set up in the GLIB file. The variables uOffsetS and uOffsetT control the
offset in the right image, to make up for differences in registering the images,
and the three uniform variables uRed , uGreen , and uBlue let you adjust the
color balance to make up for variations in the colors in the glasses. When you
create an anaglyph image, you may want to adjust the image with these vari-
ables to get the best effect.
Figure 11.8 shows another example of creating stereo anaglyphs.
Search WWH ::




Custom Search