#version 330

in vec3 vNormal;
in vec3 vEye;

out vec4 OutColor;

uniform vec3 uLightPos;
uniform vec4 uDiffuse;

void main()
{
	// All this normalization is extremely wasteful... Fix this.
	vec3 n = normalize( vNormal );
	vec3 v = normalize( -vEye );
	vec3 l = normalize( uLightPos - vEye );
	vec3 h = normalize( v + l );
	
	float specularCoefficient = 60.0;

	vec3 cAmb = vec3( 0.0 );
	vec3 cDiff = uDiffuse.rgb;
	vec3 cSpec = vec3( 1.0, 1.0, 1.0 );
	float diff = max( 0.0, dot( n, l ) );
	float spec = max( pow( ( dot( n, h ) ), specularCoefficient ), 0.0 );
	
	OutColor = vec4( cAmb + cDiff*diff + cSpec*spec, uDiffuse.a );
}