#version 400

uniform sampler2D occlusionMap;
uniform sampler2D colorMap;

uniform vec4  bgColor;
uniform float texelSize;
uniform bool  showOcclusionMap;

smooth in vec2 VS_TexCoord;

layout(location = 0) out vec4 finalMap;

void main()
{
	float occlusion = 0.0;
	for(int i = -2; i < 2; ++i)
		occlusion += texture(occlusionMap, vec2(VS_TexCoord.s, VS_TexCoord.t + i * texelSize)).r;

	occlusion *= 0.25;

	//disable blur
	//occlusion = texture(occlusionMap, VS_TexCoord).r;

	if(!showOcclusionMap)
	{
		vec4 origColor = texture(colorMap, VS_TexCoord);

		//fix problem with transparency geometry
		if(origColor == bgColor)
			finalMap = origColor;
		else
			finalMap = occlusion * origColor;
	}
	else
		finalMap = vec4(occlusion);
}