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

//Fragment shader to render scene texture

#version 150

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

uniform vec4			uGlobalAmbient; //global ambient color
uniform sampler2D		uDiffuseSpec; //diffuse-spec map 
uniform sampler2D		uLightBuffer; //light buffer 
uniform sampler2D		uGlow; //glow buffer

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


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

const vec3				LUMINANCE = vec3( 0.2126, 0.7152, 0.0722 );

out vec4				out_Color;

void main()
{
	//transform from screenspace to texture coordinates
	ivec2 texCoord = ivec2( gl_FragCoord.xy );

	vec4 light = texelFetch( uLightBuffer, texCoord, 0 );
	vec4 diffuseSpec = texelFetch( uDiffuseSpec, texCoord, 0 );

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

	out_Color = vec4(	uGlobalAmbient.rgb * diffuseSpec.rgb + //global ambient
						diffuseSpec.rgb * light.rgb + //diffuse 
						light.w * diffuseSpec.aaa * diffuseSpec.rgb + //specular contribution
						texelFetch( uGlow, texCoord, 0 ).rgb,
						1.0 );
}
