////////////////////////////////////////////////////////////////////////
//
//   Harvard Computer Science
//	    CS 175: Introduction to Computer Graphics
//   Professor: Hanspeter Pfister
//         TFs: Moritz Baecher, Yuanchen Zhu, Kalyan Sunkavalli, Kevin Dale
//
//   File: raindrop.frag
//   Name: Felix Gonda (felix.e.gonda@gmail.com)
//   Date: Dec 3rd, 2010
//   Desc: fragment shader for rain drop
//   
//////////////////////////////////////////////////////////////////////////
#define MAX_LIGHTS 5

uniform sampler2D colorMap;
uniform int Type;

varying vec2 Texcoord;
varying vec4 vColor;
varying vec3 lightDir[MAX_LIGHTS];

void main( void )
{
    vec4 globalAmbientLight = vec4(0.0,0.0,0.0,1.0);
    vec4 baseColor = globalAmbientLight;
    
    baseColor = texture2D( colorMap, Texcoord );
    
	vec4 ambient = globalAmbientLight;
	vec4 diffuse = globalAmbientLight;
	vec4 specular = globalAmbientLight;
	vec4 color = globalAmbientLight;
	    
    
    int i;
    float dist;

    // Sample all lights in the environment
    for(i=0; i<MAX_LIGHTS; i++)
    {
		// attenuate base on distance from light source
        dist = length(lightDir[i]);
		float atten = 1.0/dist;
		
		ambient += gl_FrontLightProduct[i].ambient*atten;
		diffuse += gl_FrontLightProduct[i].diffuse*atten;
		specular += gl_FrontLightProduct[i].specular*atten;
		
	}
	
	color = ambient + diffuse + specular;
	color.x = color.x > 1.0 ? 1.0 : color.x;
	color.y = color.y > 1.0 ? 1.0 : color.y;
	color.z = color.z > 1.0 ? 1.0 : color.z;
	
    
    gl_FragColor = baseColor * color;// * vec4(1,1,1,1);//texture2D( colorMap, Texcoord );
}