#version 450
// Attributeless fullscreen triangle. Reconstruct a world-space view ray.
layout(std140, binding = 0) uniform Globals {
    mat4  uInvVP;
    vec3  uZenith;
    vec3  uHorizon;
    vec3  uSunDir;
    vec3  uSunColor;
    float uStarAlpha;
    float uDayLight;
    vec3  uSunsetTint;
    float uSunsetAmt;
    float uCloudAmt;
    float uFancySky;
    float uSkyTime;
    float uCamY;
};

layout(location = 0) 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_VertexIndex];
    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
}
