#version 400

uniform sampler2DMS  theRenderTex;
uniform int numSamples; 

in vec2 fragTexCoord;
out vec4 result;


// This is the actual code that is executed.
void main( void )
{
	vec4 color = vec4( 0.0 );
	ivec2 iTexCoord = ivec2(textureSize(theRenderTex) * fragTexCoord);
	
	for(int i = 0; i < numSamples; i++)
		color += texelFetch(theRenderTex, iTexCoord, i);

	if ( dot( color.xyz, color.xyz ) < 0.01 )
		discard;

	result = color / float( numSamples );
}