#include "depth_normal.fsh"

uniform sampler2D texUnit;
uniform sampler2D texBlur;

uniform highp vec2 range;

in vec2 UV_f;

layout(location = 0) out vec4 fragColor;

void main()
{
    vec4 baseColor = texture(texUnit, UV_f);
    float depthColor = _SampleDepth(UV_f);
    vec4 blurColor = texture(texBlur, UV_f);

    float coc = clamp((depthColor - range.x) / range.y, 0.0, 1.0);
    
    vec3 farColor = blurColor.xyz;
    vec3 dstColor = vec3(0.0);
    float dstAlpha = 1.0;

    if (coc > 0.0)
    {
        float blend = sqrt(coc * 2.0 * 3.1415926);
        dstColor = farColor * clamp(blend, 0.0, 1.0);
        dstAlpha = clamp(1.0 - blend, 0.0, 1.0);
    }
    fragColor = vec4(baseColor.rgb * dstAlpha + dstColor, 1.0);
}


