#version 400 

layout(location = IGLU_VERTEX)   in vec3 vertex;   // Sends vertex data from models here
layout(location = IGLU_NORMAL)   in vec3 normal;   // Sends normal data (if any) from models here
layout(location = IGLU_TEXCOORD) in vec2 texCoord; // Sends texture coordinate data (if any) from models here
layout(location = IGLU_MATL_ID)  in float matlID;  // Sends ID for current material from model (if any)

uniform mat4 project;             // The projection/perspective matrix
uniform mat4 model;               // The model matrix
uniform mat4 view;                // The view matrix

out vec4 esNormal;
out vec4 esPosition;
out vec4 matlColor;

// This is the actual code that is executed.
void main( void )
{  
	if (matlID == 2.0f)      // Green surface
		matlColor = vec4(0.15, 0.48, 0.09, 1);
	else if (matlID == 1.0f) // Red surface
		matlColor = vec4(0.63, 0.06, 0.04, 1);
	else                     // White surface
		matlColor = vec4(0.76, 0.75, 0.5, 1);

	vec4 eyePos = view * model * vec4( vertex, 1.0f );
	esPosition = eyePos;
	gl_Position = project * ( eyePos ); 
	esNormal = inverse( transpose( view * model ) ) * vec4( normal, 0.0 );
}