/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
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 i}from"../views/3d/webgl-engine/core/shaderLibrary/Slice.glsl.js";import{Transform as r}from"../views/3d/webgl-engine/core/shaderLibrary/Transform.glsl.js";import{ColorConversion as l}from"../views/3d/webgl-engine/core/shaderLibrary/util/ColorConversion.glsl.js";import{addProjViewLocalOrigin as n,addViewNormal as s}from"../views/3d/webgl-engine/core/shaderLibrary/util/View.glsl.js";import{Float3PassUniform as a}from"../views/3d/webgl-engine/core/shaderModules/Float3PassUniform.js";import{Float4PassUniform as d}from"../views/3d/webgl-engine/core/shaderModules/Float4PassUniform.js";import{glsl as t,If as c}from"../views/3d/webgl-engine/core/shaderModules/glsl.js";import{outputColorHighlightOLID as g}from"../views/3d/webgl-engine/shaders/OutputColorHighlightOLID.glsl.js";import{ShaderBuilder as m}from"../views/webgl/ShaderBuilder.js";function v(e){const v=new m;v.include(r),v.include(o,e),v.fragment.include(i,e),v.include(g,e);const{vertex:w,fragment:u}=v;return u.include(l),n(w,e),u.uniforms.add(new d("uColor",e=>e.color)),v.attributes.add("position","vec3"),v.varyings.add("vWorldPosition","vec3"),e.screenSizeEnabled&&v.attributes.add("offset","vec3"),e.shadingEnabled&&(s(w),v.attributes.add("normal","vec3"),v.varyings.add("vViewNormal","vec3"),u.uniforms.add(new a("shadingDirection",e=>e.shadingDirection)),u.uniforms.add(new d("shadedColor",e=>f(e.shadingTint,e.color)))),w.main.add(t`
    vWorldPosition = ${e.screenSizeEnabled?t`screenSizeScaling(offset, position)`:t`position`};
    ${c(e.shadingEnabled,t`vec3 worldNormal = normal;
           vViewNormal = (viewNormal * vec4(worldNormal, 1)).xyz;`)}
    gl_Position = transformPosition(proj, view, vWorldPosition);
  `),u.main.add(t`
      discardBySlice(vWorldPosition);

      ${e.shadingEnabled?t`vec3 viewNormalNorm = normalize(vViewNormal);
             float shadingFactor = 1.0 - clamp(-dot(viewNormalNorm, shadingDirection), 0.0, 1.0);
             vec4 finalColor = mix(uColor, shadedColor, shadingFactor);`:t`vec4 finalColor = uColor;`}
      outputColorHighlightOLID(applySlice(finalColor, vWorldPosition), finalColor.rgb);`),v}function f(e,o){const i=1-e[3],r=e[3]+o[3]*i;return 0===r?(w[3]=r,w):(w[0]=(e[0]*e[3]+o[0]*o[3]*i)/r,w[1]=(e[1]*e[3]+o[1]*o[3]*i)/r,w[2]=(e[2]*e[3]+o[2]*o[3]*i)/r,w[3]=o[3],w)}const w=e(),u=Object.freeze(Object.defineProperty({__proto__:null,build:v},Symbol.toStringTag,{value:"Module"}));export{u as S,v as b};
