/**
 * Copyright (c) 2019-2021 mol* contributors, licensed under MIT, See LICENSE file for more info.
 *
 * @author Alexander Rose <alexander.rose@weirdbyte.de>
 * @author Áron Samuel Kovács <aron.kovacs@mail.muni.cz>
 */
export declare const postprocessing_frag = "\nprecision highp float;\nprecision highp int;\nprecision highp sampler2D;\n\nuniform sampler2D tSsaoDepth;\nuniform sampler2D tColor;\nuniform sampler2D tDepth;\nuniform sampler2D tOutlines;\nuniform vec2 uTexSize;\n\nuniform float uNear;\nuniform float uFar;\nuniform float uFogNear;\nuniform float uFogFar;\nuniform vec3 uFogColor;\nuniform bool uTransparentBackground;\n\nuniform float uOcclusionBias;\nuniform float uOcclusionRadius;\n\nuniform float uMaxPossibleViewZDiff;\n\nconst vec3 occlusionColor = vec3(0.0);\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\nfloat getDepth(const in vec2 coords) {\n    return unpackRGBAToDepth(texture2D(tDepth, coords));\n}\n\nbool isBackground(const in float depth) {\n    return depth == 1.0;\n}\n\nfloat getOutline(const in vec2 coords, out float closestTexel) {\n    float backgroundViewZ = uFar + 3.0 * uMaxPossibleViewZDiff;\n    vec2 invTexSize = 1.0 / uTexSize;\n\n    float selfDepth = getDepth(coords);\n    float selfViewZ = isBackground(selfDepth) ? backgroundViewZ : getViewZ(selfDepth);\n\n    float outline = 1.0;\n    closestTexel = 1.0;\n    for (int y = -dOutlineScale; y <= dOutlineScale; y++) {\n        for (int x = -dOutlineScale; x <= dOutlineScale; x++) {\n            if (x * x + y * y > dOutlineScale * dOutlineScale) {\n                continue;\n            }\n\n            vec2 sampleCoords = coords + vec2(float(x), float(y)) * invTexSize;\n\n            vec4 sampleOutlineCombined = texture2D(tOutlines, sampleCoords);\n            float sampleOutline = sampleOutlineCombined.r;\n            float sampleOutlineDepth = unpackRGToUnitInterval(sampleOutlineCombined.gb);\n\n            if (sampleOutline == 0.0 && sampleOutlineDepth < closestTexel && abs(selfViewZ - sampleOutlineDepth) > uMaxPossibleViewZDiff) {\n                outline = 0.0;\n                closestTexel = sampleOutlineDepth;\n            }\n        }\n    }\n    return outline;\n}\n\nfloat getSsao(vec2 coords) {\n    float rawSsao = unpackRGToUnitInterval(texture2D(tSsaoDepth, coords).xy);\n    if (rawSsao > 0.999) {\n        return 1.0;\n    } else if (rawSsao > 0.001) {\n        return rawSsao;\n    }\n    // treat values close to 0.0 as errors and return no occlusion\n    return 1.0;\n}\n\nvoid main(void) {\n    vec2 coords = gl_FragCoord.xy / uTexSize;\n    vec4 color = texture2D(tColor, coords);\n\n    float viewDist;\n    float fogFactor;\n\n    #ifdef dOcclusionEnable\n        float depth = getDepth(coords);\n        if (!isBackground(depth)) {\n            viewDist = abs(getViewZ(depth));\n            fogFactor = smoothstep(uFogNear, uFogFar, viewDist);\n            float occlusionFactor = getSsao(coords);\n            if (!uTransparentBackground) {\n                color.rgb = mix(mix(occlusionColor, uFogColor, fogFactor), color.rgb, occlusionFactor);\n            } else {\n                color.rgb = mix(occlusionColor * (1.0 - fogFactor), color.rgb, occlusionFactor);\n            }\n        }\n    #endif\n\n    // outline needs to be handled after occlusion to keep them clean\n    #ifdef dOutlineEnable\n        float closestTexel;\n        float outline = getOutline(coords, closestTexel);\n\n        if (outline == 0.0) {\n            color.rgb *= outline;\n            viewDist = abs(getViewZ(closestTexel));\n            fogFactor = smoothstep(uFogNear, uFogFar, viewDist);\n            if (!uTransparentBackground) {\n                color.rgb = mix(color.rgb, uFogColor, fogFactor);\n            } else {\n                color.a = 1.0 - fogFactor;\n            }\n        }\n    #endif\n\n    gl_FragColor = color;\n}\n";
