/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import{normalize as e}from"../core/arrayUtils.js";import{gauss as r}from"../core/mathUtils.js";import{create as o}from"../core/libs/gl-matrix-2/factories/vec2f64.js";import{ScreenSpacePass as t}from"../views/3d/webgl-engine/core/shaderLibrary/ScreenSpacePass.glsl.js";import{Gamma as i}from"../views/3d/webgl-engine/core/shaderLibrary/shading/Gamma.glsl.js";import{Float2PassUniform as s}from"../views/3d/webgl-engine/core/shaderModules/Float2PassUniform.js";import{FloatPassUniform as l}from"../views/3d/webgl-engine/core/shaderModules/FloatPassUniform.js";import{If as a,glsl as n}from"../views/3d/webgl-engine/core/shaderModules/glsl.js";import{Texture2DPassUniform as c}from"../views/3d/webgl-engine/core/shaderModules/Texture2DPassUniform.js";import{NoParameters as u}from"../views/webgl/NoParameters.js";import{ShaderBuilder as v}from"../views/webgl/ShaderBuilder.js";class d extends u{constructor(){super(...arguments),this.blurRadius=0,this.level=0,this.inputScale=1,this.size=o()}}function f({glowStage:o,useFloatBlend:u}){const d=new v,f=d.fragment;d.include(t),f.include(i);const m=0===o;f.uniforms.add(new c("colorTexture",e=>e.input),new l("blurRadius",({blurRadius:e})=>e),new l("level",({level:e})=>e),new l("inputScale",({inputScale:e})=>u?1:e),new s("size",({size:e})=>e));const p=7;let w="float locations1D["+p+"] = float["+p+"](";for(let e=0;e<p;e++){w+=`${0===e?"":","} ${(e/(p-1)*2-1).toFixed(15)}`}w+=");";const g=2,b=new Array(p).fill(0).map((e,o)=>r(o-Math.floor(p/2),g));e(b);const h=b.reduce((e,r,o)=>`${e}${0===o?"":","} ${r.toFixed(15)}`,"float locations1DWeights["+p+"] = float["+p+"](")+");";return f.code.add(n`
    ${w}
    ${h}

    vec3 blurUniformSamples() {
      int textureLevel = int(${m?"level":"0.0"});
      vec2 aspectCorrection = vec2(1.0, size.x / size.y);

      ${a(m,"float viewportScale = 1.0;","float viewportScale = 1.0 / pow(2.0, level);")}
      vec2 uv = uv * viewportScale;
      vec2 pixelCenterShift = 0.5 / size;

      vec3 res = vec3(0.0);
      for(int i = 0; i < ${n.int(p)}; ++i) {
        float uv1D = locations1D[i] * viewportScale + ${m?"pixelCenterShift.x":"pixelCenterShift.y"};
        vec2 uvOffset = ${m?"vec2(uv1D, 0.0)":"vec2(0.0, uv1D)"};
        vec2 uvDistorted = uv + uvOffset * blurRadius * aspectCorrection;
        vec3 sampleColor = texture(colorTexture, uvDistorted, -1.0).rgb * inputScale;
        res += sampleColor * locations1DWeights[i];
      }
      return res;
    }
  `).main.add(n`fragColor = vec4(blurUniformSamples(), 0.0);`),d}const m=Object.freeze(Object.defineProperty({__proto__:null,GlowBlurPassParameters:d,build:f},Symbol.toStringTag,{value:"Module"}));export{d as G,m as a,f as b};
