/**
 * Dubois amber blue anaglyph fragment shader.
 * Copyright © 2012 Kirill Gavrilov <kirill@sview.ru>
 *
 * Distributed under the Boost Software License, Version 1.0.
 * See accompanying file license-boost.txt or copy at
 * http://www.boost.org/LICENSE_1_0.txt
 */

/**
 * http://www.site.uottawa.ca/~edubois/anaglyph/
 */
const mat4 multL = mat4( 1.062, -0.026, -0.038,      0,
                        -0.205,  0.908, -0.173,      0,
                         0.299,  0.068,  0.022,      0,
                             0,      0,      0,      0);
const mat4 multR = mat4(-0.016,  0.006,  0.094,      0,
                        -0.123,  0.062,  0.185,      0,
                        -0.017, -0.017,  0.911,      0,
                             0,      0,      0,      0);

// normalize multipliers
const vec4 multUp =       vec4(2.2, 2.2, 2.2, 1.0);
const vec4 multDw = 1.0 / vec4(2.2, 2.2, 2.2, 1.0);

uniform sampler2D texL, texR;
varying vec2 fTexCoord;

void main(void) {
    vec4 colorL = texture2D(texL, fTexCoord);
    vec4 colorR = texture2D(texR, fTexCoord);

    // normalize
    colorL = pow(colorL, multUp);
    colorR = pow(colorR, multUp);

    // summ
    vec4 color = multR * colorR + multL * colorL;

    // return to normal
    gl_FragColor = pow(color, multDw);
}
