#include "version.sh"

uniform sampler2D texUnit;
uniform sampler2D texBlur;

uniform highp float maxRadius;
uniform highp vec2 perTexelDis;

in vec2 UV_f;

layout(location = 0) out vec4 fragColor;


void main()
{
    vec4 baseColor = texture(texUnit, UV_f);

    vec4 blurColor = texture(texBlur, UV_f);
    
    float coc = (baseColor.a - 0.5) * 2.0 * maxRadius;

    float ffa = smoothstep(perTexelDis.y * 2.0, perTexelDis.y * 4.0, coc);
    
    float alpha = max(max(blurColor.r, blurColor.g), blurColor.b);
    
    float dof = (blurColor.a - 0.5) * 2.0;
    
    vec4 color = mix(vec4(baseColor.rgb, 1.0), vec4(blurColor.rgb, alpha), ffa + dof - ffa * dof);
    
    fragColor = color;
}


