/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import{gauss as e}from"../core/mathUtils.js";import{ScreenSpacePass as r}from"../views/3d/webgl-engine/core/shaderLibrary/ScreenSpacePass.glsl.js";import{Gamma as o}from"../views/3d/webgl-engine/core/shaderLibrary/shading/Gamma.glsl.js";import{FloatPassUniform as s}from"../views/3d/webgl-engine/core/shaderModules/FloatPassUniform.js";import{glsl as t}from"../views/3d/webgl-engine/core/shaderModules/glsl.js";import{Texture2DPassUniform as i}from"../views/3d/webgl-engine/core/shaderModules/Texture2DPassUniform.js";import{blurRadiusPresets as l}from"../views/3d/webgl-engine/effects/glow/GlowPresets.glsl.js";import{NoParameters as n}from"../views/webgl/NoParameters.js";import{ShaderBuilder as a}from"../views/webgl/ShaderBuilder.js";class c extends n{constructor(){super(...arguments),this.blurRadius=l.sunny}}function u(l){const n=new a,c=n.fragment;n.include(r),c.include(o),c.uniforms.add(new i("colorTexture",e=>e.emissionsToDownsample),new s("blurRadius",e=>e.blurRadius));let u="";const d=15;for(let e=0;e<d;e++){u+=`locations1D[${e}] = ${(e/(d-1)*2-1).toFixed(3).toString()};`}const m=2;let f="";for(let r=0;r<d;r++){f+=`locations1DWeights[${r}] = ${e(r-Math.floor(d/2),m).toFixed(7).toString()};`}const v=0===l.glowStage;return c.code.add(t`
    float locations1D[${t.int(d)}];
    float locations1DWeights[${t.int(d)}];

    vec3 blurUniformSamples(sampler2D toBlur) {
      vec3 res = vec3(0.0);
      vec2 size = vec2(textureSize(toBlur, 0));
      vec2 aspectCorrection = vec2(1.0, size.x / size.y);
      vec2 uvInPixel = uv * size;

      ${u}
      ${f}
      vec2 pixelCenterShift = 0.5 / size;

      for(int i=0;i < ${t.int(d)}; i++) {
        float uv1D = locations1D[i] + ${v?"pixelCenterShift.x":"pixelCenterShift.y"};
        vec2 uvOffset = ${v?"vec2(uv1D, 0.0)":"vec2(0.0, uv1D)"};

        vec2 uvDistorted = uv + uvOffset * blurRadius * aspectCorrection;
        vec3 sampleColor = texture(toBlur, uvDistorted).rgb;
        res += sampleColor * locations1DWeights[i];
      }
      return res;
    }
  `).main.add(t`fragColor = vec4(blurUniformSamples(colorTexture), 0.0);`),n}const d=Object.freeze(Object.defineProperty({__proto__:null,GlowBlurPassParameters:c,build:u},Symbol.toStringTag,{value:"Module"}));export{c as G,d as a,u as b};
