/**
 * Copyright (c) 2019-2021 mol* contributors, licensed under MIT, See LICENSE file for more info.
 *
 * @author Áron Samuel Kovács <aron.kovacs@mail.muni.cz>
 * @author Alexander Rose <alexander.rose@weirdbyte.de>
 */
export declare const ssaoBlur_frag = "\nprecision highp float;\nprecision highp int;\nprecision highp sampler2D;\n\nuniform sampler2D tSsaoDepth;\nuniform vec2 uTexSize;\nuniform vec4 uBounds;\n\nuniform float uKernel[dOcclusionKernelSize];\n\nuniform float uBlurDirectionX;\nuniform float uBlurDirectionY;\n\nuniform float uMaxPossibleViewZDiff;\n\nuniform float uNear;\nuniform float uFar;\n\n#include common\n\nfloat getViewZ(const in float depth) {\n    #if dOrthographic == 1\n        return orthographicDepthToViewZ(depth, uNear, uFar);\n    #else\n        return perspectiveDepthToViewZ(depth, uNear, uFar);\n    #endif\n}\n\nbool isBackground(const in float depth) {\n    return depth == 1.0;\n}\n\nbool outsideBounds(const in vec2 p) {\n    return p.x < uBounds.x || p.y < uBounds.y || p.x > uBounds.z || p.y > uBounds.w;\n}\n\nvoid main(void) {\n    vec2 coords = gl_FragCoord.xy / uTexSize;\n\n    vec2 packedDepth = texture2D(tSsaoDepth, coords).zw;\n\n    if (outsideBounds(coords)) {\n        gl_FragColor = vec4(packUnitIntervalToRG(1.0), packedDepth);\n        return;\n    }\n\n    float selfDepth = unpackRGToUnitInterval(packedDepth);\n    // if background and if second pass\n    if (isBackground(selfDepth) && uBlurDirectionY != 0.0) {\n        gl_FragColor = vec4(packUnitIntervalToRG(1.0), packedDepth);\n        return;\n    }\n\n    float selfViewZ = getViewZ(selfDepth);\n\n    vec2 offset = vec2(uBlurDirectionX, uBlurDirectionY) / uTexSize;\n\n    float sum = 0.0;\n    float kernelSum = 0.0;\n    // only if kernelSize is odd\n    for (int i = -dOcclusionKernelSize / 2; i <= dOcclusionKernelSize / 2; i++) {\n        vec2 sampleCoords = coords + float(i) * offset;\n        if (outsideBounds(sampleCoords)) {\n            continue;\n        }\n\n        vec4 sampleSsaoDepth = texture2D(tSsaoDepth, sampleCoords);\n\n        float sampleDepth = unpackRGToUnitInterval(sampleSsaoDepth.zw);\n        if (isBackground(sampleDepth)) {\n            continue;\n        }\n\n        if (abs(float(i)) > 1.0) { // abs is not defined for int in webgl1\n            float sampleViewZ = getViewZ(sampleDepth);\n            if (abs(selfViewZ - sampleViewZ) > uMaxPossibleViewZDiff) {\n                continue;\n            }\n        }\n\n        float kernel = uKernel[int(abs(float(i)))]; // abs is not defined for int in webgl1\n        float sampleValue = unpackRGToUnitInterval(sampleSsaoDepth.xy);\n\n        sum += kernel * sampleValue;\n        kernelSum += kernel;\n    }\n\n    gl_FragColor = vec4(packUnitIntervalToRG(sum / kernelSum), packedDepth);\n}\n";
