#include "depth_normal.fsh"

uniform sampler2D texUnit;

uniform highp float focusDist;
uniform highp float maxCoC;
uniform highp vec2 zBuffer;

in vec2 UV_f;

layout(location = 0) out vec4 fragColor;

void main()
{
    float depth = _SampleDepth(UV_f);
    float linearEyeDepth = zBuffer.x + (zBuffer.y - zBuffer.x) * depth;
    // y = 1.0 - a / x
    float coc = (1.0 - focusDist / linearEyeDepth) * maxCoC;
    float nearCoC = clamp(coc, -1.0, 0.0);
    float farCoC = clamp(coc, 0.0, 1.0);
    fragColor = vec4(texture(texUnit, UV_f).rgb, clamp((farCoC + nearCoC + 1.0) * 0.5, 0.0, 1.0));
}


