/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","./BackgroundGrid.glsl","./TileBlendInput","../../shaderModules/Float3Uniform","../../shaderModules/Float4Uniform","../../shaderModules/FloatUniform","../../shaderModules/interfaces","../../shaderModules/Texture2DUniform"],(function(e,t,o,r,n,a,l,i){"use strict";function c(e,c){e.varyings.add("vtc","vec2"),e.vertex.uniforms.add(new n.Float4Uniform("texOffsetAndScale")),e.fragment.uniforms.add(new i.Texture2DUniform("tex")),e.fragment.uniforms.add(new r.Float3Uniform("textureOpacities"));const d=c.textureFadingEnabled&&!c.renderOccluded;d&&(e.vertex.uniforms.add(new n.Float4Uniform("nextTexOffsetAndScale")),e.varyings.add("nvtc","vec2"),e.fragment.uniforms.add(new i.Texture2DUniform("texNext")),e.fragment.uniforms.add(new r.Float3Uniform("nextTexOpacities")),e.fragment.uniforms.add(new a.FloatUniform("fadeFactor")));const s=c.tileBlendInput===o.TileBlendInput.ColorComposite,u=c.tileBlendInput===o.TileBlendInput.GridComposite;u&&e.fragment.include(t.BackgroundGrid),s&&e.fragment.uniforms.add(new r.Float3Uniform("backgroundColor")),e.vertex.code.add(l.glsl`
  void forwardTextureCoordinates(in vec2 uv) {
    vtc = uv * texOffsetAndScale.zw + texOffsetAndScale.xy;
    ${d?l.glsl`nvtc = uv * nextTexOffsetAndScale.zw + nextTexOffsetAndScale.xy;`:l.glsl``}
  }`),e.fragment.code.add(l.glsl`
    vec4 applyBaseOpacity(vec4 _color, vec3 _opacities) {
      return _opacities.z <= 0.0 ? _color : _color * _opacities.x;
    }

    vec4 getColor(vec4 color, vec2 uv, vec3 opacities) {
      ${u||s?l.glsl`
              if (opacities.y <= 0.0) {
                return color * opacities.z * opacities.x;
              }
              vec4 bg = ${s?l.glsl`vec4(backgroundColor, 1.0)`:l.glsl`gridColor(uv)`} * opacities.y;
              float alpha = opacities.z * color.a;
              return mix(bg, color, alpha) * opacities.x;`:l.glsl`return color;`}
    }`),d?e.fragment.code.add(l.glsl`vec4 getTileColor() {
vec4 color = getColor(texture2D(tex, vtc), vtc, textureOpacities);
if (fadeFactor >= 1.0) {
return color;
}
vec4 nextColor = getColor(texture2D(texNext, nvtc), nvtc, nextTexOpacities);
return mix(nextColor, color, fadeFactor);
}`):e.fragment.code.add(l.glsl`vec4 getTileColor() {
return getColor(texture2D(tex, vtc), vtc, textureOpacities);
}`)}e.TerrainTexture=c,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
