/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import{addNearFar as o}from"../ForwardLinearDepthToWriteShadowMap.glsl.js";import{SliceDraw as r}from"../Slice.glsl.js";import{Transform as e}from"../Transform.glsl.js";import{NormalAttribute as t}from"../attributes/NormalAttribute.glsl.js";import{ObjectAndLayerIdColor as i}from"../attributes/ObjectAndLayerIdColor.glsl.js";import{TextureCoordinateAttribute as a}from"../attributes/TextureCoordinateAttribute.glsl.js";import{VertexNormal as s}from"../attributes/VertexNormal.glsl.js";import{OutputDepth as l}from"../output/OutputDepth.glsl.js";import{OutputHighlight as d}from"../output/OutputHighlight.glsl.js";import{VisualVariables as n}from"../shading/VisualVariables.glsl.js";import{DiscardOrAdjustAlphaPass as c}from"../util/DiscardOrAdjustAlpha.glsl.js";import{addProjViewLocalOrigin as u}from"../util/View.glsl.js";import{glsl as p,If as v}from"../../shaderModules/glsl.js";import{Texture2DPassUniform as m}from"../../shaderModules/Texture2DPassUniform.js";function f(f,g){const{vertex:x,fragment:O,varyings:j}=f,{hasColorTexture:h,alphaDiscardMode:w}=g,V=h&&1!==w,{output:C,normalType:b,hasColorTextureTransform:A}=g;switch(C){case 3:u(x,g),f.include(e),O.include(r,g),f.include(a,g),V&&O.uniforms.add(new m("tex",o=>o.texture)),x.main.add(p`vpos = getVertexInLocalOriginSpace();
vpos = subtractOrigin(vpos);
vpos = addVerticalOffset(vpos, localOrigin);
gl_Position = transformPosition(proj, view, vpos);
forwardTextureCoordinates();`),f.include(c,g),O.main.add(p`
        discardBySlice(vpos);
        ${v(V,p`vec4 texColor = texture(tex, ${A?"colorUV":"vuv0"});
                discardOrAdjustAlpha(texColor);`)}`);break;case 5:case 6:case 7:case 8:case 11:u(x,g),f.include(e),f.include(a,g),f.include(n,g),f.include(l,g),O.include(r,g),f.include(i,g),o(f),j.add("depth","float",{invariant:!0}),V&&O.uniforms.add(new m("tex",o=>o.texture)),x.main.add(p`vpos = getVertexInLocalOriginSpace();
vpos = subtractOrigin(vpos);
vpos = addVerticalOffset(vpos, localOrigin);
gl_Position = transformPositionWithDepth(proj, view, vpos, nearFar, depth);
forwardTextureCoordinates();
forwardObjectAndLayerIdColor();`),f.include(c,g),O.main.add(p`
        discardBySlice(vpos);
        ${v(V,p`vec4 texColor = texture(tex, ${A?"colorUV":"vuv0"});
               discardOrAdjustAlpha(texColor);`)}
        ${11===C?p`outputObjectAndLayerIdColor();`:p`outputDepth(depth);`}`);break;case 4:{u(x,g),f.include(e),f.include(t,g),f.include(s,g),f.include(a,g),f.include(n,g),V&&O.uniforms.add(new m("tex",o=>o.texture)),2===b&&j.add("vPositionView","vec3",{invariant:!0});const o=0===b||1===b;x.main.add(p`
        vpos = getVertexInLocalOriginSpace();
        ${o?p`vNormalWorld = dpNormalView(vvLocalNormal(normalModel()));`:p`vPositionView = (view * vec4(vpos, 1.0)).xyz;`}
        vpos = subtractOrigin(vpos);
        vpos = addVerticalOffset(vpos, localOrigin);
        gl_Position = transformPosition(proj, view, vpos);
        forwardTextureCoordinates();`),O.include(r,g),f.include(c,g),O.main.add(p`
        discardBySlice(vpos);
        ${v(V,p`vec4 texColor = texture(tex, ${A?"colorUV":"vuv0"});
                discardOrAdjustAlpha(texColor);`)}

        ${2===b?p`vec3 normal = screenDerivativeNormal(vPositionView);`:p`vec3 normal = normalize(vNormalWorld);
                    if (gl_FrontFacing == false){
                      normal = -normal;
                    }`}
        fragColor = vec4(0.5 + 0.5 * normal, 1.0);`);break}case 10:u(x,g),f.include(e),f.include(a,g),f.include(n,g),V&&O.uniforms.add(new m("tex",o=>o.texture)),x.main.add(p`vpos = getVertexInLocalOriginSpace();
vpos = subtractOrigin(vpos);
vpos = addVerticalOffset(vpos, localOrigin);
gl_Position = transformPosition(proj, view, vpos);
forwardTextureCoordinates();`),O.include(r,g),f.include(c,g),f.include(d,g),O.main.add(p`
        discardBySlice(vpos);
        ${v(V,p`vec4 texColor = texture(tex, ${A?"colorUV":"vuv0"});
                discardOrAdjustAlpha(texColor);`)}
        calculateOcclusionAndOutputHighlight();`)}}export{f as DefaultMaterialAuxiliaryPasses};
