#define s_dofSize 1.0    //[0.5 0.75 1.0 1.25 1.5 1.75 2.0 2.25 2.5 3.0 3.5 4.0 4.5 5.0 6.0 7.0 8.0 9.0 10.0 12.0 14.0 16.0 18.0 20.0]
#define s_dofFarFix

#include "/lib/post/bokeh.glsl"

void bokehDof(sampler2D tex, float delta) {
    const float bokehScale = 0.05*s_dofSize;
    vec3 bokehCol = vec3(0.0);
    vec2 bokehCoord = coord;
    vec2 aspectFix  = vec2(1.0, aspectRatio);
    float CoC = (depth)-(centerDepthSmooth);
        CoC *= bokehScale;
        if (CoC < 0.0) CoC *= 1.2;

    #ifdef s_dofFarFix
        CoC *= pow4(1.0-smoothstep(depthLin(centerDepthSmooth), 0.02, 0.5));
    #endif

    if (abs(CoC)>0.0005) {
        #ifdef s_dofHQ
            for (int i = 0; i<75; i++) {
                vec2 bokehShape = pentagonalBokeh75[i];
                vec3 temp = textureLod(tex, coord + bokehShape*CoC*aspectFix, saturate(abs(CoC)*(1.0/bokehScale)*10)*2.0).rgb;
                float luma = getLuma(temp);
                bokehCol += temp*(1.0+smoothstep(luma, 10.0, 50.0)*saturate(abs(CoC)));
            }    
            bokehCol /= 75.0;
        #else
            for (int i = 0; i<50; i++) {
                vec2 bokehShape = pentagonalBokeh50[i];
                vec3 temp = textureLod(tex, coord + bokehShape*CoC*aspectFix, saturate(abs(CoC)*(1.0/bokehScale)*10)*2.0).rgb;
                float luma = getLuma(temp);
                bokehCol += temp*(1.0+smoothstep(luma, 10.0, 50.0)*saturate(abs(CoC)));
            }    
            bokehCol /= 50.0;
        #endif
    returnCol = bokehCol;
    }
}