@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 7.24 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.19/LICENSE.txt */
import{__decorate as t}from"tslib";import{lerp as e}from"../../../../../core/mathUtils.js";import{watch as i,syncAndInitial as s}from"../../../../../core/reactiveUtils.js";import{property as r,subclass as o}from"../../../../../core/accessorSupport/decorators.js";import{length as a}from"../../../../../core/libs/gl-matrix-2/math/vec3.js";import{ZEROS as n}from"../../../../../core/libs/gl-matrix-2/factories/vec4f32.js";import{getReferenceEllipsoid as h}from"../../../../../geometry/ellipsoidUtils.js";import{InternalRenderCategory as c}from"../../../webgl.js";import{TransparentEnvironment as m}from"../TransparentEnvironment.js";import{G as l}from"../../../../../chunks/GlowBlur.glsl.js";import{GlowBlurTechnique as p}from"./GlowBlurTechnique.js";import{GlowBlurTechniqueConfiguration as u}from"./GlowBlurTechniqueConfiguration.js";import{G as g,a as _,m as d}from"../../../../../chunks/GlowComposition.glsl.js";import{GlowCompositionTechnique as f}from"./GlowCompositionTechnique.js";import{GlowCompositionTechniqueConfiguration as w}from"./GlowCompositionTechniqueConfiguration.js";import{ColorAttachment1 as b,DepthStencilAttachment as P}from"../../../../webgl/enums.js";let T=class extends m{constructor(t){super(t),this.consumes={required:[c.TRANSPARENT_ENVIRONMENT,"emissive"]},this.produces=c.TRANSPARENT_ENVIRONMENT,this._blurHorizontalConfiguration=new u,this._blurVerticalConfiguration=new u,this._compositionConfiguration=new w,this._compositionParameters=new g,this._blurParameters=new l,this._blurScalePerLod=3.06,this._logicalBlurRadius=.0037,this._mode=0,this._intensity=.5,this._scatteringFactors={realistic:new _([.8,.12,.05,.02,.01,0]),maximumFog:new _([0,.27,.6,1.05,1.58,2.1],!1),cartographicMin:new _([.4,.18,.25,.12,.05,0],!1),cartographicDefault:new _([1.17,1.08,.78,.4,.26,.11],!1),cartographicMax:new _([3.59,3.9,2.46,1.4,.93,.44],!1)},this._glowResults=new Array;const e=h(t.view.spatialReference);this._atmosphereRadius=e.radius+e.atmosphereHeight;t.view.stage.renderView.techniques.precompile(f,this._compositionConfiguration),this._compositionParameters.minDisperse=new _([.8,.12,.05,.02,.01,0])}initialize(){this.addHandles([i(()=>this._updateFogParameters(),()=>{},s),i(()=>this._updateParameters(),()=>{},s)])}_updateParameters(){const t=this.view.environment.lighting.glow;this._mode=null==t?this.view.environment.atmosphereEnabled?0:2:1,t&&(this._intensity=t.intensity),this._compositionParameters.minDisperse&&(this._compositionParameters.minDisperse.presets=this.getPreset(this._mode)),this.precompile(),this.requestRender(1)}_updateFogParameters(){const t=this.view.environment.weather;"sunny"===t.type||"cloudy"===t.type?this._compositionParameters.distanceModifier=0:this._compositionParameters.distanceModifier="foggy"===t.type?e(3e-5,.005,t.fogStrength**3):e(4e-6,2e-4,(t.precipitation??0)**3),this._compositionParameters.maxDisperse=this._scatteringFactors.maximumFog,this.requestRender(1)}precompile(){this.techniques.precompile(p,this._blurHorizontalConfiguration),this._blurVerticalConfiguration.glowStage=1,this.techniques.precompile(p,this._blurVerticalConfiguration),this._compositionConfiguration.blurEnabled=!0,this.techniques.precompile(f,this._compositionConfiguration),this._compositionConfiguration.blurEnabled=!1,this.techniques.precompile(f,this._compositionConfiguration)}render(t){const e=t.find(({name:t})=>t===c.TRANSPARENT_ENVIRONMENT),i=e.getAttachment(b);if(!i?.attachment)return e;const s=2!==this._mode;this._compositionConfiguration.blurEnabled=s;const r=e.getAttachment(P);if(!s){const t=this.techniques.get(f,this._compositionConfiguration);if(!t.compiled)return this.requestRender(1),e;const s=e.getTexture(),o=this.fboCache,{fullWidth:a,fullHeight:n}=this.bindParameters.camera,h=this.renderingContext,c=o.acquire(s.descriptor.width,s.descriptor.height,this.produces);return this._prepareFBO(c,a,n),this._compositionParameters.color=s,this._compositionParameters.emission=i.attachment,h.bindTechnique(t,this.bindParameters,this._compositionParameters),h.screen.draw(),c.attachDepth(r),c.attachColor(i,b),c}const o=this.techniques.get(p,this._blurHorizontalConfiguration),n=this.techniques.get(p,this._blurVerticalConfiguration),h=this.techniques.get(f,this._compositionConfiguration);if(!o.compiled||!n.compiled||!h.compiled)return this.requestRender(1),e;const m=e.getTexture(),l=this.fboCache,{fullWidth:u,fullHeight:g}=this.bindParameters.camera,_=this.renderingContext;let d=i.attachment,w=Math.ceil(u/2),T=Math.ceil(g/2);const C=5;this._blurParameters.blurRadius=this._logicalBlurRadius;for(let a=0;a<C;a++){const t=l.acquire(w,T,"glow horizontal",8);this._blurParameters.emissionsToDownsample=d,this._prepareFBO(t,w,T),_.bindTechnique(o,this.bindParameters,this._blurParameters),_.screen.draw();const e=l.acquire(w,T,"glow vertical",8);this._blurParameters.emissionsToDownsample=t.getTexture(),this._prepareFBO(e,w,T),_.bindTechnique(n,this.bindParameters,this._blurParameters),_.screen.draw(),t.release(),this._glowResults[a]=e,w=Math.ceil(w/2),T=Math.ceil(T/2),d=this._glowResults[a].getTexture(),this._blurParameters.blurRadius*=this._blurScalePerLod}const R=this.bindParameters.camera,q=a(R.eye);this._compositionParameters.atmosphereC=q**2-this._atmosphereRadius**2,this._compositionParameters.color=m,this._compositionParameters.emission=i.attachment,this._compositionParameters.lodTexture0=this._glowResults[0].getTexture(),this._compositionParameters.lodTexture1=this._glowResults[1].getTexture(),this._compositionParameters.lodTexture2=this._glowResults[2].getTexture(),this._compositionParameters.lodTexture3=this._glowResults[3].getTexture(),this._compositionParameters.lodTexture4=this._glowResults[4].getTexture();const x=l.acquire(m.descriptor.width,m.descriptor.height,this.produces);return x.acquireColor(b,8,"emissive glow"),this._prepareFBO(x,u,g,!0),_.bindTechnique(h,this.bindParameters,this._compositionParameters),_.screen.draw(),this._glowResults.forEach(t=>t.release()),x.attachDepth(r),x}getPreset(t){return 0===t?this._scatteringFactors.realistic.presets:this._intensity<=.5?d(this._scatteringFactors.cartographicMin.presets,this._scatteringFactors.cartographicDefault.presets,2*this._intensity):d(this._scatteringFactors.cartographicDefault.presets,this._scatteringFactors.cartographicMax.presets,2*(this._intensity-.5))}_prepareFBO(t,e,i,s=!1){const r=this.renderingContext;r.bindFramebuffer(t.fbo),r.setViewport(0,0,e,i),r.setClearColor(0,0,0,0),r.clear(16384),s&&r.clearBuffer(1,n)}get test(){return{compositionParameters:this._compositionParameters,blurParameters:this._blurParameters,setBlurLodCombination:t=>{this._compositionParameters.dispersionWeight=t},getPresets:this.getPreset(this._mode),setMinDisperse:(t,e)=>{0===this._mode?this._scatteringFactors.realistic.presets[t]=e:(this._scatteringFactors.cartographicMin.presets[t]=e,this._scatteringFactors.cartographicMax.presets[t]=e)},toggleTonemapping:t=>{this._compositionConfiguration.tonemappingEnabled=t,this.requestRender(1)}}}};t([r()],T.prototype,"consumes",void 0),t([r()],T.prototype,"produces",void 0),T=t([o("esri.views.3d.webgl-engine.effects.glow.GlowRenderNode")],T);export{T as GlowRenderNode};