#version 400

uniform sampler2D originalColorMap;
uniform sampler2D blurredColorMap;
uniform sampler2D blurAmount;
uniform sampler2D depthMap;

uniform bool setupMode;

uniform int maxBlurRadius;
uniform vec2 planes;
uniform vec2 planesReal;
uniform float focusDistance;


smooth in vec2 VS_TexCoord;

layout(location = 0) out vec4 colorOut;


void main()
{
	float blurAmount = texture(blurAmount, VS_TexCoord).x;

	float lerp = min(blurAmount / maxBlurRadius, 1.0);
	colorOut = mix(texture(originalColorMap, VS_TexCoord), texture(blurredColorMap, VS_TexCoord), lerp);

	if(setupMode)
	{
		float depthReal = planes.y / (planes.x + texture(depthMap, VS_TexCoord).x);
		float planesDiff = planesReal.y - planesReal.x;

		if(depthReal < focusDistance + planesDiff*0.0002 && depthReal > focusDistance - planesDiff*0.0002)
			colorOut = vec4(1.0,0.0,0.0,1.0);
		else
		{
			float lerp = min(blurAmount / maxBlurRadius, 1.0);
			colorOut = vec4(lerp);
		}
	}
}	
