/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import{ScreenSpacePass as e}from"../views/3d/webgl-engine/core/shaderLibrary/ScreenSpacePass.glsl.js";import{If as r,glsl as s}from"../views/3d/webgl-engine/core/shaderModules/glsl.js";import{Texture2DPassUniform as o}from"../views/3d/webgl-engine/core/shaderModules/Texture2DPassUniform.js";import{O as t}from"./OITDim.glsl.js";import{ShaderBuilder as n}from"../views/webgl/ShaderBuilder.js";class a extends t{}function i(t){const a=new n;a.include(e);const{hasEmitters:i}=t,c=a.fragment;return c.uniforms.add(new o("colorTexture",e=>e.colorTexture),new o("alphaTexture",e=>e.alphaTexture)),a.outputs.add("fragColor","vec4",0),i&&a.outputs.add("fragEmission","vec4",1),c.uniforms.add(new o("frontFaceTexture",e=>e.frontFaceTexture)),i&&(c.uniforms.add(new o("emissionTexture",e=>e.emissionTexture)),c.uniforms.add(new o("emissionFrontFaceTexture",e=>e.emissionFrontFaceTexture))),c.main.add(s`
    float srcAlpha = texture(alphaTexture, uv).r;
    if(srcAlpha == 0.0){
      fragColor = vec4(0.0);
      ${r(i,"fragEmission = vec4(0.0);")}
      return;
    }

    vec4 srcColor = texture(colorTexture, uv);
    vec4 frontFace = texture(frontFaceTexture, uv);
    fragColor = vec4(mix(srcColor.rgb / srcAlpha, frontFace.rgb, frontFace.a), 1.0 - srcColor.a);

    ${r(i,"vec4 emission = texture(emissionTexture, uv);\n        vec4 emissionFrontFace = texture(emissionFrontFaceTexture, uv);\n\n        // Modulate transparent emitter by front faces. This case is important for surfaces which contain emitter and\n        // non-emitter at the same time. Non-emitter surface parts need to modulate emissions as well.\n        emission.rgb = emission.rgb * (1.0 - frontFace.a);\n\n        fragEmission = vec4(mix(emission.rgb / srcAlpha, emissionFrontFace.rgb, emissionFrontFace.a), 1.0 - srcColor.a);")}
  `),a}const c=Object.freeze(Object.defineProperty({__proto__:null,OITBlendPassParameters:a,build:i},Symbol.toStringTag,{value:"Module"}));export{a as O,c as a,i as b};
