uniform float eyeDistance;
uniform float depthFactor;
uniform sampler2D depthTexture;
uniform sampler2D previousImage;

void main (void)
{
    //real depth of the current point in the pre-rendered scene, [0,1]
    float depthValue = texture2D(depthTexture, gl_TexCoord[0].xy).x;

    //determine the pixel which the eye should identify with the current one
    //(so that the distance between the two pixels on the screen is the same
    //
    float pairedPoint = gl_TexCoord[0].x - eyeDistance - depthFactor*depthValue;

    //copy the color of that pixel to the current pixel
    //(this is the problematic step because it is not sure that this pixel has
    //already a valid color in previousImage. The only solution seems to be
    //to repeat this pixel shader several times)
    gl_FragColor = texture2D(previousImage, vec2(pairedPoint, gl_TexCoord[0].y));
}
