/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import{ColorConversion as e}from"../views/3d/webgl-engine/core/shaderLibrary/util/ColorConversion.glsl.js";import{addProjViewLocalOrigin as i}from"../views/3d/webgl-engine/core/shaderLibrary/util/View.glsl.js";import{Float4PassUniform as r}from"../views/3d/webgl-engine/core/shaderModules/Float4PassUniform.js";import{FloatPassUniform as o}from"../views/3d/webgl-engine/core/shaderModules/FloatPassUniform.js";import{glsl as l,If as d}from"../views/3d/webgl-engine/core/shaderModules/glsl.js";import{alphaCutoff as a}from"../views/3d/webgl-engine/shaders/alphaCutoff.glsl.js";import{outputColorHighlightOLID as s}from"../views/3d/webgl-engine/shaders/OutputColorHighlightOLID.glsl.js";import{ShaderBuilder as g}from"../views/webgl/ShaderBuilder.js";function t(t){const n=new g,{vertex:u,fragment:p,attributes:c,varyings:v}=n;return i(u,t),n.include(s,t),p.include(a),p.include(e),c.add("position","vec3"),c.add("uv0","vec2"),v.add("vUV","vec2"),u.main.add(l`vUV = uv0;
gl_Position = proj * view * vec4(position, 1.0);`),p.uniforms.add(new r("backgroundColor",e=>e.backgroundColor),new r("gridColor",e=>e.gridColor),new o("gridWidth",e=>e.gridWidth)).main.add(l`
    const float LINE_WIDTH = 1.0;

    vec2 uvScaled = vUV * gridWidth;
    vec2 gridUV = (fract(uvScaled + 0.5) - 0.5) / (LINE_WIDTH * fwidth(uvScaled));
    vec2 grid = (1.0 - step(0.5, gridUV)) * step(-0.5, gridUV);

    // mask aliasing along edges
    grid.x *= step(0.5, uvScaled.x) * step(uvScaled.x, gridWidth - 0.5);
    grid.y *= step(0.5, uvScaled.y) * step(uvScaled.y, gridWidth - 0.5);

    float gridFade = max(grid.x, grid.y);
    float gridAlpha = gridColor.a * gridFade;

    // premultiply alpha in output
    vec4 finalColor =
      premultiplyAlpha(backgroundColor) * (1.0 - gridAlpha) +
      premultiplyAlpha(vec4(gridColor.rgb, gridAlpha));
    ${d(t.emissionDimmingPass,"if (finalColor.a > alphaCutoff) { finalColor.rgb /= finalColor.a; }")}
    outputColorHighlightOLID(finalColor, finalColor.rgb);`),n}const n=Object.freeze(Object.defineProperty({__proto__:null,build:t},Symbol.toStringTag,{value:"Module"}));export{n as S,t as b};
