@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 4.15 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import{__decorate as e}from"tslib";import{lerp as t}from"../../../core/mathUtils.js";import{disposeMaybe as r}from"../../../core/maybe.js";import{watch as i,syncAndInitial as s,initial 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{set as m,length as h}from"../../../core/libs/gl-matrix-2/math/vec3.js";import{ZEROS as c}from"../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{earth as p}from"../../../geometry/support/Ellipsoid.js";import{InternalRenderCategory as d}from"../webgl.js";import{computeInnerAltitudeFade as u,innerAtmosphereDepth as l}from"./atmosphereUtils.js";import{ChapmanAtmospherePassParameters as f,ChapmanAtmosphereTechnique as g}from"./ChapmanAtmosphereTechnique.js";import{ChapmanAtmosphereTechniqueConfiguration as b}from"./ChapmanAtmosphereTechniqueConfiguration.js";import{OpaqueEnvironment as _}from"../webgl-engine/effects/OpaqueEnvironment.js";import{createQuadVAO as w}from"../webgl-engine/lib/glUtil3D.js";import{applyTextureResizeModulo as P}from"../webgl-engine/lib/textureUtils.js";import{A as v}from"../../../chunks/AtmosphereCompositing.glsl.js";import{AtmosphereCompositingTechnique as j}from"../webgl-engine/shaders/AtmosphereCompositingTechnique.js";import{DepthStencilAttachment as A,PrimitiveType as q}from"../../webgl/enums.js";import x from"../../../webscene/background/ColorBackground.js";let T=class extends _{constructor(){super(...arguments),this._compositingPassParameters=new v,this._vao=null,this._passParameters=new f,this._configuration=new b}initialize(){this.addHandles([i(()=>this.view.environment.background,e=>{const t=e instanceof x?e.color.toUnitRGBA():c;m(this._passParameters.backgroundColor,t[0]*t[3],t[1]*t[3],t[2]*t[3])},s),i(()=>this.view.stage?.renderer?.highResolutionAtmosphere,e=>this._configuration.reduced=!e,s),i(()=>this.view.map.ground.undergroundColor,e=>{this._passParameters.undergroundColor=e?.toUnitRGBA()??c,this.requestRender(1)},o),i(()=>this.view.environment.atmosphereEnabled,e=>e?this._enable():this._disable(),s)])}destroy(){this._vao=r(this._vao)}precompile(){this.techniques.precompile(g,this._configuration),this.techniques.precompile(j)}render(e){const r=e.find(({name:e})=>e===d.OPAQUE_ENVIRONMENT);if(!this.bindParameters.mainDepth)return r;const i=this.renderingContext;this._vao??=w(i,1);const s=r.getAttachment(A);this._update();const o=this.techniques.get(g,this._configuration);if(!o.compiled)return this.requestRender(1),r;if(!this._configuration.reduced)return r.detachDepth(),i.bindFramebuffer(r.fbo),i.bindTechnique(o,this.bindParameters,this._passParameters),i.bindVAO(this._vao),i.drawArrays(q.TRIANGLE_STRIP,0,4),r.attachDepth(s),r;const a=this.techniques.get(j);if(!a.compiled)return this.requestRender(1),r;const n=i.getViewport(),m=this.bindParameters.camera,c=h(m.eye)-p.radius;let u;const l=p.atmosphereHeight;if(c<l){const e=Math.min(1,Math.max(0,c/l));u=t(.2,.3,e)}else{const e=Math.min(1,Math.max(0,(c-l)/(15*l)));u=t(.3,.6,e)}const f=this.renderingContext.parameters.maxTextureSize,b=P(Math.round(u*m.fullViewport[2]),f),_=P(Math.round(u*m.fullViewport[3]),f);i.setViewport(0,0,b,_);const v=this.fboCache.acquire(b,_,"chapman",5);return i.bindFramebuffer(v.fbo),i.clearFramebuffer([0,0,0,1],!0,!0),i.bindTechnique(o,this.bindParameters,this._passParameters),i.bindVAO(this._vao),i.drawArrays(q.TRIANGLE_STRIP,0,4),i.setViewport(n.x,n.y,n.width,n.height),this._compositingPassParameters.color=v.getTexture(),r.detachDepth(),i.bindFramebuffer(r.fbo),i.bindTechnique(a,this.bindParameters,this._compositingPassParameters),i.screen.draw(),r.attachDepth(s),v.release(),r}_update(){const e=this.view.basemapTerrain?.getLowerBoundRadius()??0;n(this._passParameters.radii,e,e+p.atmosphereHeight);const t=h(this.bindParameters.camera.eye);this._passParameters.altitudeFade=u(t-e),this._passParameters.innerFadeDistance=2*Math.sqrt((2*e-l)*l)}};T=e([a("esri.views.3d.environment.ChapmanAtmosphere")],T);export{T as ChapmanAtmosphere};