/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import{ReadShadowMapPassParameters as e}from"../shading/ReadShadowMap.glsl.js";import{BackgroundGrid as t}from"./BackgroundGrid.glsl.js";import{If as o,glsl as r}from"../../shaderModules/glsl.js";import{Uniform as c}from"../../../../../webgl/Uniform.js";class n extends e{constructor(){super(...arguments),this.overlayOpacity=1}}function s(e,c){const{vertex:n,fragment:s,varyings:u}=e;u.add("vtc","vec2"),n.uniforms.add(new i("texOffsetAndScale")),s.uniforms.add(new l("tex")),s.uniforms.add(new d("textureOpacities"));const{textureFadingEnabled:x,renderOccluded:f,tileBlendInput:v}=c,p=x&&!f;p&&(n.uniforms.add(new i("nextTexOffsetAndScale")),u.add("nvtc","vec2"),s.uniforms.add(new l("texNext")),s.uniforms.add(new d("nextTexOpacities")),s.uniforms.add(new a("fadeFactor")));const m=2===v;m&&s.include(t);const g=1===v;g&&s.uniforms.add(new d("backgroundColor")),n.code.add(r`
  void forwardTextureCoordinatesWithTransform(in vec2 uv) {
    vtc = texOffsetAndScale.xy + uv * texOffsetAndScale.zw;
    ${o(p,"nvtc = nextTexOffsetAndScale.xy + uv * nextTexOffsetAndScale.zw;")}
  }`),s.code.add(r`
    vec4 getColor(vec4 color, vec2 uv, vec3 opacities) {
      ${o(m||g,r`if (opacities.y <= 0.0) {
           return color * opacities.z * opacities.x;
         }
         vec4 bg = vec4(${g?r`backgroundColor`:r`gridColor(uv)`} * opacities.y, opacities.y);
         vec4 layer = color * opacities.z;
         return (bg * (1.0 - layer.a) + layer) * opacities.x;`,"return color;")}
    }`),p?s.code.add(r`vec4 getTileColor() {
vec4 color = getColor(texture(tex, vtc), vtc, textureOpacities);
if (fadeFactor >= 1.0) {
return color;
}
vec4 nextColor = getColor(texture(texNext, nvtc), nvtc, nextTexOpacities);
return mix(nextColor, color, fadeFactor);
}`):s.code.add(r`vec4 getTileColor() {
return getColor(texture(tex, vtc), vtc, textureOpacities);
}`)}class a extends c{constructor(e){super(e,"float")}}class d extends c{constructor(e){super(e,"vec3")}}class i extends c{constructor(e){super(e,"vec4")}}class l extends c{constructor(e){super(e,"sampler2D")}}export{d as Float3Uniform,n as OverlayTerrainPassParameters,s as TerrainTexture,l as Texture2DUniform};
