#version 400
#extension GL_EXT_gpu_shader4 : enable

in vec2 fragCoord;

uniform usampler2D voxels0, voxels1, voxels2, voxels3;
uniform int  useMRT0, useMRT1, useMRT2, useMRT3;
uniform float intensity;

layout(location = 0) out vec4 countColor;

void main(void)
{
	uvec4 bitSum = uvec4( 0u );
	
	if ( useMRT0 > 0 )
		bitSum += bitCount( texture( voxels0, fragCoord ) );
		
	if ( useMRT1 > 0 )
		bitSum += bitCount( texture( voxels1, fragCoord ) );
	
	if ( useMRT2 > 0 )
		bitSum += bitCount( texture( voxels2, fragCoord ) );
	
	if ( useMRT3 > 0 )
		bitSum += bitCount( texture( voxels3, fragCoord ) );

	float heat = float( bitSum.x + bitSum.y + bitSum.z + bitSum.w ) / 512.0;

	countColor = vec4( intensity*heat );
}
