#version 400

uniform mat4 project;
uniform mat4 modelview;

layout (location = IGLU_VERTEX) in vec4 vertex;
layout (location = IGLU_NORMAL) in vec3 normal;

out float NdotE;
out float distToEye;
out vec3  esNorm;

void main( void )
{ 
	vec4 eyeSpaceNorm  = inverse( transpose( modelview ) ) * vec4( normal, 0.0f );
	vec4 eyeSpacePos   = modelview * vertex;

	gl_Position = project * (modelview * vertex);
	esNorm      = eyeSpaceNorm.xyz;
	NdotE       = dot( normalize(eyeSpaceNorm.xyz), -normalize(eyeSpacePos.xyz) );
	distToEye   = length( eyeSpacePos.xyz );
}

