/**
 * Copyright (c) 2019-2024 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 outlines_frag = "\nprecision highp float;\nprecision highp int;\nprecision highp sampler2D;\n\nuniform sampler2D tDepthOpaque;\nuniform sampler2D tDepthTransparent;\nuniform vec2 uTexSize;\n\nuniform float uNear;\nuniform float uFar;\nuniform mat4 uInvProjection;\n\nuniform float uOutlineThreshold;\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 getDepthOpaque(const in vec2 coords) {\n    #ifdef depthTextureSupport\n        return texture2D(tDepthOpaque, coords).r;\n    #else\n        return unpackRGBAToDepth(texture2D(tDepthOpaque, coords));\n    #endif\n}\n\nfloat getDepthTransparent(const in vec2 coords) {\n    #ifdef dTransparentOutline\n        return unpackRGBAToDepthWithAlpha(texture2D(tDepthTransparent, coords)).x;\n    #else\n        return 1.0;\n    #endif\n}\n\nbool isBackground(const in float depth) {\n    return depth == 1.0;\n}\n\nfloat getPixelSize(const in vec2 coords, const in float depth) {\n    vec3 viewPos0 = screenSpaceToViewSpace(vec3(coords, depth), uInvProjection);\n    vec3 viewPos1 = screenSpaceToViewSpace(vec3(coords + vec2(1.0, 0.0) / uTexSize, depth), uInvProjection);\n    return distance(viewPos0, viewPos1);\n}\n\nvoid main(void) {\n    float backgroundViewZ = 2.0 * uFar;\n\n    vec2 coords = gl_FragCoord.xy / uTexSize;\n    vec2 invTexSize = 1.0 / uTexSize;\n\n    float selfDepthOpaque = getDepthOpaque(coords);\n    float selfViewZOpaque = isBackground(selfDepthOpaque) ? backgroundViewZ : getViewZ(selfDepthOpaque);\n    float pixelSizeOpaque = getPixelSize(coords, selfDepthOpaque) * uOutlineThreshold;\n\n    float selfDepthTransparent = getDepthTransparent(coords);\n    float selfViewZTransparent = isBackground(selfDepthTransparent) ? backgroundViewZ : getViewZ(selfDepthTransparent);\n    float pixelSizeTransparent = getPixelSize(coords, selfDepthTransparent) * uOutlineThreshold;\n\n    float outline = 1.0;\n    float bestDepth = 1.0;\n    float transparentFlag = 0.0;\n\n    for (int y = -1; y <= 1; y++) {\n        for (int x = -1; x <= 1; x++) {\n            vec2 sampleCoords = coords + vec2(float(x), float(y)) * invTexSize;\n\n            float sampleDepthOpaque = getDepthOpaque(sampleCoords);\n            float sampleDepthTransparent = getDepthTransparent(sampleCoords);\n\n            float sampleViewZOpaque = isBackground(sampleDepthOpaque) ? backgroundViewZ : getViewZ(sampleDepthOpaque);\n            if (abs(selfViewZOpaque - sampleViewZOpaque) > pixelSizeOpaque && selfDepthOpaque > sampleDepthOpaque && sampleDepthOpaque <= bestDepth) {\n                outline = 0.0;\n                bestDepth = sampleDepthOpaque;\n            }\n\n            if (sampleDepthTransparent < sampleDepthOpaque) {\n                float sampleViewZTransparent = isBackground(sampleDepthTransparent) ? backgroundViewZ : getViewZ(sampleDepthTransparent);\n                if (abs(selfViewZTransparent - sampleViewZTransparent) > pixelSizeTransparent && selfDepthTransparent > sampleDepthTransparent && sampleDepthTransparent <= bestDepth) {\n                    outline = 0.0;\n                    bestDepth = sampleDepthTransparent;\n                    transparentFlag = 1.0;\n                }\n            }\n        }\n    }\n\n    gl_FragColor = vec4(outline, packUnitIntervalToRG(bestDepth), transparentFlag);\n}\n";
