#version 410 core
// Attributeless fullscreen triangle. Reconstruct a world-space view ray.
uniform mat4 uInvVP;
out vec3 vRay;
void main() {
    vec2 pos[3] = vec2[](vec2(-1.0, -1.0), vec2(3.0, -1.0), vec2(-1.0, 3.0));
    vec2 ndc = pos[gl_VertexID];
    vec4 near = uInvVP * vec4(ndc, -1.0, 1.0);
    vec4 far  = uInvVP * vec4(ndc,  1.0, 1.0);
    vRay = (far.xyz / far.w) - (near.xyz / near.w);
    gl_Position = vec4(ndc, 1.0, 1.0); // far plane
}
