/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../../chunks/_rollupPluginBabelHelpers","../../../chunks/tslib.es6","../../../core/Accessor","../../../core/mathUtils","../../../core/maybe","../../../core/accessorSupport/decorators/property","../../../core/arrayUtils","../../../core/has","../../../core/accessorSupport/ensureType","../../../core/accessorSupport/decorators/subclass","../../../chunks/vec3","../../../chunks/vec3f32","../../../geometry/projectionEllipsoid","./atmosphereUtils","./FogTechnique","./weather","../webgl-engine/core/shaderModules/interfaces","../webgl-engine/lib/DefaultVertexBufferLayouts","../webgl-engine/lib/glUtil3D","../../webgl/enums"],(function(e,t,i,o,r,s,n,a,h,c,u,g,_,d,f,l,p,m,y,F,T){"use strict";e.Fog=function(e){function i(t){var i;(i=e.call(this,t)||this)._fogColor=_.create(),i._fogColorAtNight=_.create(),i._cameraDirection=_.create(),i._foggyFadeStart=.95,i._foggyFadeEnd=1,i._hazeFadeStart=.7,i._hazeFadeEnd=1,i._strength=4e-6;const o=t.context.renderContext.rctx;i._vao=F.createQuadVAO(o,y.Pos2Tex);const r=d.getReferenceEllipsoid(t.view.spatialReference);return i._planetRadius=r.radius,i._atmosphereRadius=r.radius+f.atmosphereHeight,i}t._inheritsLoose(i,e);var o=i.prototype;return o.destroy=function(){this._hazeFogTechnique=s.releaseMaybe(this._hazeFogTechnique),this._thickFogTechnique=s.releaseMaybe(this._thickFogTechnique),this._vao=s.disposeMaybe(this._vao)},o.when=function(){return Promise.resolve()},o.render=function(e,t,i){if(0===this.view.basemapTerrain.baseOpacity&&!t)return;if(this._update(e,t,i),this._fogAmount<=0)return;const o=t?this.thickFogTechnique:this.hazeFogTechnique;if(!o.compiled)return void this.context.requestRender();const r=e.offscreenRenderingHelper,s=e.rctx.bindTechnique(o,b,e.bindParameters);r.renderDepthDetached((()=>{s.bindTexture("depthTex",r.depthTexture),this._renderFog(o.program,e)}))},o._renderFog=function(e,t){if(s.isNone(this._vao))return!1;const i=t.rctx,o=t.bindParameters.camera;return e.setUniform3fv("cameraPosition",o.eye),e.setUniform1f("atmosphereC",this._atmosphereC),e.setUniform1f("fogStrength",this._strength),e.setUniform1f("fogAmount",this._fogAmount),e.setUniform3fv("fogColor",this._fogColor),i.bindVAO(this._vao),e.assertCompatibleVertexAttributeLocations(this._vao),i.drawArrays(T.PrimitiveType.TRIANGLE_STRIP,0,4),!0},o._update=function(e,t,i){const o=e.bindParameters.camera,s=t?.1:0;i?g.set(this._fogColor,.5,.5,.5):t?g.set(this._fogColor,1.5,1.5,1.5):g.set(this._fogColor,.24,.44,.8),g.scale(this._fogColorAtNight,this._fogColor,s),g.normalize(this._cameraDirection,o.eye);const n=Math.max(0,g.dot(this._cameraDirection,e.bindParameters.lighting.lightingMainDirection));g.lerp(this._fogColor,this._fogColorAtNight,this._fogColor,n);const a=g.length(o.eye),h=a*a;this._atmosphereC=h-this._atmosphereRadius*this._atmosphereRadius,this._fogAmount=t?1-r.smoothstep(this._foggyFadeStart*p.weatherHeightLimit,this._foggyFadeEnd*p.weatherHeightLimit,Math.abs(a-this._planetRadius)):1-r.smoothstep(this._hazeFadeStart*p.weatherHeightLimit,this._hazeFadeEnd*p.weatherHeightLimit,Math.abs(a-this._planetRadius))},i.isSupported=function(e){return e.capabilities.depthTexture},t._createClass(i,[{key:"_shaderTechniqueRepository",get:function(){return this.context.shaderTechniqueRepository}},{key:"strength",get:function(){return this._strength},set:function(e){this._strength=e}},{key:"thickFogTechnique",get:function(){if(s.isNone(this._thickFogTechnique)){const e=new l.FogTechniqueConfiguration;e.haze=!1,this._thickFogTechnique=this._shaderTechniqueRepository.acquire(l.FogTechnique,e)}return this._thickFogTechnique}},{key:"hazeFogTechnique",get:function(){if(s.isNone(this._hazeFogTechnique)){const e=new l.FogTechniqueConfiguration;e.haze=!0,this._hazeFogTechnique=this._shaderTechniqueRepository.acquire(l.FogTechnique,e)}return this._hazeFogTechnique}}]),i}(o),i.__decorate([n.property({constructOnly:!0})],e.Fog.prototype,"context",void 0),i.__decorate([n.property({constructOnly:!0})],e.Fog.prototype,"view",void 0),e.Fog=i.__decorate([u.subclass("esri.views.3d.environment.Fog")],e.Fog);const b=new m.NoParameters;Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
