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

//Fragment shader to add glow textures to the final scene texture

#version 150

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

//textures
uniform sampler2D		uScene; //scene texture
uniform sampler2D		uBlur; //blur texture
uniform sampler2D		uGlowMap; //glow map from gbuffer pass
uniform float			uMaxGlow; //total glow amount
uniform float			uDesaturate; //amount of desaturation, where 1.0 means fully greyscale

// ---------------------------------------------------------------------------
// from vertex shader

in vec2					vTexCoord;

// ---------------------------------------------------------------------------
// constants

const vec3				GREYSCALE = vec3( 0.3, 0.59, 0.11 ); //converts RGB to greyscale

// ---------------------------------------------------------------------------
// output

out vec4				out_Color; 


void main()
{
	ivec2 tc = ivec2( gl_FragCoord.xy );
	vec4 sceneColor = texelFetch( uScene, tc, 0 );
	float intensity = dot( GREYSCALE, sceneColor.rgb );
	out_Color = vec4( mix( sceneColor.rgb, vec3( intensity, intensity, intensity ), uDesaturate ), sceneColor.a ) + //interpolate between greyscale and original color
				texture( uBlur, vTexCoord ) * (texelFetch( uGlowMap, tc, 0 ).a * uMaxGlow); //add glow maps on top
}





