#version 420

layout (location = IGLU_VERTEX)   in vec3 vertex;
layout (location = IGLU_TEXCOORD) in vec2 texcoord;

uniform float fovy, aspect;
uniform mat4 rotation;

out vec3 viewVec;
out vec2 fragTexCoord;
out float vertID;

void main( void ) 
{
	// Compute the direction to the current fragment (i.e., the view vector)
    float tan_fovy_2 = tan( fovy * 3.14159265358979323846 / 360.0 );
    vec4 vVec  = normalize( vec4( tan_fovy_2*aspect*vertex.x, tan_fovy_2*vertex.y, -1, 0 ) );
    viewVec = vVec.xyz;

	// Position on screen.  vertex is already in [-1..1] NDC space
    gl_Position = vec4( vertex.xy, 0.0f, 1.0f );
    
    // Tex coordinate from C code.  Is already [0..1] for full screeen texture.
    fragTexCoord = texcoord;
    
    // Store the vertex ID.  Useful for randomizing pseudrandom number in frag shader
    vertID       = gl_VertexID;
}