/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import{isColor as o,isOITColorAlpha as l,isOITFrontFace as i}from"../core/shaderLibrary/ShaderOutput.js";import{Emissions as r}from"../core/shaderLibrary/output/Emissions.glsl.js";import{OutputHighlight as a}from"../core/shaderLibrary/output/OutputHighlight.glsl.js";import{ColorConversion as s}from"../core/shaderLibrary/util/ColorConversion.glsl.js";import{emissionDimming as e}from"../core/shaderLibrary/util/EmissionDimming.glsl.js";import{If as n,glsl as t}from"../core/shaderModules/glsl.js";import{alphaCutoff as f}from"./alphaCutoff.glsl.js";import{ditherNoise as m}from"./ditherNoise.glsl.js";import{oitResolution as g}from"./oitResolution.glsl.js";function u(u,p){u.include(a,p),u.include(r,p);const{fragment:d,outputs:c}=u,{output:h,hasEmission:C,discardInvisibleFragments:b,oitPremultipliedAlpha:v,snowCover:A,useFloatBlend:E,emissionDimmingPass:y}=p,$=11===h,j=l(h),O=i(h),L=o(h)&&!j;let S=0;(L||j)&&c.add("fragColor","vec4",S++),j&&c.add("fragAlpha","float",S++),C&&c.add("fragEmission","vec4",S++),d.include(s),d.include(f),d.include(g,p),d.include(m,p),y&&d.include(e,p),d.code.add(t`
    void outputColorHighlightOLID(vec4 finalColor, vec3 emissiveSymbolColor ${n(A,", float snow")}) {
      ${n($,"finalColor.a = 1.0;")}
      ${n(b,"if (finalColor.a < alphaCutoff) { discard; }")}

      ${n(j,`float noise = ditherNoise(finalColor);\n         fragColor = ${n(v,"finalColor","premultiplyAlpha(finalColor)")};\n         fragColor = vec4(fragColor.rgb * floatBlendOutputScale + noise, fragColor.a);\n         float scaledAlpha = finalColor.a * floatBlendOutputScale;\n         fragAlpha = scaledAlpha + noise;\n         ${n(!E,"fragAlpha = fragAlpha < alphaCutoff ? scaledAlpha : fragAlpha;")}`)}
      ${n(O&&v&&b,"finalColor.rgb /= finalColor.a;")}
      ${n(L,"fragColor = finalColor;")}
      ${n(C,y?"fragEmission = vec4(emissionDimming(premultiplyAlpha(finalColor).rgb, finalColor.a), 0.0);":`fragEmission = ${n(A,"mix(finalColor.a * getEmissions(emissiveSymbolColor), vec4(0.0), snow);","finalColor.a * getEmissions(emissiveSymbolColor);")}\n            float emissionNoise = ditherNoise(fragEmission);\n            fragEmission.rgb = fragEmission.rgb * floatBlendOutputScale + emissionNoise;\n            fragEmission.a = finalColor.a;\n            fragEmission = premultiplyAlpha(fragEmission);\n            `)}
      calculateOcclusionAndOutputHighlight();
      ${n($,"outputObjectAndLayerIdColor();")}
    }
  `)}export{u as outputColorHighlightOLID};
