/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import{ReadDepth as e}from"../output/ReadDepth.glsl.js";import{If as r,glsl as t}from"../../shaderModules/glsl.js";import{Texture2DBindUniform as o}from"../../shaderModules/Texture2DBindUniform.js";function i(i,{occlusionPass:d,terrainDepthTest:a,cullAboveTerrain:n}){const{vertex:s,fragment:p,varyings:h}=i;if(!a)return s.code.add("void forwardViewPosDepth(vec3 pos) {}"),void p.code.add(`${d?"bool":"void"} discardByTerrainDepth() { ${r(d,"return false;")}}`);h.add("viewPosDepth","float",{invariant:!0}),s.code.add("void forwardViewPosDepth(vec3 pos) {\n    viewPosDepth = pos.z;\n  }"),p.include(e),p.uniforms.add(new o("terrainDepthTexture",e=>e.terrainDepth?.attachment)).code.add(t`
    ${d?"bool":"void"} discardByTerrainDepth() {
      float depth = texelFetch(terrainDepthTexture, ivec2(gl_FragCoord.xy), 0).r;
      float linearDepth = linearizeDepth(depth);
      ${d?"return viewPosDepth < linearDepth && depth < 1.0;":`if(viewPosDepth ${n?">":"<="} linearDepth) discard;`}
    }`)}export{i as terrainDepthTest};
