/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import{create as e}from"../core/libs/gl-matrix-2/factories/vec4f64.js";import{ScreenSizeScaling as o}from"../views/3d/webgl-engine/core/shaderLibrary/ScreenSizeScaling.glsl.js";import{SliceDraw as r}from"../views/3d/webgl-engine/core/shaderLibrary/Slice.glsl.js";import{Transform as i}from"../views/3d/webgl-engine/core/shaderLibrary/Transform.glsl.js";import{terrainDepthTest as n}from"../views/3d/webgl-engine/core/shaderLibrary/shading/TerrainDepthTest.glsl.js";import{ColorConversion as l}from"../views/3d/webgl-engine/core/shaderLibrary/util/ColorConversion.glsl.js";import{addProjViewLocalOrigin as s,addViewNormal as a}from"../views/3d/webgl-engine/core/shaderLibrary/util/View.glsl.js";import{Float3PassUniform as d}from"../views/3d/webgl-engine/core/shaderModules/Float3PassUniform.js";import{Float4PassUniform as t}from"../views/3d/webgl-engine/core/shaderModules/Float4PassUniform.js";import{If as c,glsl as g}from"../views/3d/webgl-engine/core/shaderModules/glsl.js";import{outputColorHighlightOLID as m}from"../views/3d/webgl-engine/shaders/OutputColorHighlightOLID.glsl.js";import{ShaderBuilder as v}from"../views/webgl/ShaderBuilder.js";function w(e){const w=new v;w.include(i),w.include(o,e),w.fragment.include(r,e),w.include(m,e),w.include(n,e);const{vertex:u,fragment:b}=w;return b.include(l),s(u,e),b.uniforms.add(new t("uColor",e=>e.color)),w.attributes.add("position","vec3"),w.varyings.add("vWorldPosition","vec3"),e.screenSizeEnabled&&w.attributes.add("offset","vec3"),e.shadingEnabled&&(a(u),w.attributes.add("normal","vec3"),w.varyings.add("vViewNormal","vec3"),b.uniforms.add(new d("shadingDirection",e=>e.shadingDirection)),b.uniforms.add(new t("shadedColor",e=>f(e.shadingTint,e.color)))),u.main.add(g`
    vWorldPosition = ${e.screenSizeEnabled?g`screenSizeScaling(offset, position)`:g`position`};
    ${c(e.shadingEnabled,g`vec3 worldNormal = normal;
           vViewNormal = (viewNormal * vec4(worldNormal, 1)).xyz;`)}
    forwardViewPosDepth((view * vec4(vWorldPosition, 1.0)).xyz);
    gl_Position = transformPosition(proj, view, vWorldPosition);
  `),b.main.add(g`
      discardBySlice(vWorldPosition);
      discardByTerrainDepth();
      ${e.shadingEnabled?g`vec3 viewNormalNorm = normalize(vViewNormal);
             float shadingFactor = 1.0 - clamp(-dot(viewNormalNorm, shadingDirection), 0.0, 1.0);
             vec4 finalColor = mix(uColor, shadedColor, shadingFactor);`:g`vec4 finalColor = uColor;`}
      outputColorHighlightOLID(finalColor, vWorldPosition, finalColor.rgb);`),w}function f(e,o){const r=1-e[3],i=e[3]+o[3]*r;return 0===i?(u[3]=i,u):(u[0]=(e[0]*e[3]+o[0]*o[3]*r)/i,u[1]=(e[1]*e[3]+o[1]*o[3]*r)/i,u[2]=(e[2]*e[3]+o[2]*o[3]*r)/i,u[3]=o[3],u)}const u=e(),b=Object.freeze(Object.defineProperty({__proto__:null,build:w},Symbol.toStringTag,{value:"Module"}));export{b as S,w as b};
