/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import{exactEquals as e}from"../../../../../../core/libs/gl-matrix-2/math/vec3.js";import{ZEROS as r}from"../../../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{ComponentTechnique as s}from"./ComponentTechnique.js";import{ComponentTechniqueConfiguration as t}from"./ComponentTechniqueConfiguration.js";import{MaterialBase as i}from"../../../core/material/MaterialBase.js";import{isColor as o}from"../../../core/shaderLibrary/ShaderOutput.js";class a extends i{constructor(e,r,s,i,o){super(),this.parameters=e,this.key=o,this.usePBR=e.usePBR,this.hasParametersFromSource=e.hasParametersFromSource,this.isGround=e.isGround,this.slicePlaneEnabled=e.slicePlaneEnabled,this.isIntegratedMesh=e.isIntegratedMesh,this.applySSAO=e.applySSAO,this.hasEmissions=u(e,s,i),this.materialPass=n(e,s),this._configuration=new t(i.sphericalSR),this._initializeMaterialConfiguration(e,r,s,i)}destroy(){}acquireTechnique(e,r,t,i){const o=this._updateConfiguration(r,t);return e.get(s,o,i.layout)}_initializeMaterialConfiguration(e,r,s,t){const i=this._configuration;i.hasMetallicRoughnessTexture=null!=e.metallicRoughnessTexture,i.hasOcclusionTexture=null!=e.occlusionTexture,i.hasNormalTexture=null!=e.normalTexture,i.sphereDepthInterpolate=e.sphereDepthInterpolate&&i.spherical,i.ellipsoidMode=e.ellipsoidMode,i.doubleSidedMode=e.doubleSided?1:0,i.hasColorTexture=null!=e.baseColorTexture,i.cullFace=e.cullFace,i.alphaDiscardMode=e.alphaDiscardMode,i.hasVertexColors=r.hasVertexColors,i.textureCoordinateType=r.textureCoordinateType,i.shadeNormals=r.shadeNormals,i.normalType=r.hasNormals?1:2,i.hasPolygonOffset=e.polygonOffsetEnabled,i.hasModelRotationScale=r.hasModelRotationScale,i.componentDataType=s.componentDataType,i.emissionSource=c(e,s,t)}_updateConfiguration(e,r){const s=this._configuration,{identifier:t,output:i}=e,a=0===t;s.output=i,s.hasEmission=r.hasEmission&&a,s.renderOccluded=10===r.slot,s.oitPass=a?r.oitPass:0,s.terrainDepthTest=a&&r.terrainDepthTest,s.cullAboveTerrain=!!a&&r.cullAboveTerrain;const n=this.isIntegratedMesh?d(r)?h(r)?3:2:1:0;s.integratedMeshMode=n,s.pbrMode=3===n?4:this.usePBR?this.hasParametersFromSource?s.shadeNormals&&this.isIntegratedMesh?0:2:1:0,s.hasSlicePlane=null!=r.slicePlane&&this.slicePlaneEnabled,s.isGroundSlice=s.hasSlicePlane&&this.isGround;const{materialPass:l}=this;s.blendingEnabled=1===l||2===l||4===l||s.isGroundSlice,s.hasHighlightMixTexture=2===t&&null!=r.highlightMixTexture,s.snowCover=a&&r.snowCover>0,s.vertexDiscardMode=a&&2===l?e.transparent?2:1:0;const u=a&&o(i);return s.receiveAmbientOcclusion=u&&this.applySSAO&&null!=r.ssao?.getTexture(),s.hasOccludees=u&&r.hasOccludees,s.receiveShadows=u&&r.shadowMap.ready,s.screenSpaceReflections=u&&null!=r.ssr.lastFrameColor,s.cloudReflections=u&&null!=r.clouds.data?.cubeMap?.colorTexture,s}}function n(e,r){const{alphaDiscardMode:s,isIntegratedMesh:t,slicePlaneEnabled:i}=e,{transparent:o,opaqueOverride:a}=r,n=e.opacity<1,l=e.baseColor[3]<1;if(t)return n||i?4:3;if(n)return 1;if(0===a)return 0;if(l||0===s||3===s)return 1;switch(o){case 2:return 0;case 0:return 1;case 1:return 2}}function l(s){return null!=s.emissionTexture||!e(s.emissiveBaseColor,r)}function u(e,r,s){const t=l(e);return s.floatBufferBlendSupported&&2!==r.emissiveOverride&&(t||2!==r.emissiveSourceOverride)}function c(e,r,s){const t=null!=e.emissionTexture,{emissiveSourceOverride:i}=r,o=1===i,a=2===i,n=u(e,r,s),c=l(e);return n?c?a?t?4:2:o?t?5:7:6:o?7:6:0}function h(e){return null!=e.overlay?.getTexture(3)}function d(e){return null!=e.overlay?.getTexture(1)}export{a as ComponentMaterial,c as calculateEmissionSource,u as calculateHasEmissions,l as calculateHasEmissiveBase,n as computeMaterialPass};
