/* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
import{If as e}from"../../core/shaderModules/glsl.js";import{Texture2DPassUniform as r}from"../../core/shaderModules/Texture2DPassUniform.js";import{alphaCutoff as o}from"../../shaders/alphaCutoff.glsl.js";import{oitResolution as t}from"../../shaders/oitResolution.glsl.js";import{NoParameters as a}from"../../../../webgl/NoParameters.js";class n extends a{}function l(a,n){const{frontFaceMask:l,useFloatBlend:c}=n;a.include(t,n),a.include(o),a.uniforms.add(new r("colorTexture",e=>e.colorTexture),new r("alphaTexture",e=>e.alphaTexture),new r("frontFaceTexture",e=>e.frontFaceTexture)).code.add(`\n    vec4 oitBlendFragment() {\n      float srcAlpha = texture(alphaTexture, uv).r * floatBlendInputScale;\n      if(srcAlpha < alphaCutoff) {\n        return vec4(0.0);\n      }\n      vec4 frontFace = texture(frontFaceTexture, uv);\n      ${e(l,"if (frontFace.a == 0.0) return vec4(0.0);")}\n\n      vec4 srcColor = texture(colorTexture, uv);\n      ${e(!c,"float frontWeight = srcAlpha * floatBlendOutputScale;\n        frontWeight = clamp((frontWeight - 0.9) * 10.0, 0.0, 1.0);\n\n        float toAlpha = (1.0 + frontFace.a) * 0.5;\n        frontFace.a = mix(frontFace.a, toAlpha, frontWeight);")}\n      vec3 backColor = srcColor.rgb * floatBlendInputScale / srcAlpha;\n      return vec4(mix(backColor, frontFace.rgb, frontFace.a), 1.0 - srcColor.a);\n    }\n  `)}export{n as OITBlendFragmentPassParameters,l as oitBlendFragment};
