#version 330

//RAY
#define PI      3.1415926536
#define PI_HALF 1.5707963268

uniform sampler2D PosDataA;
uniform sampler2D PosDataB;
uniform sampler2D RgbData;
uniform float Aspect;

in  vec3 TexCoord;
out vec3 vColor;

void main() {
    vec2 posA = texture2D(PosDataA, TexCoord.xy).xy;
    vec2 posB = texture2D(PosDataB, TexCoord.xy).xy;
    vec2 pos = mix(posA, posB, TexCoord.z);
    vec2 dir = posB - posA;
    float biasCorrection = clamp(length(dir)/max(abs(dir.x), abs(dir.y)), 1.0, 1.414214);
    
    gl_Position = vec4(pos.x/Aspect, pos.y, 0.0, 1.0);
    vColor = texture2D(RgbData, TexCoord.xy).rgb*biasCorrection;
}
