/*************************************************************
GLSL Demo - 2D texturing plus phong lighting fragment shader
(c) 2005 Antoine Bouthors, EVASION
*************************************************************/

varying vec3 normal;
varying vec3 lightDir;
uniform sampler2D Tex2D;

void main()
{
	vec4 fragment = texture2D( Tex2D, gl_TexCoord[0].xy );
	vec3 Nnormal = normalize( normal );
	vec3 NlightDir = normalize( lightDir );
	vec3 ReflectedRay = reflect( NlightDir, Nnormal );
	
	vec3 lightColor = vec3( clamp( pow( dot( ReflectedRay, vec3( 0., 0., -1. ) ), 10. ), 0., 1. ) );
	lightColor += gl_LightSource[0].diffuse.xyz * clamp( dot( Nnormal, NlightDir ), 0., 1. );
	gl_FragColor.xyz = .5*fragment.xyz + .5*lightColor;
}
