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

//which copies out a portion of the luminance texture

#version 150

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

uniform sampler2D		uLightBuffer; //light buffer value
uniform sampler2D		uGBuffer; //normals + depth
uniform float			uFarClipPlane; //camera far clip plane

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

in float				vDepth; //negative linear depth

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

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

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

out vec4				out_Color;

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

void main()
{	
	ivec2 texCoord = ivec2(gl_FragCoord.xy);
	float gBufferDepth = texelFetch( uGBuffer, texCoord, 0 ).a * uFarClipPlane;

	out_Color = vDepth < gBufferDepth + 0.3 ?		//is anything blocking the player?	
				vec4( dot(LUMINANCE, texelFetch( uLightBuffer, ivec2(gl_FragCoord.xy), 0 ).rgb ), 1.0, 0.0, 0.0 ) : //if not, calc luminance value from light value
				vec4( 0.0, 0.0, 0.0, 0.0 );
}





