/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import{create as e}from"../core/libs/gl-matrix-2/factories/vec2f64.js";import{create as o}from"../core/libs/gl-matrix-2/factories/vec3f64.js";import{Transform as i}from"../views/3d/webgl-engine/core/shaderLibrary/Transform.glsl.js";import{addMainLightDirection as r}from"../views/3d/webgl-engine/core/shaderLibrary/shading/MainLighting.glsl.js";import{Float2PassUniform as t}from"../views/3d/webgl-engine/core/shaderModules/Float2PassUniform.js";import{Float3BindUniform as s}from"../views/3d/webgl-engine/core/shaderModules/Float3BindUniform.js";import{Float3PassUniform as n}from"../views/3d/webgl-engine/core/shaderModules/Float3PassUniform.js";import{FloatPassUniform as a}from"../views/3d/webgl-engine/core/shaderModules/FloatPassUniform.js";import{glsl as l}from"../views/3d/webgl-engine/core/shaderModules/glsl.js";import{Matrix4BindUniform as d}from"../views/3d/webgl-engine/core/shaderModules/Matrix4BindUniform.js";import{Texture2DPassUniform as c}from"../views/3d/webgl-engine/core/shaderModules/Texture2DPassUniform.js";import{NoParameters as m}from"../views/webgl/NoParameters.js";import{ShaderBuilder as f}from"../views/webgl/ShaderBuilder.js";class g extends m{constructor(){super(...arguments),this.texV=e(),this.altitudeFade=0,this.innerScale=0,this.undergroundFadeAlpha=0,this.silhouette=new p}}class p{constructor(){this.center=o(),this.v1=o(),this.v2=o()}}function u(e){const o=new f,{vertex:m,fragment:g}=o;if(r(m),2===e.geometry)o.attributes.add("position","vec2"),o.varyings.add("color","vec4"),m.uniforms.add(new s("cameraPosition",e=>e.camera.eye),new a("undergroundFadeAlpha",e=>e.undergroundFadeAlpha)),m.main.add(l`float ndotl = dot(normalize(cameraPosition), mainLightDirection);
float lighting = max(0.0, smoothstep(-1.0, 0.8, 2.0 * ndotl));
color = vec4(vec3(lighting), undergroundFadeAlpha);
gl_Position = vec4(position.xy, 1.0, 1.0);`),g.main.add(l`fragColor = color;`);else{o.include(i),o.attributes.add("position","vec3"),o.varyings.add("vtc","vec2"),o.varyings.add("falloff","float");const r=1===e.geometry;m.uniforms.add(new d("proj",e=>e.camera.projectionMatrix),new d("view",e=>e.camera.viewMatrix)),r||(o.varyings.add("innerFactor","float"),m.uniforms.add(new n("silCircleCenter",e=>e.silhouette.center)),m.uniforms.add(new n("silCircleV1",e=>e.silhouette.v1)),m.uniforms.add(new n("silCircleV2",e=>e.silhouette.v2)),m.uniforms.add(new t("texV",e=>e.texV)),m.uniforms.add(new a("innerScale",e=>e.innerScale)));const s=6.2831853,f=1/128;m.main.add(l`
      ${r?l`
      vec3 pos = position;
      float ndotl = mainLightDirection.z;
      vtc = vec2(0.0, position.z + 0.05);`:l`
      innerFactor = clamp(-position.z, 0.0, 1.0);
      float scale = position.y * (1.0 + innerFactor * innerScale);
      float phi = position.x * ${l.float(s*f)} + 1.0;
      vec3 pos =  (silCircleCenter + sin(phi) * silCircleV1 + cos(phi) * silCircleV2) * scale;
      float ndotl = dot(normalize(position.y > 0.0 ? pos: silCircleCenter), mainLightDirection);
      vtc.x = position.x  * ${l.float(f)};
      vtc.y = texV.x * (1.0 - position.z) + texV.y * position.z;
      `}
      falloff = max(0.0, smoothstep(-1.0, 0.8, 2.0 * ndotl));

		  gl_Position = transformPosition(proj, view, pos);
		  gl_Position.z = gl_Position.w; // project atmosphere onto the far plane
	  `),g.uniforms.add(new c("tex",e=>e.texture)),r||g.uniforms.add(new a("altitudeFade",e=>e.altitudeFade)),g.main.add(l`
			vec4 atmosphereColor = texture(tex, vtc) * falloff;
      ${r?l`fragColor = atmosphereColor;`:l`
			vec4 innerColor = vec4(atmosphereColor.rgb, 1.0 - altitudeFade);
			fragColor = mix(atmosphereColor, innerColor, smoothstep(0.0, 1.0, innerFactor));`}`)}return o}const h=Object.freeze(Object.defineProperty({__proto__:null,SilhouetteCircle:p,SimpleAtmospherePassParameters:g,build:u},Symbol.toStringTag,{value:"Module"}));export{g as S,h as a,p as b,u as c};
