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

//Fragment shader to render translucent objects

#version 150

#define HAS_SPECULAR			1

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

uniform int				uFlag; //flag indicating various states of the object
uniform sampler2D		uDiffuse; //diffuse map in tex unit 0
uniform sampler2D		uSpecular; //specular map in tex unit 1
uniform sampler2D		uLightBuffer; //texture storing light properties in tex unit 2
uniform vec4			uGlobalAmbient; //global ambient light
uniform float			uAlpha; //alpha value of this object
uniform vec3			uTint; //tint of the model

// ---------------------------------------------------------------------------
// from vs

in vec2					vTexCoord;

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

out vec4				out_Color;

void main()
{
	vec4 light = texelFetch( uLightBuffer, ivec2(gl_FragCoord.xy), 0 );

	vec4 tex = texture( uDiffuse, vTexCoord );

	//-------------------------------------------------------------------
	// calculate final color

	//Add global ambient and diffuse components
	vec4 color = uGlobalAmbient * tex + tex * vec4( light.xyz, 1.0 ) * vec4( uTint, 1.0 );

	//add specular
	if ( (uFlag & HAS_SPECULAR) > 0 )
		color += light.w * texture( uSpecular, vTexCoord ) * tex;

	//add alpha
	color.a *= uAlpha;

	out_Color = color;	
}




