/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import{normalize as e}from"../core/arrayUtils.js";import{ReadDepth as o}from"../views/3d/webgl-engine/core/shaderLibrary/output/ReadDepth.glsl.js";import{Gamma as r}from"../views/3d/webgl-engine/core/shaderLibrary/shading/Gamma.glsl.js";import{FloatPassUniform as i}from"../views/3d/webgl-engine/core/shaderModules/FloatPassUniform.js";import{FloatsPassUniform as s}from"../views/3d/webgl-engine/core/shaderModules/FloatsPassUniform.js";import{glsl as l}from"../views/3d/webgl-engine/core/shaderModules/glsl.js";import{IntegerPassUniform as a}from"../views/3d/webgl-engine/core/shaderModules/IntegerPassUniform.js";import{Texture2DBindUniform as t}from"../views/3d/webgl-engine/core/shaderModules/Texture2DBindUniform.js";import{Texture2DPassUniform as n}from"../views/3d/webgl-engine/core/shaderModules/Texture2DPassUniform.js";import{DistanceFalloffPassParameters as d,getDistanceFalloff as m}from"../views/3d/webgl-engine/effects/raymarching/DistanceFalloff.glsl.js";import{ditherNoise as c}from"../views/3d/webgl-engine/shaders/ditherNoise.glsl.js";import{oitResolution as p}from"../views/3d/webgl-engine/shaders/oitResolution.glsl.js";import{ScreenSpacePassAtmosphere as u}from"../views/3d/webgl-engine/shaders/ScreenSpacePassAtmosphere.glsl.js";import{ToneMapping as g}from"../views/3d/webgl-engine/shaders/ToneMapping.glsl.js";import{ShaderBuilder as f}from"../views/webgl/ShaderBuilder.js";class x extends d{constructor(){super(...arguments),this.glowLod=-1,this.minDisperse=new v([32,16,8,4,2,1],1),this.maxDisperse=new v([0,.27,.6,1.05,1.58,2.1],6),this.fogOpacity=1e-4}}function w(e){const d=new f,x=d.fragment;return d.include(u,{needUVs:!0,needEyeDirection:!0}),x.include(r),x.include(m),x.include(o),d.outputs.add("fragColor","vec4",0),d.outputs.add("fragEmission","vec3",1),x.include(g),x.include(p,e),x.include(c,e),x.uniforms.add(new n("colorTexture",({color:e})=>e),new n("emissionTexture",({emission:e})=>e)),e.blurEnabled?(x.uniforms.add(new t("depthTexture",e=>e.mainDepth),new i("fogOpacity",e=>e.fogOpacity),new n("lodTexture",e=>e.lodTexture?.getTexture()),new a("glowLod",e=>e.glowLod),new s("minDisperse",6,e=>e.minDisperse.preset),new s("maxDisperse",6,e=>e.maxDisperse.preset)).main.add(l`vec4 color = texture(colorTexture, uv);
color = vec4(linearizeGamma(color.rgb), color.a);
vec3 lod0 = texture(emissionTexture, uv).rgb * floatBlendInputScale;
vec3 lod1 = texture(lodTexture, uv, 1.0).rgb;
vec3 lod2 = texture(lodTexture, uv, 2.0).rgb;
vec3 lod3 = texture(lodTexture, uv, 3.0).rgb;
vec3 lod4 = texture(lodTexture, uv, 4.0).rgb;
vec3 lod5 = texture(lodTexture, uv, 5.0).rgb;
float terrainDepth = -1.0;
float depthSample = depthFromTexture(depthTexture, uv);
if(depthSample < 1.0 && depthSample > 0.0){
vec3 cameraSpaceRay = normalize(eyeDir);
cameraSpaceRay /= cameraSpaceRay.z;
cameraSpaceRay *= linearizeDepth(depthSample);
terrainDepth = max(0.0, length(cameraSpaceRay));
}
vec3 rayDir = normalize(worldRay);
float dispersionPerPixel = getDistanceFalloff(terrainDepth, rayDir, fogOpacity);
float lodFactor0 = mix(minDisperse[0], maxDisperse[0], dispersionPerPixel);
float lodFactor1 = mix(minDisperse[1], maxDisperse[1], dispersionPerPixel);
float lodFactor2 = mix(minDisperse[2], maxDisperse[2], dispersionPerPixel);
float lodFactor3 = mix(minDisperse[3], maxDisperse[3], dispersionPerPixel);
float lodFactor4 = mix(minDisperse[4], maxDisperse[4], dispersionPerPixel);
float lodFactor5 = mix(minDisperse[5], maxDisperse[5], dispersionPerPixel);
vec3 emission = lodFactor0 * lod0;
emission += lodFactor1 * lod1;
emission += lodFactor2 * lod2;
emission += lodFactor3 * lod3;
emission += lodFactor4 * lod4;
emission += lodFactor5 * lod5;
emission = glowLod == 0 ? lodFactor0 * lod0 : glowLod == 1 ? lodFactor1 * lod1 : glowLod == 2 ? lodFactor2 * lod2 : glowLod == 3 ? lodFactor3 * lod3 : glowLod == 4 ? lodFactor4 * lod4 : glowLod == 5 ? lodFactor5 * lod5 : emission;
fragEmission.rgb = emission.rgb * floatBlendOutputScale + ditherNoise(vec4(emission, color.a));
emission = tonemapKhronosNeutral(emission);
fragColor = delinearizeGamma(vec4(color.rgb + emission, color.w));`),d):(x.main.add(l`vec4 color = texture(colorTexture, uv);
color = vec4(linearizeGamma(color.rgb), color.a);
vec3 emission = texture(emissionTexture, uv).rgb * floatBlendInputScale;
emission = tonemapKhronosNeutral(emission);
fragColor = delinearizeGamma(vec4(color.rgb + emission, color.w));`),d)}class v{constructor(o,r){this.preset=o,e(o,r)}}function h(e,o,r=1){return[e[0]*(1-r)+o[0]*r,e[1]*(1-r)+o[1]*r,e[2]*(1-r)+o[2]*r,e[3]*(1-r)+o[3]*r,e[4]*(1-r)+o[4]*r,e[5]*(1-r)+o[5]*r]}const b=Object.freeze(Object.defineProperty({__proto__:null,GlowCompositionPassParameters:x,GlowLodFactors:v,build:w,mixPreset:h},Symbol.toStringTag,{value:"Module"}));export{v as G,x as a,b,w as c,h as m};
