/*
* oZone3D.Net SURFACE DEFORMER Benchmark
* Pixel Shader
* Author: Jerome 'JeGX' Guinot
* URL: http://www.ozone3d.net/demos_projects/surface_deformer_benchmark.php
*/

#define NUM_LIGHTS 2
varying vec3 normal, lightDir[NUM_LIGHTS], eyeVec;

void main(void)
{
	vec4 final_color = vec4(0.0, 0.0, 0.0, 0.0);

	vec3 N = normalize(normal);

	final_color += gl_FrontLightModelProduct.sceneColor;
	
	int i = 0;
	for( i=0; i<NUM_LIGHTS; i++ )
	{
		final_color += gl_FrontLightProduct[i].ambient;
		
		vec3 L = normalize(lightDir[i]);
	
		float lambertTerm = dot(N,L);

		if(lambertTerm > 0.0)
		{
			final_color += gl_LightSource[i].diffuse * 
						   gl_FrontMaterial.diffuse * 
						   lambertTerm;	
			
			vec3 E = normalize(eyeVec);
			vec3 R = reflect(-L, N);
			float specular = pow( max(dot(R, E), 0.0), 
							 gl_FrontMaterial.shininess );
			final_color += gl_LightSource[i].specular * 
						   gl_FrontMaterial.specular * 
						   specular;	
		}
	}
	
	gl_FragColor = final_color; 
}
