#version 420

layout (location = IGLU_VERTEX)   in vec3 vertex;

uniform float fovy, aspect;
uniform mat4 rotation;

out vec3 fragTexCoord;

void main( void ) 
{
    gl_Position = vec4( vertex.xy, 0.0f, 1.0f );
    
    // Compute an unrotate cube map vector based on the screen-space position;
    float tan_fovy_2 = tan( fovy * 3.14159265358979323846 / 360.0 );
    vec4 cubeMapVec  = normalize( vec4( tan_fovy_2*aspect*vertex.x, tan_fovy_2*vertex.y, -1, 0 ) );
    
    //
    vec4 rotatedCubeMapVec = rotation * cubeMapVec;
    fragTexCoord = rotatedCubeMapVec.xyz;
}