varying vec3 normal, eyeVec;

varying vec3 lightDir;
varying float att;

varying vec3 lightDir2;
varying float att2;

uniform sampler2D colourTexture;
uniform sampler2D normalTexture;

void main (void)
{
	vec4 final_color = (gl_FrontLightModelProduct.sceneColor * gl_FrontMaterial.ambient);

	final_color += (gl_LightSource[0].ambient * gl_FrontMaterial.ambient) * att;
	final_color += (gl_LightSource[1].ambient * gl_FrontMaterial.ambient) * att2;

	// Normal map			
	vec3 N = normalize(normal);
	vec3 L = normalize(lightDir);
	
	float lambertTerm = dot(N,L);	
	if(lambertTerm > 0.0)
	{
		final_color += gl_LightSource[0].diffuse * gl_FrontMaterial.diffuse * lambertTerm * att;	
		
		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[0].specular * gl_FrontMaterial.specular * specular * att;	
	}

	L = normalize(lightDir2);
	
	lambertTerm = dot(N,L);	
	if(lambertTerm > 0.0)
	{
		final_color += gl_LightSource[1].diffuse * gl_FrontMaterial.diffuse * lambertTerm * att2;	
		
		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[1].specular * gl_FrontMaterial.specular * specular * att2;	
	}

	
	vec4 fog_color = gl_Fog.color;
	float fog = (gl_Fog.end - gl_FogFragCoord) * gl_Fog.scale;

	// Vertex colour
	if (fog <= 0.0)
	{
		gl_FragColor = gl_Fog.color;
	}
	else if (fog >= 1.0)
	{
		gl_FragColor = final_color * gl_Color;
	}
	else
	{
		gl_FragColor = mix(gl_Fog.color,final_color * gl_Color, fog);
	}
}