/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import{create as a}from"../../../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{ForwardLinearDepthToReadShadowMap as o}from"../ForwardLinearDepthToReadShadowMap.glsl.js";import{calculateUVZShadowPass as e,calculateUVZShadowDraw as t,ReadShadowMapOrigin as r}from"./calculateUVZShadow.glsl.js";import{ShadowmapFiltering as d}from"./ShadowmapFiltering.glsl.js";import{FloatBindUniform as i}from"../../shaderModules/FloatBindUniform.js";import{If as n,glsl as s}from"../../shaderModules/glsl.js";import{Texture2DBindUniform as l}from"../../shaderModules/Texture2DBindUniform.js";import{Texture2DShadowBindUniform as h}from"../../shaderModules/Texture2DShadowBindUniform.js";import{NoParameters as c}from"../../../../../webgl/NoParameters.js";class u extends r{}class w extends c{constructor(){super(...arguments),this.origin=a()}}function f(a,o){o.receiveShadows&&a.fragment.include(e),g(a,o)}function m(a,o){o.receiveShadows&&a.fragment.include(t),g(a,o)}function g(a,e){a.fragment.uniforms.add(new i("lightingGlobalFactor",a=>a.lighting.globalFactor));const{hasShadowHighlights:t,receiveShadows:r,spherical:d}=e;a.include(o,e),r&&p(a.fragment,t),a.fragment.code.add(s`
    float readShadow(float additionalAmbientScale, vec3 vpos) {
      return ${r?"max(lightingGlobalFactor * (1.0 - additionalAmbientScale), readShadowMap(vpos, linearDepth))":n(d,"lightingGlobalFactor * (1.0 - additionalAmbientScale)","0.0")};
    }
  `)}function p(a,o){v(a,o),S(a)}function S(a){a.code.add(s`float readShadowMap(const in vec3 _worldPos, float _linearDepth) {
vec3 uvzShadow = calculateUVZShadow(_worldPos, _linearDepth, textureSize(shadowMap, 0));
return readShadowMaps(uvzShadow);
}`)}function v(a,o){a.include(d),a.uniforms.add(M()),o&&a.uniforms.add(new l("shadowHighlight",({shadowHighlight:a})=>a?.getTexture())),a.code.add(s`
    float readShadowMaps(const in vec3 uvzShadow) {
      if (uvzShadow.z < 0.0) {
        return 0.0;
      }

      float shadow1 = readShadowMapUVZ(uvzShadow, shadowMap);
      ${n(o,"float shadow2 = texelFetch(shadowHighlight, ivec2(gl_FragCoord.xy), 0).r;\n         return shadow1 > shadow2 ? shadow1 : shadow2;","return shadow1;")}
    }
  `)}function M(){return new h("shadowMap",({shadowMap:a})=>a.getOutput(5)??a.getOutput(7))}export{m as ReadShadowMapDrawFragment,u as ReadShadowMapDrawParameters,f as ReadShadowMapPassFragment,w as ReadShadowMapPassParameters,v as readShadowMapsFragment};
