// All content © 2010-2011 DigiPen (USA) Corporation, all rights reserved.

//test shader to calculate luminance value of player

#version 150

// ---------------------------------------------------------------------------
//uniforms

//light variables
uniform vec3		uLightPos; //viewspace light position
uniform float		uRadius; //light radius
uniform vec4		uDiffuse; //diffuse component
uniform vec3		uAtten; //attenuation
uniform float		uIntensity; //light intensity

// ---------------------------------------------------------------------------
// varyings

in vec3				vPixelPos; 			

// ---------------------------------------------------------------------------
// const

const vec4			LUMINANCE = vec4( 0.2126, 0.7152, 0.0722, 0.0 );

// ---------------------------------------------------------------------------

out vec4			out_Color;

void main()
{
	//reconstruct pixel position from depth and get the surface-to-light ray
	vec3 lightVec = uLightPos - vPixelPos; //eyescreenray * normalized view space depth
		
	//---------------------------------------------------------------
	//calculate distance attenuation factor
		
	float l = length( lightVec ); //distance from light to this pixel
	
	//	out_Color = vec4( diffuse_color.rgb, specular_component ) * attenuation * light_intensity

	//diffuse * n.l * atten * intensity
	out_Color = vec4( dot( LUMINANCE, uDiffuse * max( lightVec.y/l, 0.0 ) * 
						clamp( 1.0 - l/uRadius, 0.0, 1.0 ) * uIntensity ), 1.0, 0.0, 0.0 ) ;
}
