UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

3 lines (2 loc) 3.86 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.19/LICENSE.txt */ import{__decorate as e}from"tslib";import{lerp as t,smoothstep as i}from"../../../../../core/mathUtils.js";import{disposeMaybe as r}from"../../../../../core/maybe.js";import{watch as s,syncAndInitial as o}from"../../../../../core/reactiveUtils.js";import{subclass as a}from"../../../../../core/accessorSupport/decorators.js";import{set as n}from"../../../../../core/libs/gl-matrix-2/math/vec2.js";import{length as m}from"../../../../../core/libs/gl-matrix-2/math/vec3.js";import{earth as h}from"../../../../../geometry/support/Ellipsoid.js";import{InternalRenderCategory as c}from"../../../webgl.js";import{TransparentEnvironment as d}from"../TransparentEnvironment.js";import{H as p}from"../../../../../chunks/HazeCompositing.glsl.js";import{HazeCompositingTechnique as u}from"./HazeCompositingTechnique.js";import{HazePassParameters as f,HazeTechnique as l}from"./HazeTechnique.js";import{HazeTechniqueConfiguration as _}from"./HazeTechniqueConfiguration.js";import{createQuadVAO as g}from"../../lib/glUtil3D.js";import{applyTextureResizeModulo as b}from"../../lib/textureUtils.js";import{DepthStencilAttachment as w,PrimitiveType as P}from"../../../../webgl/enums.js";let v=class extends d{constructor(e){super(e),this._compositingPassParameters=new p,this._passParameters=new f,this._hazeConfiguration=new _,this._oldAmount=1,this._newAmount=1,this._amount=this._newAmount;const t=e.view.stage.renderView.techniques;t.precompile(l,new _);const i=new _;i.reduced=!0,t.precompile(l,i),t.precompile(u)}initialize(){this.addHandles([s(()=>this.view.environment.atmosphereEnabled,e=>e?this._enable():this._disable(),o),s(()=>this.view.stage?.renderer.renderContext.bind.clouds.fadeFactor??1,e=>this._fade(e),o),s(()=>this.view.environment.weather.type,e=>this._newAmount="rainy"===e?0:1,o),s(()=>this.view.stage.renderer?.highResolutionAtmosphere,e=>this._hazeConfiguration.reduced=!e,o)])}_fade(e){e>=1?(this._amount=this._newAmount,this._oldAmount=this._newAmount):this._amount=e<=0?this._oldAmount:t(this._oldAmount,this._newAmount,e)}destroy(){this._vao=r(this._vao)}render(e){const i=e.find(({name:e})=>e===c.TRANSPARENT_ENVIRONMENT);if(!this.bindParameters.mainDepth)return i;const r=this.techniques.get(l,this._hazeConfiguration);if(!r.compiled)return i;const s=this.renderingContext,o=i.getAttachment(w);if(this._update(),!this._hazeConfiguration.reduced)return i.detachDepth(),s.bindFramebuffer(i.fbo),s.bindTechnique(r,this.bindParameters,this._passParameters),this._renderCommon(s),i.attachDepth(o),i;const a=this.techniques.get(u);if(!a.compiled)return i;const n=s.getViewport(),d=this.camera,p=m(d.eye)-h.radius;let f;const _=h.atmosphereHeight;if(p<_){const e=Math.min(1,Math.max(0,p/_));f=t(.4,.5,e)}else{const e=Math.min(1,Math.max(0,(p-_)/(15*_)));f=t(.5,1,e)}const g=this.renderingContext.parameters.maxTextureSize,P=b(Math.round(f*d.fullViewport[2]),g),v=b(Math.round(f*d.fullViewport[3]),g);s.setViewport(0,0,P,v);const A=this.fboCache.acquire(P,v,"haze",5);return s.bindFramebuffer(A.fbo),s.clearFramebuffer([0,0,0,1],!0,!0),s.bindTechnique(r,this.bindParameters,this._passParameters),this._renderCommon(s),s.setViewport(n.x,n.y,n.width,n.height),this._compositingPassParameters.color=A.getTexture(),i.detachDepth(),s.bindFramebuffer(i.fbo),s.bindTechnique(a,this.bindParameters,this._compositingPassParameters),s.screen.draw(),i.attachDepth(o),A.release(),i}_renderCommon(e){this._vao??=g(e,1),e.bindVAO(this._vao),e.drawArrays(P.TRIANGLE_STRIP,0,4)}_update(){const e=this.view.basemapTerrain?.getLowerBoundRadius()??0;n(this._passParameters.radii,e,e+h.atmosphereHeight);const r=m(this.bindParameters.camera.eye);this._passParameters.hazeStrength=t(t(.6,1,i(9500,10500,r-h.radius)),1,this._amount)}};v=e([a("esri.views.3d.webgl-engine.effects.haze.Haze")],v);export{v as Haze};