#ifdef GL_ES
precision highp float;
#endif
uniform sampler2D texUnit0;
uniform mat4 mv_matrix;
uniform mat4 mat4_slot_1;
varying vec3 N;
varying vec3 v; 
varying vec2 v_texcoord;
void main (void)  
{  
		vec3 E = normalize(-v); 
		vec3 L;
		//calculate Ambient Term:  
		vec4 Iamb = vec4(0.2,0.2,0.2,1.0); 			
		vec4 light0, light1, light2;
		for(int i=0; i<3; i++)
		{	
			if(i==0)
				L = normalize((mat4_slot_1[0]).xyz - (v*mat4_slot_1[3].x)); 	
			else if(i==1)
				L = normalize((mat4_slot_1[1]).xyz - (v*mat4_slot_1[3].x)); 
			else
				L = normalize((mat4_slot_1[2]).xyz - (v*mat4_slot_1[3].x)); 
			
			vec3 R = normalize(-reflect(L,N));  
		
			//calculate Diffuse Term:  
			vec4 Idiff = vec4(0.08,0.08,0.08,1.0) * max(dot(N,L), 0.0);
			Idiff = clamp(Idiff, 0.0, 1.0);     
		   
			// calculate Specular Term:
			vec4 Ispec = vec4(0.08,0.08,0.08,1.0)
						* pow(max(dot(R,E),0.0),20.0); 
			Ispec = clamp(Ispec, 0.0, 1.0); 
			// write Total Color: 
			float intensity=clamp(dot(L,N),0.0,1.0);
			
			if(i==0)
				light0 = (vec4(intensity,intensity,intensity,1.0)*mat4_slot_1[0].w)+(Ispec) + Idiff;
			else if(i==1)
				light1 = (vec4(intensity,intensity,intensity,1.0)*mat4_slot_1[1].w)+(Ispec) + Idiff;
			else
	 			light2 = (vec4(intensity,intensity,intensity,1.0)*mat4_slot_1[2].w)+(Ispec) + Idiff;
		}		
		gl_FragColor = (light0+light1+light2+Iamb)*texture2D(texUnit0, v_texcoord);
}