
precision highp float;
precision highp int;

in float vColorPixelIndex;
in vec2 vUV;

#ifndef nonLinearDepth
    in float vDepthMetric;
#endif

#ifdef requiresWorldFragment
    in vec3 vPositionW;
#endif

uniform sampler2D diffuseSampler;
#ifdef isBabylonMesh
    uniform float babylonMeshAlpha;
#else
    uniform sampler2D propertiesSampler;
#endif

uniform vec3 size;
// #typescript options?.clipPlaneUniforms()

void main(void) {

    ivec2 textureSize = textureSize(diffuseSampler, 0);
    float colorPixelIndex = vColorPixelIndex + 0.5;
    float uvY = floor(colorPixelIndex / float(textureSize.x));
    float uvX = floor(floor(colorPixelIndex) - uvY * float(textureSize.x));
    vec2 pixelIndex = vec2(uvX, uvY);

    #ifndef isBabylonMesh
        // #include PropertiesPixel.glsl
    #endif

    #ifdef discardDitherTransparent
        float alpha = texelFetch(diffuseSampler, ivec2(pixelIndex), 0).a;

        #ifndef isBabylonMesh
            if (abs(alpha - 1.0) > 0.0001) {
                discard;
            }
        #endif
    #endif

    #ifdef isBabylonMesh
        if(babylonMeshAlpha < 0.001) {
            discard;
        }
    #else
        if (!visible && !depthWriteIgnoresVisibility) {
            discard;
        }
    #endif

    #ifdef requiresWorldFragment
        vec3 worldSpaceVertex = vPositionW;

        // #typescript options?.clipPlaneDiscarding()
    #endif
    float depthValue;
    #ifdef nonLinearDepth
        depthValue = gl_FragCoord.z;
    #else
        depthValue = vDepthMetric;
    #endif

    gl_FragColor = vec4(depthValue, 0, 0, 0);
}
