/**
 * NOTE: This file is autogenerated. Do not edit.
 */
export const gpuPickingShader = {
    vertex: (options?: Record<string, () => string>): string => /* glsl */ `
        // #typescript options?.IsNotIfcProductFlag()
        ${options?.IsNotIfcProductFlag()}
        
        
        precision highp float;
        
        attribute vec3 position;
        attribute vec2 uv;
        uniform vec3 size;
        uniform mat4 worldViewProjection;
        uniform mat4 worldMatrix;
        out vec3 vPositionW;
        out float vColorPixelIndex;
        
        void main(void) {
            gl_Position = worldViewProjection * vec4(position, 1.0);
        
            vPositionW = (worldMatrix * vec4(position, 1.0)).xyz;
        
            // uv.x is colorPixelIndex which represents 
            // * pixel offset in IFC object color texture (diffuseSampler). We calculate real UV coordinates from this
            // * gpu pickingcolor (RGB). We use this as fragment color to ge unique color representing the object this vertex belongs to.
            //   do note that we only use 24 bits of uv.x for color (alpha is not used). Hence we have a maximum of 2^24 unique colors.
        
            vColorPixelIndex = uv.x;
        }`,
    fragment: (options?: Record<string, () => string>): string => /* glsl */ `
        precision highp float;    
        precision highp int;
        
        in vec3 vPositionW;
        in float vColorPixelIndex;
        uniform vec3 size;
        #if defined(readAlphaPropertyByte) || defined(outlinedProperty)
            uniform sampler2D propertiesSampler;
            // #typescript options?.clipPlaneUniforms()
        ${options?.clipPlaneUniforms()}
        #endif
        uniform sampler2D diffuseSampler;
        
        
        vec3 unpackRGBColor(float f)
        {
            uint bits = uint(f);
            return vec3(
                float(bits & 0xFFu),
                float((bits >> 8u) & 0xFFu),
                float((bits >> 16u) & 0xFFu)
            ) / 255.0;
        }
        
        void main(void) {
            ivec2 textureSize = textureSize(diffuseSampler, 0);
            
            // #include ColorPickingIndex.glsl
        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);
            
            // colorPixelIndex holds the gpu picking color 
            vec3 gpuPickingColorAndAlpha = unpackRGBColor(colorPixelIndex);  
            
            #if defined(readAlphaPropertyByte) || defined(outlinedProperty)
                // #include PropertiesPixel.glsl
        vec4 properties = texelFetch(propertiesSampler, ivec2(floor(pixelIndex)), 0);
        
        int castedA = int(ceil(clamp(properties.a, 0., 1.) * 255.0));
        #ifdef depthWriteIgnoresVisibilityProperty
            int lastBitMask = 1; // Depth write bit
            int depthWriteIgnoresVisibilityValue = castedA & lastBitMask;
            bool depthWriteIgnoresVisibility = depthWriteIgnoresVisibilityValue == lastBitMask;
        #endif
        
        #ifdef visibilityProperty
            int secondLastBitMask = 2; // Visibility bit
            int visibilityValue = castedA & secondLastBitMask;
            bool visible = visibilityValue == secondLastBitMask;
        #endif
        
        #ifdef highlightProperty
            int fourthAndThirdLastBitsMask = 12; // Highlight bits
            int highlightIndex = (castedA & fourthAndThirdLastBitsMask) >> 2; // Move 2 bits right to get 0-3 range
            bool highlighted = highlightIndex != 0;
        #endif
        
        #ifdef outlinedProperty
            int fifthBitMask = 16; // Outline bit
            int outlinedValue = castedA & fifthBitMask;
            bool outlined = outlinedValue == fifthBitMask;
        #endif
        
        #ifdef ignoreClipPlanesProperty
            int sixthBitMask = 32; // Clip plane ignore bit
            int clipPlaneIgnoreValue = castedA & sixthBitMask;
            bool clipPlaneIgnore = clipPlaneIgnoreValue == sixthBitMask;
        #endif
        
            #endif
            #ifdef isIFcPickingMaterial
                #ifdef requiresWorldFragment
                    vec3 worldSpaceVertex = vPositionW;
        
                    // #typescript options?.clipPlaneDiscarding()
        ${options?.clipPlaneDiscarding()}
                #endif
                
                
                if (!visible) {
                    discard;
                }
        
                float alpha = texelFetch(diffuseSampler, ivec2(pixelIndex), 0).a;
                if (sign(alpha) < 1.0) {
                    discard;
                }
            #endif
            #ifdef outlinedProperty
                
                if (!outlined) {
                    discard;
                }
            #endif
            
            
            gl_FragColor = vec4(gpuPickingColorAndAlpha, 1.0);
        }`
};
