/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","./_rollupPluginBabelHelpers","../views/3d/environment/SimpleAtmosphereTechniqueConfiguration","../views/3d/webgl-engine/core/shaderLibrary/Transform.glsl","../views/3d/webgl-engine/core/shaderModules/Float2Uniform","../views/3d/webgl-engine/core/shaderModules/Float3PassUniform","../views/3d/webgl-engine/core/shaderModules/Float3Uniform","../views/3d/webgl-engine/core/shaderModules/FloatUniform","../views/3d/webgl-engine/core/shaderModules/interfaces","../views/3d/webgl-engine/core/shaderModules/Matrix4PassUniform","../views/3d/webgl-engine/core/shaderModules/Matrix4Uniform","../views/3d/webgl-engine/core/shaderModules/ShaderBuilder","../views/3d/webgl-engine/core/shaderModules/Texture2DPassUniform","../views/3d/webgl-engine/lib/VertexAttribute"],(function(e,o,i,r,n,t,l,s,a,d,g,c,m,f){"use strict";let u=function(e){function i(){return e.apply(this,arguments)||this}return o._inheritsLoose(i,e),i}(a.NoParameters);function p(e){const o=new c.ShaderBuilder,{vertex:u,fragment:p}=o;if(e.geometry===i.SimpleAtmosphereGeometry.Underground)o.attributes.add(f.VertexAttribute.POSITION,"vec2"),o.varyings.add("color","vec4"),u.uniforms.add([new t.Float3PassUniform("lightingMainDirection",((e,o)=>o.lighting.lightingMainDirection)),new l.Float3Uniform("cameraPosition"),new s.FloatUniform("undergroundFadeAlpha")]),u.code.add(a.glsl`void main(void) {
float ndotl = dot(normalize(cameraPosition), lightingMainDirection);
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);
}`),p.code.add(a.glsl`void main() {
gl_FragColor = color;
}`);else{o.include(r.Transform),o.attributes.add(f.VertexAttribute.POSITION,"vec3"),o.varyings.add("vtc","vec2"),o.varyings.add("falloff","float");const c=e.geometry===i.SimpleAtmosphereGeometry.Cylinder;u.uniforms.add([new d.Matrix4PassUniform("proj",((e,o)=>o.camera.projectionMatrix)),new g.Matrix4Uniform("view"),new t.Float3PassUniform("lightingMainDirection",((e,o)=>o.lighting.lightingMainDirection))]),c||(o.varyings.add("innerFactor","float"),u.uniforms.add(new l.Float3Uniform("silCircleCenter")),u.uniforms.add(new l.Float3Uniform("silCircleV1")),u.uniforms.add(new l.Float3Uniform("silCircleV2")),u.uniforms.add(new n.Float2Uniform("texV")),u.uniforms.add(new s.FloatUniform("innerScale")));const h=6.2831853,v=1/128;u.code.add(a.glsl`
		void main(void) {
      ${c?a.glsl`
      vec3 pos = position;
      float ndotl = lightingMainDirection.z;
      vtc = vec2(0.0, position.z + 0.05);`:a.glsl`
      innerFactor = clamp(-position.z, 0.0, 1.0);
      float scale = position.y * (1.0 + innerFactor * innerScale);
      float phi = position.x * ${a.glsl.float(h*v)} + 1.0;
      vec3 pos =  (silCircleCenter + sin(phi) * silCircleV1 + cos(phi) * silCircleV2) * scale;
      float ndotl = dot(normalize(position.y > 0.0 ? pos: silCircleCenter), lightingMainDirection);
      vtc.x = position.x  * ${a.glsl.float(v)};
      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
    }
	  `),p.uniforms.add(new m.Texture2DPassUniform("tex",(e=>e.texture))),c||p.uniforms.add(new s.FloatUniform("altitudeFade")),p.code.add(a.glsl`
		void main() {
			vec4 atmosphereColor = texture2D(tex, vtc) * falloff;
      ${c?a.glsl`gl_FragColor = atmosphereColor;`:a.glsl`
			vec4 innerColor = vec4(atmosphereColor.rgb, 1.0 - altitudeFade);
			gl_FragColor = mix(atmosphereColor, innerColor, smoothstep(0.0, 1.0, innerFactor));
      `}
    }`)}return o}const h=Object.freeze(Object.defineProperty({__proto__:null,SimpleAtmospherePassParameters:u,build:p},Symbol.toStringTag,{value:"Module"}));e.SimpleAtmosphere=h,e.SimpleAtmospherePassParameters=u,e.build=p}));
