/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import{If as e}from"../../core/shaderModules/glsl.js";import{Texture2DPassUniform as r}from"../../core/shaderModules/Texture2DPassUniform.js";import{alphaCutoff as t}from"../../shaders/alphaCutoff.glsl.js";import{oitResolution as o}from"../../shaders/oitResolution.glsl.js";import{NoParameters as n}from"../../../../webgl/NoParameters.js";class a extends n{}function l(n,a){const{frontFaceMask:l,useFloatBlend:c}=a;n.include(o,a),n.include(t),n.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(sampler2D colorTex, sampler2D frontFaceTex, float frontFaceScale) {\n      float srcAlpha = texture(alphaTexture, uv).r * floatBlendInputScale;\n      if(srcAlpha < alphaCutoff) {\n        return vec4(0.0);\n      }\n      vec4 frontFace = texture(frontFaceTex, uv);\n      ${e(l,"if (frontFace.a == 0.0) return vec4(0.0);")}\n\n      vec4 srcColor = texture(colorTex, uv);\n      srcColor.rgb *= floatBlendInputScale / srcAlpha;\n\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      return vec4(mix(srcColor.rgb, frontFace.rgb * frontFaceScale, frontFace.a), 1.0 - srcColor.a);\n    }\n\n    vec4 oitBlendFragment() {\n      return oitBlendFragment(colorTexture, frontFaceTexture, 1.0);\n    }\n  `)}export{a as OITBlendFragmentPassParameters,l as oitBlendFragment};
