@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 3.54 kB
JavaScript
import e from"../../../core/Handles.js";import{clamp as t,lerp as s,smoothstep as i}from"../../../core/mathUtils.js";import{isNone as r}from"../../../core/maybe.js";import{watch as a}from"../../../core/reactiveUtils.js";import{s as o}from"../../../chunks/vec2.js";import{p as n}from"../../../chunks/vec3.js";import{s as h}from"../../../chunks/vec4.js";import{earth as d}from"../../../geometry/support/Ellipsoid.js";import{AtmosphereType as u}from"./AtmosphereType.js";import{atmosphereHeight as p,innerAtmosphereDepth as m,computeInnerAltitudeFade as l}from"./atmosphereUtils.js";import{ChapmanAtmospherePassParameters as _,ChapmanAtmosphereTechnique as c}from"./ChapmanAtmosphereTechnique.js";import{ChapmanAtmosphereTechniqueConfiguration as f}from"./ChapmanAtmosphereTechniqueConfiguration.js";import{Pos2Tex as T}from"../webgl-engine/lib/DefaultVertexBufferLayouts.js";import{createQuadVAO as v}from"../webgl-engine/lib/glUtil3D.js";import{PrimitiveType as b}from"../../webgl/enums.js";class R{constructor(t,s){this._view=t,this.type=u.Realistic,this._handles=new e,this._passParameters=new _,this._rootTileElevationMin=NaN,this._lowerBoundEarthRadius=d.radius,this._fadeHaze=0,this._updateRadius(d.radius);const i=s.renderContext.rctx;this._updateRootTileElevationBounds(),this._handles.add([a((()=>this._view.basemapTerrain.rootTileElevationBounds),(()=>this._updateRootTileElevationBounds())),a((()=>this._view.basemapTerrain.visibleElevationBounds),(()=>this._updateVisibleElevationBounds()))]);const r=new f;r.haze=!1,this._atmosphereTechnique=s.techniqueRepository.acquire(c,r),r.haze=!0,this._atmosphereHazeTechnique=s.techniqueRepository.acquire(c,r),this._vao=v(i,T)}destroy(){this._atmosphereTechnique.release(),this._atmosphereHazeTechnique.release(),this._vao.dispose(),this._handles.destroy()}render(e){this._render(e,this._atmosphereTechnique,e.offscreenRenderingHelper.depthTexture)}renderHaze(e,t){this._fadeHaze=t,this._render(e,this._atmosphereHazeTechnique,e.offscreenRenderingHelper.linearDepthTexture)}_render(e,t,s){if(r(s))return;this._update(e.bindParameters.camera),this._passParameters.depthTex=s;const i=e.rctx.bindTechnique(t,this._passParameters,e.bindParameters);e.offscreenRenderingHelper.renderDepthDetached((()=>this._renderCommon(i,e)))}_renderCommon(e,t){r(this._vao)||(t.rctx.bindVAO(this._vao),e.assertCompatibleVertexAttributeLocations(this._vao),t.rctx.drawArrays(b.TRIANGLE_STRIP,0,4))}_adjustRadiusForTesselation(e){return e*Math.cos(Math.PI/16/16)}_updateRootTileElevationBounds(){const e=this._view.basemapTerrain.rootTileElevationBounds.min;e!==this._rootTileElevationMin&&(this._rootTileElevationMin=e,this._lowerBoundEarthRadius=d.radius,this._updateVisibleElevationBounds())}_updateVisibleElevationBounds(){const e=this._adjustRadiusForTesselation(d.radius+this._view.basemapTerrain.visibleElevationBounds.min);e<this._lowerBoundEarthRadius&&this._updateRadius(e)}_updateRadius(e){this._lowerBoundEarthRadius=e,o(this._passParameters.radii,e,e+p),this._passParameters.innerFadeDistance=2*Math.sqrt((2*e-m)*m)}_update(e){if(r(e))return;const a=n(e.eye),o=Math.sqrt(a),u=a-this._passParameters.radii[1]*this._passParameters.radii[1],m=t((o-this._passParameters.radii[0])/p,0,1);h(this._passParameters.heightParameters,o,a,u,m),this._passParameters.altitudeFade=l(o-this._lowerBoundEarthRadius),this._passParameters.hazeStrength=s(s(.6,1,i(9500,10500,o-d.radius)),1,this._fadeHaze)}static isSupported(e){return e.renderContext.rctx.capabilities.depthTexture}}export{R as ChapmanAtmosphere};