@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 4.26 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.32/esri/copyright.txt for details.
*/
import{_ as e}from"../../../../../chunks/tslib.es6.js";import{clamp as r}from"../../../../../core/mathUtils.js";import{disposeMaybe as s}from"../../../../../core/maybe.js";import{watch as t}from"../../../../../core/reactiveUtils.js";import{Milliseconds as i}from"../../../../../core/time.js";import{property as o}from"../../../../../core/accessorSupport/decorators/property.js";import"../../../../../core/has.js";import"../../../../../core/Logger.js";import"../../../../../core/RandomLCG.js";import{subclass as a}from"../../../../../core/accessorSupport/decorators/subclass.js";import{set as m}from"../../../../../core/libs/gl-matrix-2/math/vec2.js";import{InternalRenderCategory as n}from"../../../webgl.js";import{ColorFormat as p}from"../../../webgl/formats.js";import c from"../../../webgl/RenderNode.js";import{distanceFadeEnd as h,distanceFadeStart as u}from"../../core/shaderLibrary/shading/ScreenSpaceConstants.js";import{SSAOBlurTechnique as l}from"./SSAOBlurTechnique.js";import{noiseData as d}from"./SSAONoiseData.js";import{SSAOPassParameters as f,BlurDrawParameters as b}from"./SSAOParameters.js";import{SSAOTechnique as w}from"./SSAOTechnique.js";import{RenderRequestType as T}from"../../lib/basicInterfaces.js";import{g as S}from"../../../../../chunks/SSAO.glsl.js";import{TextureWrapMode as _,PixelFormat as P,DepthStencilAttachment as j,FramebufferBit as g}from"../../../../webgl/enums.js";import{Texture as x}from"../../../../webgl/Texture.js";import{TextureDescriptor as q}from"../../../../webgl/TextureDescriptor.js";const A=2;let E=class extends c{constructor(e){super(e),this.consumes={required:["normals"]},this.produces=n.SSAO,this.isEnabled=()=>!1,this._enableTime=i(0),this._passParameters=new f,this._drawParameters=new b}initialize(){const e=Uint8Array.from(atob(d),(e=>e.charCodeAt(0))),r=new q;r.wrapMode=_.CLAMP_TO_EDGE,r.pixelFormat=P.RGB,r.wrapMode=_.REPEAT,r.hasMipmap=!0,r.width=32,r.height=32,this._passParameters.noiseTexture=new x(this.renderingContext,r,e),this.techniques.precompile(w),this.techniques.precompile(l),this.addHandles(t((()=>this.isEnabled()),(()=>this._enableTime=i(0))))}destroy(){this._passParameters.noiseTexture=s(this._passParameters.noiseTexture)}render(e){const s=this.bindParameters,t=e.find((({name:e})=>"normals"===e)),o=t?.getTexture(),a=t?.getTexture(j),c=this.fboCache,d=s.camera,f=d.fullViewport[2],b=d.fullViewport[3],_=Math.round(f/A),P=Math.round(b/A),x=this.techniques.get(w),q=this.techniques.get(l);if(!x.compiled||!q.compiled)return this._enableTime=i(performance.now()),this.requestRender(T.UPDATE),c.acquire(_,P,n.SSAO,p.RED);0===this._enableTime&&(this._enableTime=i(performance.now()));const E=this.renderingContext,y=this.view.qualitySettings.fadeDuration,R=d.relativeElevation,v=r((h-R)/(h-u),0,1),C=y>0?Math.min(y,performance.now()-this._enableTime)/y:1,D=C*v;this._passParameters.normalTexture=o,this._passParameters.depthTexture=a,this._passParameters.projScale=1/d.computeScreenPixelSizeAtDist(1),this._passParameters.intensity=4*O/S(d)**6*D;const V=c.acquire(f,b,"ssao input",p.RG);E.bindFramebuffer(V.fbo),E.setViewport(0,0,f,b),E.bindTechnique(x,s,this._passParameters,this._drawParameters),E.screen.draw();const M=c.acquire(_,P,"ssao blur",p.RED);E.bindFramebuffer(M.fbo),this._drawParameters.colorTexture=V.getTexture(),m(this._drawParameters.blurSize,0,A/b),E.bindTechnique(q,s,this._passParameters,this._drawParameters),E.setViewport(0,0,_,P),E.screen.draw(),V.release();const L=c.acquire(_,P,n.SSAO,p.RED);return E.bindFramebuffer(L.fbo),E.setViewport(0,0,f,b),E.setClearColor(1,1,1,0),E.clear(g.COLOR),this._drawParameters.colorTexture=M.getTexture(),m(this._drawParameters.blurSize,A/f,0),E.bindTechnique(q,s,this._passParameters,this._drawParameters),E.setViewport(0,0,_,P),E.screen.draw(),E.setViewport4fv(d.fullViewport),M.release(),C<1&&this.requestRender(T.UPDATE),L}};e([o()],E.prototype,"consumes",void 0),e([o()],E.prototype,"produces",void 0),e([o({constructOnly:!0})],E.prototype,"isEnabled",void 0),E=e([a("esri.views.3d.webgl-engine.effects.ssao.SSAO")],E);const O=.5;export{E as SSAO,A as blurSizePixels};