import { CullingMaterial, clipPlanesStrings } from './CullingMaterial';
import { DIFFUSE_SAMPLER, OUTLINE_PROPERTY_DEFINE, PROPERTIES_SAMPLER, VISIBILITY_PROPERTY_DEFINE } from '../ShaderConstants';
import { TextureObject } from '../texture-object';
import { gpuPickingShader } from './shaders/GpuPickingShader';
const SIZE = 'size';
const WORLD_MATRIX = 'worldMatrix';
const IS_IFC_PICKING_MATERIAL = 'isIFcPickingMaterial';
const READ_ALPHA_PROPERTY_BYTE = 'readAlphaPropertyByte';
export class GpuPickingMaterial extends CullingMaterial {
    diffuseTexture;
    propertiesTexture;
    isOutlineDiscerner;
    constructor(name, scene, renderingInfo, diffuseTexture, propertiesTexture, isOutlineDiscerner = false) {
        super(name, scene, renderingInfo, {
            attributes: ['position', 'uv'],
            samplers: []
        }, false, false);
        this.diffuseTexture = diffuseTexture;
        this.propertiesTexture = propertiesTexture;
        this.isOutlineDiscerner = isOutlineDiscerner;
        this.visualSettings.ifc.transparency.onPropertyChanged.add((change) => {
            if (change.property === 'ditheringOptions') {
                this.isDirty = true;
            }
        });
    }
    getFragmentSource() {
        return gpuPickingShader.fragment({
            clipPlaneUniforms: () => {
                return clipPlanesStrings.CLIP_PLANE_UNIFORMS;
            },
            clipPlaneDiscarding: () => {
                return clipPlanesStrings.CLIP_PLANE_DISCARDING;
            },
            clipPlaneColorBlending: () => {
                return clipPlanesStrings.CLIP_PLANE_COLOR_BLENDING;
            }
        });
    }
    getVertexSource() {
        return gpuPickingShader.vertex({
            IsNotIfcProductFlag: () => {
                return `const float isNotIfcProductFlag = float(${TextureObject.IsNotIfcProductFlag.toString()});`;
            }
        });
    }
    getUniformsAndDefinesAndSamplers() {
        const uniformsAndDefinesAndSamplers = super.getUniformsAndDefinesAndSamplers();
        const uniforms = ['worldViewProjection', SIZE, WORLD_MATRIX];
        const defines = [VISIBILITY_PROPERTY_DEFINE];
        const samplers = [DIFFUSE_SAMPLER];
        if (this.propertiesTexture || this.isOutlineDiscerner) {
            defines.push(READ_ALPHA_PROPERTY_BYTE);
            samplers.push(PROPERTIES_SAMPLER);
        }
        if (this.propertiesTexture) {
            defines.push(IS_IFC_PICKING_MATERIAL);
        }
        if (this.isOutlineDiscerner) {
            defines.push(OUTLINE_PROPERTY_DEFINE);
        }
        return {
            uniforms: [...uniforms, ...uniformsAndDefinesAndSamplers.uniforms],
            defines: [...defines, ...uniformsAndDefinesAndSamplers.defines],
            samplers: [...uniformsAndDefinesAndSamplers.samplers, ...samplers]
        };
    }
    bindFunction(mesh) {
        super.bindFunction(mesh);
        const effect = this.getEffect();
        effect.setTexture(DIFFUSE_SAMPLER, this.diffuseTexture.getTexture(mesh.getScene()));
        if (this.propertiesTexture) {
            effect.setTexture(PROPERTIES_SAMPLER, this.propertiesTexture.getTexture(mesh.getScene()));
        }
        effect.setMatrix(WORLD_MATRIX, mesh.getWorldMatrix());
    }
}
//# sourceMappingURL=GpuPickingMaterial.js.map