/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../views/3d/webgl-engine/core/shaderLibrary/ForwardLinearDepth.glsl","../views/3d/webgl-engine/core/shaderLibrary/ShaderOutputOptions","../views/3d/webgl-engine/core/shaderLibrary/Slice.glsl","../views/3d/webgl-engine/core/shaderLibrary/Transform.glsl","../views/3d/webgl-engine/core/shaderLibrary/attributes/PathVertexPosition.glsl","../views/3d/webgl-engine/core/shaderLibrary/output/OutputDepth.glsl","../views/3d/webgl-engine/core/shaderLibrary/output/OutputHighlight.glsl","../views/3d/webgl-engine/core/shaderLibrary/shading/EvaluateAmbientOcclusion.glsl","../views/3d/webgl-engine/core/shaderLibrary/shading/EvaluateSceneLighting.glsl","../views/3d/webgl-engine/core/shaderLibrary/shading/MultipassTerrainTest.glsl","../views/3d/webgl-engine/core/shaderLibrary/shading/Normals.glsl","../views/3d/webgl-engine/core/shaderLibrary/shading/NormalUtils.glsl","../views/3d/webgl-engine/core/shaderLibrary/shading/ReadShadowMap.glsl","../views/3d/webgl-engine/core/shaderLibrary/util/ColorConversion.glsl","../views/3d/webgl-engine/core/shaderLibrary/util/View.glsl","../views/3d/webgl-engine/core/shaderModules/Float2PassUniform","../views/3d/webgl-engine/core/shaderModules/Float3PassUniform","../views/3d/webgl-engine/core/shaderModules/Float4Uniform","../views/3d/webgl-engine/core/shaderModules/FloatPassUniform","../views/3d/webgl-engine/core/shaderModules/interfaces","../views/3d/webgl-engine/core/shaderModules/Matrix4PassUniform","../views/3d/webgl-engine/core/shaderModules/ShaderBuilder","../views/3d/webgl-engine/lib/basicInterfaces","../views/3d/webgl-engine/lighting/SceneLighting"],(function(e,a,i,o,r,l,n,s,t,d,c,g,u,h,v,p,m,w,b,f,y,P,S,F,L){"use strict";function O(e){const O=new S.ShaderBuilder,M=p.addProjViewLocalOrigin(O,e),{vertex:C,fragment:D}=O;return O.varyings.add("vpos","vec3"),O.include(l.PathVertexPosition,e),e.output!==i.ShaderOutput.Color&&e.output!==i.ShaderOutput.Alpha||(O.include(r.Transform),O.include(h.ReadShadowMapDraw,e),O.include(a.ForwardLinearDepth,e),O.varyings.add("vnormal","vec3"),O.varyings.add("vcolor","vec4"),e.hasMultipassTerrain&&O.varyings.add("depth","float"),C.code.add(y.glsl`
      void main() {
        vpos = calculateVPos();
        vnormal = normalize(localNormal());

        ${e.hasMultipassTerrain?"depth = (view * vec4(vpos, 1.0)).z;":""}
        gl_Position = transformPosition(proj, view, vpos);

        ${e.output===i.ShaderOutput.Color?"forwardLinearDepth();":""}

        vcolor = getColor();
      }
    `)),O.include(c.multipassTerrainTest,e),e.output===i.ShaderOutput.Alpha&&(O.include(o.SliceDraw,e),D.uniforms.add(new f.FloatPassUniform("opacity",(e=>e.opacity))),D.code.add(y.glsl`
      void main() {
        discardBySlice(vpos);
        ${e.hasMultipassTerrain?"terrainDepthTest(gl_FragCoord, depth);":""}
        float combinedOpacity = vcolor.a * opacity;
        gl_FragColor = vec4(combinedOpacity);
      }
    `)),e.output===i.ShaderOutput.Color&&(O.include(o.SliceDraw,e),O.include(d.EvaluateSceneLighting,e),O.include(t.EvaluateAmbientOcclusion,e),O.include(h.ReadShadowMapDraw,e),O.include(g.Normals,e),p.addCameraPosition(D,e),D.uniforms.add([M,new w.Float3PassUniform("ambient",(e=>e.ambient)),new w.Float3PassUniform("diffuse",(e=>e.diffuse)),new w.Float3PassUniform("specular",(e=>e.specular)),new f.FloatPassUniform("opacity",(e=>e.opacity)),new f.FloatPassUniform("lightingGlobalFactor",((e,a)=>a.lighting.globalFactor)),new w.Float3PassUniform("lightingMainIntensity",((e,a)=>a.lighting.mainLight.intensity))]),D.constants.add("ambientBoostFactor","float",L.ambientBoost),D.include(v.ColorConversion),D.code.add(y.glsl`
      void main() {
        discardBySlice(vpos);
        ${e.hasMultipassTerrain?"terrainDepthTest(gl_FragCoord, depth);":""}

        shadingParams.viewDirection = normalize(vpos - cameraPosition);
        shadingParams.normalView = vnormal;
        vec3 normal = shadingNormal(shadingParams);
        float ssao = evaluateAmbientOcclusionInverse();

        float additionalAmbientScale = additionalDirectedAmbientLight(vpos + localOrigin);
        vec3 additionalLight = ssao * lightingMainIntensity * additionalAmbientScale * ambientBoostFactor * lightingGlobalFactor;
        ${e.receiveShadows?"float shadow = readShadowMap(vpos, linearDepth);":e.spherical?"float shadow = lightingGlobalFactor * (1.0 - additionalAmbientScale);":"float shadow = 0.0;"}
        vec3 albedo = vcolor.rgb * max(ambient, diffuse); // combine the old material parameters into a single one
        float combinedOpacity = vcolor.a * opacity;
        albedo += 0.25 * specular; // don't completely ignore specular for now

        vec3 shadedColor = evaluateSceneLighting(normal, albedo, shadow, 1.0 - ssao, additionalLight);
        gl_FragColor = vec4(shadedColor, combinedOpacity);
        gl_FragColor = highlightSlice(gl_FragColor, vpos);
        ${e.transparencyPassType===F.TransparencyPassType.Color?"gl_FragColor = premultiplyAlpha(gl_FragColor);":""}
      }
    `)),e.output!==i.ShaderOutput.Depth&&e.output!==i.ShaderOutput.Shadow||(O.include(r.Transform,{hasModelTransformation:!1,linearDepth:!0}),C.uniforms.add(new m.Float2PassUniform("nearFar",((e,a)=>a.camera.nearFar))),O.varyings.add("depth","float"),C.code.add(y.glsl`void main() {
vpos = calculateVPos();
gl_Position = transformPositionWithDepth(proj, view, vpos, nearFar, depth);
}`),O.include(o.SliceDraw,e),O.include(n.OutputDepth,e),D.code.add(y.glsl`void main() {
discardBySlice(vpos);
outputDepth(depth);
}`)),e.output===i.ShaderOutput.Normal&&(O.include(r.Transform),O.include(u.NormalUtils,e),C.uniforms.add(new P.Matrix4PassUniform("viewNormal",((e,a)=>a.camera.viewInverseTransposeMatrix))),O.varyings.add("vnormal","vec3"),C.code.add(y.glsl`void main(void) {
vpos = calculateVPos();
vnormal = normalize((viewNormal * vec4(localNormal(), 1.0)).xyz);
gl_Position = transformPosition(proj, view, vpos);
}`),O.include(o.SliceDraw,e),D.uniforms.add(new b.Float4Uniform("waterColor")),D.code.add(y.glsl`void main() {
discardBySlice(vpos);
vec3 normal = normalize(vnormal);
if (gl_FrontFacing == false) normal = -normal;
gl_FragColor = vec4(vec3(0.5) + 0.5 * normal, 1.0);
}`)),e.output===i.ShaderOutput.Highlight&&(O.include(r.Transform),O.include(u.NormalUtils,e),O.varyings.add("vnormal","vec3"),C.code.add(y.glsl`void main(void) {
vpos = calculateVPos();
gl_Position = transformPosition(proj, view, vpos);
}`),O.include(o.SliceDraw,e),O.include(s.OutputHighlight),D.code.add(y.glsl`void main() {
discardBySlice(vpos);
outputHighlight();
}`)),O}const M=Object.freeze(Object.defineProperty({__proto__:null,build:O},Symbol.toStringTag,{value:"Module"}));e.Path=M,e.build=O}));
