UNPKG

@babylonjs/viewer

Version:

The Babylon Viewer aims to simplify a specific but common Babylon.js use case: loading, viewing, and interacting with a 3D model.

1 lines 64.5 kB
import{b1 as e,O as s,M as t,y as i,c6 as a,c5 as r,aA as n,C as o,m as h,be as l,c as d,bd as u,V as _,aP as c,bc as g,z as m,D as x,l as p,q as f,aw as T,s as b,H as P,a as R,aD as E,aH as S,aY as w}from"./index-BPURObVq.esm.min.js";import{P as v}from"./proceduralTexture.pure-Cev_FPRk.esm.min.js";import{G as M,R as y}from"./geometryBufferRenderer.pure-BG473DMM.esm.min.js";import{a as D,P as O}from"./postProcessRenderEffect-BTQhrmYp.esm.min.js";import{R as A,I as B}from"./iblCdfGenerator-Caa9m9di.esm.min.js";import{M as G}from"./material.detailMapConfiguration-FEC73qwc.esm.min.js";import{P as C}from"./pbrBaseMaterial.pure-DmNe0cGL.esm.min.js";import{S as I}from"./standardMaterial.pure-BRp0YAN-.esm.min.js";import{OpenPBRMaterial as V}from"./openpbrMaterial.pure-BTbF5aqI.esm.min.js";import"./postProcessRenderPipelineManager-Im9ZJXSn.esm.min.js";import"./cubeTexture.pure-CFZf4s_Z.esm.min.js";import"./abstractEngine.cubeTexture.pure-DReMqode.esm.min.js";import"./textureLoaderManager-CGf6Ha4H.esm.min.js";import"./brdfTextureTools-CdNQgSAC.esm.min.js";import"./prepass.defines-DBIG3K_p.esm.min.js";class N{getVoxelGrid(){return this._engine.isWebGPU?this._voxelGrid:this._triPlanarVoxelization?this._combinedVoxelGridPT:this._voxelGridZaxis}getRT(){return this._engine.isWebGPU?this._voxelGridRT:this._triPlanarVoxelization?this._combinedVoxelGridPT:this._voxelGridZaxis}get triPlanarVoxelization(){return this._triPlanarVoxelization}set triPlanarVoxelization(e){this._engine.isWebGPU?this._triPlanarVoxelization=!0:this._triPlanarVoxelization!==e&&(this._triPlanarVoxelization=e,this._disposeVoxelTextures(),this._createTextures())}setWorldScaleMatrix(e){this._invWorldScaleMatrix=e}isVoxelizationInProgress(){return this._voxelizationInProgress}get voxelResolutionExp(){return this._voxelResolutionExp}set voxelResolutionExp(e){this._voxelResolutionExp===e&&this._voxelGridZaxis||(this._voxelResolutionExp=Math.round(Math.min(Math.max(e,3),9)),this._voxelResolution=Math.pow(2,this._voxelResolutionExp),this._disposeVoxelTextures(),this._createTextures())}constructor(n,o,h=6,l=!0){this._voxelMrtsXaxis=[],this._voxelMrtsYaxis=[],this._voxelMrtsZaxis=[],this._voxelClearColor=new e(0,0,0,1),this.onVoxelizationCompleteObservable=new s,this._renderTargets=[],this._gsVoxelMaterialCache=new Map,this._triPlanarVoxelization=!0,this._voxelizationInProgress=!1,this._sortSettleWaitFrames=0,this._invWorldScaleMatrix=t.Identity(),this._voxelResolution=64,this._voxelResolutionExp=6,this._copyMipLayer=0,this._mipArray=[],this._scene=n,this._engine=n.getEngine(),this._triPlanarVoxelization=this._engine.isWebGPU||l,this._engine.getCaps().drawBuffersExtension||i.Error("Can't do voxel rendering without the draw buffers extension.");const d=this._engine.isWebGPU,u=this._engine.getCaps().maxDrawBuffers||0,_=Math.min(u,16);this._maxDrawBuffers=_>=1?1<<Math.floor(Math.log2(_)):0,this._copyMipEffectRenderer=new a(this._engine),this._copyMipEffectWrapper=new r({engine:this._engine,fragmentShader:"copyTexture3DLayerToTexture",useShaderStore:!0,uniformNames:["layerNum"],samplerNames:["textureSampler"],shaderLanguage:d?1:0,extraInitializationsAsync:async()=>{d?await import("./copyTexture3DLayerToTexture.fragment-BJpA-3kr.esm.min.js"):await import("./copyTexture3DLayerToTexture.fragment-Dq5dvuhz.esm.min.js")}}),this._copyMipEffectWrapper.onApplyObservable.add(()=>{const e=this._copyMipEffectWrapper.effect;e&&this._copyMipSourceTexture&&(e.setTexture("textureSampler",this._copyMipSourceTexture),e.setInt("layerNum",this._copyMipLayer))}),this.voxelResolutionExp=h}_generateMipMaps(){const e=Math.ceil(Math.log2(this._voxelResolution));for(let s=1;s<e+1;s++)this._generateMipMap(s)}_generateMipMap(e){const s=this._mipArray[e-1];s&&(s.setTexture("srcMip",1===e?this.getVoxelGrid():this._mipArray[e-2]),s.render())}_copyMipMaps(){const e=Math.ceil(Math.log2(this._voxelResolution));for(let s=1;s<e+1;s++)this._copyMipMap(s)}_copyMipMap(e){const s=this._mipArray[e-1];if(!s)return;const t=this.getVoxelGrid();let i;if(i=t instanceof n&&t.renderTarget?t.renderTarget:t._rtWrapper,i){this._copyMipEffectRenderer.saveStates();const t=this._engine.getColorWrite(),a=this._engine.getDepthBuffer(),r=this._engine.getDepthWrite(),n=this._engine.getAlphaMode();this._engine.setColorWrite(!0),this._engine.setDepthBuffer(!1),this._engine.setDepthWrite(!1),this._engine.setAlphaMode(o.ALPHA_DISABLE);const h=s.getSize().width;let l=s.getInternalTexture()?.depth;l=Math.max(1,l||h);const d=Math.max(1,this._voxelResolution>>e),u=Math.min(l,d),_=i.texture,c=_?.generateMipMaps;_&&(_.generateMipMaps=!1);try{for(let t=0;t<u;t++)this._engine.bindFramebuffer(i,0,h,h,!0,e,t),this._copyMipSourceTexture=s,this._copyMipLayer=t,this._copyMipEffectRenderer.applyEffectWrapper(this._copyMipEffectWrapper),this._copyMipEffectRenderer.draw(),this._engine.unBindFramebuffer(i,!0);this._engine.isWebGPU||this._engine.unbindAllTextures()}finally{_&&void 0!==c&&(_.generateMipMaps=c),this._engine.setAlphaMode(n),this._engine.setDepthWrite(r),this._engine.setDepthBuffer(a),this._engine.setColorWrite(t)}this._copyMipSourceTexture=void 0,this._copyMipEffectRenderer.restoreStates()}}_computeNumberOfSlabs(){return Math.ceil(this._voxelResolution/this._maxDrawBuffers)}_createTextures(){const e=this._engine.isWebGPU,s={width:this._voxelResolution,height:this._voxelResolution,depth:this._voxelResolution},t={generateDepthBuffer:!1,generateMipMaps:!1,type:o.TEXTURETYPE_UNSIGNED_BYTE,format:o.TEXTUREFORMAT_R,samplingMode:o.TEXTURE_NEAREST_SAMPLINGMODE},i=this._computeNumberOfSlabs(),a={generateDepthBuffer:!1,generateMipMaps:!0,type:o.TEXTURETYPE_UNSIGNED_BYTE,format:o.TEXTUREFORMAT_R,samplingMode:o.TEXTURE_NEAREST_NEAREST_MIPNEAREST,shaderLanguage:e?1:0,extraInitializationsAsync:async()=>{e?await import("./iblCombineVoxelGrids.fragment-mg3O-e4_.esm.min.js"):await import("./iblCombineVoxelGrids.fragment-BQF13ki3.esm.min.js")}};this._engine.isWebGPU?(this._voxelGrid=new n("voxelGrid",s,this._scene,{...a,format:o.TEXTUREFORMAT_R,creationFlags:o.TEXTURE_CREATIONFLAG_STORAGE}),this._voxelGridRT=new n("voxelGridRT",{width:Math.min(2*s.width,2048),height:Math.min(2*s.height,2048)},this._scene,t)):this._triPlanarVoxelization?(this._voxelGridXaxis=new n("voxelGridXaxis",s,this._scene,t),this._voxelGridYaxis=new n("voxelGridYaxis",s,this._scene,t),this._voxelGridZaxis=new n("voxelGridZaxis",s,this._scene,t),this._voxelMrtsXaxis=this._createVoxelMRTs("x_axis_",this._voxelGridXaxis,i),this._voxelMrtsYaxis=this._createVoxelMRTs("y_axis_",this._voxelGridYaxis,i),this._voxelMrtsZaxis=this._createVoxelMRTs("z_axis_",this._voxelGridZaxis,i),this._combinedVoxelGridPT=new v("combinedVoxelGrid",s,"iblCombineVoxelGrids",this._scene,a,!1),this._scene.proceduralTextures.splice(this._scene.proceduralTextures.indexOf(this._combinedVoxelGridPT),1),this._combinedVoxelGridPT.setFloat("layer",0),this._combinedVoxelGridPT.setTexture("voxelXaxisSampler",this._voxelGridXaxis),this._combinedVoxelGridPT.setTexture("voxelYaxisSampler",this._voxelGridYaxis),this._combinedVoxelGridPT.setTexture("voxelZaxisSampler",this._voxelGridZaxis),this._combinedVoxelGridPT.autoClear=!1,this._combinedVoxelGridPT.wrapU=h.CLAMP_ADDRESSMODE,this._combinedVoxelGridPT.wrapV=h.CLAMP_ADDRESSMODE):(this._voxelGridZaxis=new n("voxelGridZaxis",s,this._scene,a),this._voxelMrtsZaxis=this._createVoxelMRTs("z_axis_",this._voxelGridZaxis,i));const r={generateDepthBuffer:!1,generateMipMaps:!1,type:o.TEXTURETYPE_UNSIGNED_BYTE,format:o.TEXTUREFORMAT_R,samplingMode:o.TEXTURE_NEAREST_SAMPLINGMODE,shaderLanguage:e?1:0,extraInitializationsAsync:async()=>{e?await import("./iblGenerateVoxelMip.fragment-DqNslapm.esm.min.js"):await import("./iblGenerateVoxelMip.fragment-DniyHFiC.esm.min.js")}};this._mipArray=new Array(Math.ceil(Math.log2(this._voxelResolution)));for(let e=1;e<=this._mipArray.length;e++){const s=this._voxelResolution>>e,t={width:s,height:s,depth:s};this._mipArray[e-1]=new v("voxelMip"+e,t,"iblGenerateVoxelMip",this._scene,r,!1),this._scene.proceduralTextures.splice(this._scene.proceduralTextures.indexOf(this._mipArray[e-1]),1);const i=this._mipArray[e-1];i.autoClear=!1,i.wrapU=h.CLAMP_ADDRESSMODE,i.wrapV=h.CLAMP_ADDRESSMODE,i.setTexture("srcMip",e>1?this._mipArray[e-2]:this.getVoxelGrid()),i.setInt("layerNum",0)}this._createVoxelMaterials()}_createVoxelMRTs(s,t,i){t.wrapU=h.CLAMP_ADDRESSMODE,t.wrapV=h.CLAMP_ADDRESSMODE,t.noPrePassRenderer=!0;const a=[],r=new Array(this._maxDrawBuffers).fill(o.TEXTURE_3D);for(let n=0;n<i;n++){let i=new Array(this._maxDrawBuffers).fill(0);i=i.map((e,s)=>n*this._maxDrawBuffers+s);let h=new Array(this._maxDrawBuffers).fill("");h=h.map((e,t)=>"voxel_grid_"+s+(n*this._maxDrawBuffers+t));const d=new l("mrt_"+s+n,{width:this._voxelResolution,height:this._voxelResolution,depth:this._voxelResolution},this._maxDrawBuffers,this._scene,{types:new Array(this._maxDrawBuffers).fill(o.TEXTURETYPE_UNSIGNED_BYTE),samplingModes:new Array(this._maxDrawBuffers).fill(o.TEXTURE_TRILINEAR_SAMPLINGMODE),generateMipMaps:!1,targetTypes:r,formats:new Array(this._maxDrawBuffers).fill(o.TEXTUREFORMAT_R),faceIndex:new Array(this._maxDrawBuffers).fill(0),layerIndex:i,layerCounts:new Array(this._maxDrawBuffers).fill(this._voxelResolution),generateDepthBuffer:!1,generateStencilBuffer:!1},h);d.clearColor=new e(0,0,0,1),d.noPrePassRenderer=!0;for(let e=0;e<this._maxDrawBuffers;e++)d.setInternalTexture(t.getInternalTexture(),e);a.push(d)}return a}_disposeVoxelTextures(){this._stopVoxelization();for(let e=0;e<this._voxelMrtsZaxis.length;e++)this._triPlanarVoxelization&&(this._voxelMrtsXaxis[e].dispose(!0),this._voxelMrtsYaxis[e].dispose(!0)),this._voxelMrtsZaxis[e].dispose(!0);this._triPlanarVoxelization&&(this._voxelGridXaxis?.dispose(),this._voxelGridYaxis?.dispose(),this._combinedVoxelGridPT?.dispose()),this._voxelGridZaxis?.dispose();for(const e of this._mipArray)e.dispose();this._voxelMaterial?.dispose(),this._mipArray=[],this._voxelMrtsXaxis=[],this._voxelMrtsYaxis=[],this._voxelMrtsZaxis=[]}_createVoxelMaterials(){const e=this._engine.isWebGPU;this._voxelMaterial=new d("voxelization",this._scene,"iblVoxelGrid",{uniforms:["world","viewMatrix","invTransWorld","invWorldScale","nearPlane","farPlane","stepSize"],defines:["MAX_DRAW_BUFFERS "+this._maxDrawBuffers],shaderLanguage:e?1:0,extraInitializationsAsync:async()=>{e?await Promise.all([import("./iblVoxelGrid.fragment-D0MjXls8.esm.min.js"),import("./iblVoxelGrid.vertex-I_ccVMQf.esm.min.js")]):await Promise.all([import("./iblVoxelGrid.fragment-ruoC9is5.esm.min.js"),import("./iblVoxelGrid.vertex-BOwfcJR_.esm.min.js")])}}),this._voxelMaterial.cullBackFaces=!1,this._voxelMaterial.backFaceCulling=!1,this._voxelMaterial.depthFunction=o.ALWAYS}isReady(){let e=this.getVoxelGrid().isReady();for(let s=0;s<this._mipArray.length;s++){const t=this._mipArray[s].isReady();e&&=t}return!(!e||this._voxelizationInProgress)}_stopVoxelization(){this._removeVoxelRTs(this._voxelMrtsXaxis),this._removeVoxelRTs(this._voxelMrtsYaxis),this._removeVoxelRTs(this._voxelMrtsZaxis),this._removeVoxelRTs([this._voxelGridRT])}_removeVoxelRTs(e){const s=this._renderTargets.findIndex(s=>s===e[0]);if(s>=0)this._renderTargets.splice(s,e.length);else{const s=this._scene.customRenderTargets.findIndex(s=>s===e[0]);s>=0&&this._scene.customRenderTargets.splice(s,e.length)}}updateVoxelGrid(e,s=!0){this._voxelizationInProgress||(this._stopVoxelization(),this._voxelizationInProgress=!0,this._engine.isWebGPU?(this._voxelGridRT.renderList=e,this._addRTsForRender([this._voxelGridRT],e,0)):this._triPlanarVoxelization?(this._addRTsForRender(this._voxelMrtsXaxis,e,0),this._addRTsForRender(this._voxelMrtsYaxis,e,1),this._addRTsForRender(this._voxelMrtsZaxis,e,2)):this._addRTsForRender(this._voxelMrtsZaxis,e,2),s&&(this._renderVoxelGridBound=this._renderVoxelGrid.bind(this),this._scene.onAfterRenderObservable.add(this._renderVoxelGridBound)))}processVoxelization(){this._renderVoxelGrid()}_renderVoxelGrid(){if(this._voxelizationInProgress){let e=!1;for(let s=0;s<this._renderTargets.length&&!e;s++){const t=this._renderTargets[s].renderList;if(t)for(const s of t)if(u(s.getClassName())&&!s._isDepthSortSettled){e=!0;break}}if(e&&this._sortSettleWaitFrames<180)return void this._sortSettleWaitFrames++;this._sortSettleWaitFrames=0;let s=this.getVoxelGrid().isReady();for(let e=0;e<this._mipArray.length;e++){const t=this._mipArray[e].isReady();s&&=t}for(let e=0;e<this._renderTargets.length;e++){const t=this._renderTargets[e].isReadyForRendering();s&&=t}for(const e of Array.from(this._gsVoxelMaterialCache.values()))s&&=e.isReady();if(!s)return;if(!this._copyMipEffectWrapper.effect.isReady())return;if(this._engine.isWebGPU&&this._voxelGrid&&this._voxelGrid.renderTarget)for(let e=0;e<this._voxelResolution;e++)this._engine.bindFramebuffer(this._voxelGrid.renderTarget,0,void 0,void 0,!0,0,e),this._engine.clear(this._voxelClearColor,!0,!1,!1),this._engine.unBindFramebuffer(this._voxelGrid.renderTarget,!0);for(const e of this._renderTargets)e.render();this._stopVoxelization(),this._triPlanarVoxelization&&!this._engine.isWebGPU&&this._combinedVoxelGridPT.render(),this._generateMipMaps(),this._copyMipMaps(),this._scene.onAfterRenderObservable.removeCallback(this._renderVoxelGridBound),this._voxelizationInProgress=!1,this.onVoxelizationCompleteObservable.notifyObservers()}}_installVoxelMixedCustomRender(e){const s=this._scene.getEngine(),t=e=>{const t=e.getRenderingMesh(),i=e.getEffectiveMesh(),a=this._gsVoxelMaterialCache.get(i.uniqueId);if(!a||!a.isReady())return;const r=a._getDrawWrapper();if(!r?.effect)return;const n=r.effect,h=t._getInstancesRenderList(e._id,!!e.getReplacementMesh());if(h.mustReturn)return;const l=s.getCaps().instancedArrays&&(null!==h.visibleInstances[e._id]&&void 0!==h.visibleInstances[e._id]||t.hasThinInstances),d=e.getMaterial()?.fillMode??o.MATERIAL_TriangleFillMode;if(s.enableEffect(r),t._bind(e,n,d),a._preBind(r),a.bind(i.getWorldMatrix(),i,n),i.rotationsATexture){if(s.isWebGPU){const s=N._VOXEL_VIEW_MATRICES;for(let a=0;a<3;a++)n.setMatrix("viewMatrix",s[a]),t._processRendering(i,e,n,d,h,l,(e,s)=>{n.setMatrix("world",s)})}else t._processRendering(i,e,n,d,h,l,(e,s)=>n.setMatrix("world",s));a.unbind()}else a.unbind()},i=(e,s)=>{for(let i=0;i<e.length;i++){const a=e.data[i],r=a.getEffectiveMesh();u(r.getClassName())?t(a):a.render(s)}};e.customRenderFunction=(e,t,a,r)=>{r.length&&(s.setColorWrite(!1),i(r,!1),s.setColorWrite(!0)),i(e,!1),i(t,!1),i(a,!0)}}_addGsMeshToVoxelRT(e,s){let t=this._gsVoxelMaterialCache.get(s.uniqueId);if(!t){const e=s.material;if(!e)return;const i=this._engine.isWebGPU?1:0;t=e.makeVoxelRenderingMaterial(this._scene,i,this._maxDrawBuffers,s.isCompound),this._gsVoxelMaterialCache.set(s.uniqueId,t)}e.renderList?.push(s),e.setMaterialForRendering(s,t)}_addRTsForRender(e,s,t){const i=1/this._computeNumberOfSlabs(),a=this._voxelMaterial;for(let r=0;r<e.length;r++){const n=e[r];n._disableEngineStages=!0,n.useCameraPostProcesses=!1,n.renderParticles=!1,n.renderSprites=!1,n.enableOutlineRendering=!1;const o=e=>{for(let s=0;s<e.length;s++){const t=e.data[s];t.getMaterial()===a&&t.render(!1)}};n.customRenderFunction=(e,s,t,i)=>{o(i),o(e),o(s),o(t)},n.renderList=[];const h=r*i,l=(r+1)*i,d=i/this._maxDrawBuffers,_=N._VOXEL_VIEW_MATRICES[t];if(n.onBeforeRenderObservable.clear(),n.onBeforeRenderObservable.add(()=>{a.setMatrix("viewMatrix",_),a.setMatrix("invWorldScale",this._invWorldScaleMatrix),a.setFloat("nearPlane",h),a.setFloat("farPlane",l),a.setFloat("stepSize",d),this._engine.isWebGPU&&(this._voxelMaterial.useVertexPulling=!0,this._voxelMaterial.setTexture("voxel_storage",this.getVoxelGrid()));for(const e of n.renderList??[])if(u(e.getClassName())){const s=this._gsVoxelMaterialCache.get(e.uniqueId);s&&(s.setMatrix("invWorldScale",this._invWorldScaleMatrix),this._engine.isWebGPU?s.setTexture("voxel_storage",this.getVoxelGrid()):(s.setMatrix("viewMatrix",_),s.setFloat("nearPlane",h),s.setFloat("farPlane",l),s.setFloat("stepSize",d)))}}),0===s.length)return;for(const e of s){if(!e)continue;u(e.getClassName())?this._addGsMeshToVoxelRT(n,e):e.subMeshes&&e.subMeshes.length>0&&(n.renderList?.push(e),n.setMaterialForRendering(e,a));const s=e.getChildMeshes();for(const e of s)u(e.getClassName())?this._addGsMeshToVoxelRT(n,e):e.subMeshes&&e.subMeshes.length>0&&(n.renderList?.push(e),n.setMaterialForRendering(e,a))}this._installVoxelMixedCustomRender(n)}this._renderTargets=this._renderTargets.concat(e)}resize(){}dispose(){this._disposeVoxelTextures();for(const e of Array.from(this._gsVoxelMaterialCache.values()))e.dispose();this._gsVoxelMaterialCache.clear()}}N._VOXEL_VIEW_MATRICES=[t.LookAtLH(_.Zero(),new _(1,0,0),_.Up()),t.LookAtLH(_.Zero(),new _(0,1,0),new _(1,0,0)),t.LookAtLH(_.Zero(),new _(0,0,1),_.Up())];class L{get voxelShadowOpacity(){return this._voxelShadowOpacity}set voxelShadowOpacity(e){this._voxelShadowOpacity=e}get ssShadowOpacity(){return this._ssShadowOpacity}set ssShadowOpacity(e){this._ssShadowOpacity=e}get sssSamples(){return this._sssSamples}set sssSamples(e){this._sssSamples=e}get sssStride(){return this._sssStride}set sssStride(e){this._sssStride=e}get sssMaxDist(){return this._sssMaxDist}set sssMaxDist(e){this._sssMaxDist=e}get sssThickness(){return this._sssThickness}set sssThickness(e){this._sssThickness=e}get voxelNormalBias(){return this._voxelNormalBias}set voxelNormalBias(e){this._voxelNormalBias=e}get voxelDirectionBias(){return this._voxelDirectionBias}set voxelDirectionBias(e){this._voxelDirectionBias=e}get enabled(){return this._enabled}set enabled(e){this._enabled=e,this._outputTexture&&(this._outputTexture.isEnabled=e)}get sampleDirections(){return this._sampleDirections}set sampleDirections(e){this._sampleDirections=e}get envRotation(){return this._envRotation}set envRotation(e){this._envRotation=e}getOutputTexture(){return this._outputTexture}getDebugPassPP(){return this._debugPassPP||this._createDebugPass(),this._debugPassPP}get debugPassName(){return this._debugPassName}setWorldScaleMatrix(e){this._invWorldScaleMatrix=e}set coloredShadows(e){this._coloredShadows=e}get coloredShadows(){return this._coloredShadows}setDebugDisplayParams(e,s,t,i){this._debugSizeParams.set(e,s,t,i)}_createDebugPass(){const e=this._engine.isWebGPU;if(!this._debugPassPP){const s={width:this._engine.getRenderWidth(),height:this._engine.getRenderHeight(),uniforms:["sizeParams"],samplers:["debugSampler"],engine:this._engine,reusable:!0,shaderLanguage:e?1:0,extraInitializations:(e,s)=>{e?s.push(import("./iblShadowDebug.fragment-5LIZhuIq.esm.min.js")):s.push(import("./iblShadowDebug.fragment-CbGXyUEv.esm.min.js"))}};this._debugPassPP=new c(this.debugPassName,"iblShadowDebug",s),this._debugPassPP.autoClear=!1,this._debugPassPP.onApplyObservable.add(e=>{e.setTexture("debugSampler",this._outputTexture),e.setVector4("sizeParams",this._debugSizeParams)})}}constructor(e,s){this._voxelShadowOpacity=1,this._sssSamples=16,this._sssStride=8,this._sssMaxDist=.05,this._sssThickness=.5,this._ssShadowOpacity=1,this._cameraInvView=t.Identity(),this._cameraInvProj=t.Identity(),this._invWorldScaleMatrix=t.Identity(),this._frameId=0,this._sampleDirections=4,this._shadowParameters=new g(0,0,0,0),this._sssParameters=new g(0,0,0,0),this._opacityParameters=new g(0,0,0,0),this._voxelBiasParameters=new g(0,0,0,0),this._voxelNormalBias=1.4,this._voxelDirectionBias=1.75,this._enabled=!0,this.debugEnabled=!1,this._debugPassName="Voxel Tracing Debug Pass",this._envRotation=0,this._coloredShadows=!1,this._debugVoxelMarchEnabled=!1,this._debugSizeParams=new g(0,0,0,0),this._renderWhenGBufferReady=null,this._scene=e,this._engine=e.getEngine(),this._renderPipeline=s,this._createTextures()}_createTextures(){const e=this._createDefines(),s=this._engine.isWebGPU,t={type:o.TEXTURETYPE_UNSIGNED_BYTE,format:o.TEXTUREFORMAT_RGBA,samplingMode:o.TEXTURE_NEAREST_SAMPLINGMODE,generateDepthBuffer:!1,shaderLanguage:s?1:0,extraInitializationsAsync:async()=>{s?await Promise.all([import("./iblShadowVoxelTracing.fragment-CdzRvWxh.esm.min.js")]):await Promise.all([import("./iblShadowVoxelTracing.fragment-CYT--bfh.esm.min.js")])}};this._outputTexture=new v("voxelTracingPass",{width:this._engine.getRenderWidth(),height:this._engine.getRenderHeight()},"iblShadowVoxelTracing",this._scene,t),this._outputTexture.refreshRate=-1,this._outputTexture.autoClear=!1,this._outputTexture.defines=e,this._setBindings(this._scene.activeCamera),this._renderWhenGBufferReady=this._render.bind(this),this._renderPipeline.onVoxelizationCompleteObservable.addOnce(()=>{this._scene.geometryBufferRenderer&&this._scene.geometryBufferRenderer.getGBuffer().onAfterRenderObservable.add(this._renderWhenGBufferReady)})}_createDefines(){let e="";return this._scene.useRightHandedSystem&&(e+="#define RIGHT_HANDED\n"),this._debugVoxelMarchEnabled&&(e+="#define VOXEL_MARCH_DIAGNOSTIC_INFO_OPTION 1u\n"),this._coloredShadows&&(e+="#define COLOR_SHADOWS 1u\n"),this._scene.geometryBufferRenderer?.normalsAreUnsigned&&(e+="#define WORLD_NORMAL_UNSIGNED\n"),e}_setBindings(e){this._outputTexture.defines=this._createDefines(),this._outputTexture.setMatrix("viewMtx",e.getViewMatrix()),this._outputTexture.setMatrix("projMtx",e.getProjectionMatrix()),e.getProjectionMatrix().invertToRef(this._cameraInvProj),e.getViewMatrix().invertToRef(this._cameraInvView),this._outputTexture.setMatrix("invProjMtx",this._cameraInvProj),this._outputTexture.setMatrix("invViewMtx",this._cameraInvView),this._outputTexture.setMatrix("wsNormalizationMtx",this._invWorldScaleMatrix),this._frameId++;let s=0;this._scene.environmentTexture&&(s=this._scene.environmentTexture.rotationY??0),s=this._scene.useRightHandedSystem?-(s+.5*Math.PI):s-.5*Math.PI,s%=2*Math.PI,this._shadowParameters.set(this._sampleDirections,this._frameId,1,s),this._outputTexture.setVector4("shadowParameters",this._shadowParameters);const t=this._renderPipeline._getVoxelGridTexture(),a=Math.floor(Math.log2(t.getSize().width));this._voxelBiasParameters.set(this._voxelNormalBias,this._voxelDirectionBias,a,0),this._outputTexture.setVector4("voxelBiasParameters",this._voxelBiasParameters),this._sssParameters.set(this._sssSamples,this._sssStride,this._sssMaxDist,this._sssThickness),this._outputTexture.setVector4("sssParameters",this._sssParameters),this._opacityParameters.set(this._voxelShadowOpacity,this._ssShadowOpacity,0,0),this._outputTexture.setVector4("shadowOpacity",this._opacityParameters),this._outputTexture.setTexture("voxelGridSampler",t),this._outputTexture.setTexture("blueNoiseSampler",this._renderPipeline._getNoiseTexture());const r=this._scene.iblCdfGenerator;if(!r)return i.Warn("IBLShadowsVoxelTracingPass: Can't bind for render because iblCdfGenerator is not enabled."),!1;this._outputTexture.setTexture("icdfSampler",r.getIcdfTexture()),this._coloredShadows&&this._scene.environmentTexture&&this._outputTexture.setTexture("iblSampler",this._scene.environmentTexture);const n=this._scene.geometryBufferRenderer;if(!n)return i.Warn("IBLShadowsVoxelTracingPass: Can't bind for render because GeometryBufferRenderer is not enabled."),!1;const o=n.getTextureIndex(M.SCREENSPACE_DEPTH_TEXTURE_TYPE);this._outputTexture.setTexture("depthSampler",n.getGBuffer().textures[o]);const h=n.getTextureIndex(M.NORMAL_TEXTURE_TYPE);return this._outputTexture.setTexture("worldNormalSampler",n.getGBuffer().textures[h]),!0}_render(){this.enabled&&this._outputTexture.isReady()&&this._outputTexture.getEffect()?.isReady()&&this._setBindings(this._scene.activeCamera)&&this._outputTexture.render()}resize(e=1){const s={width:Math.max(1,Math.floor(this._engine.getRenderWidth()*e)),height:Math.max(1,Math.floor(this._engine.getRenderHeight()*e))};this._outputTexture.getSize().width===s.width&&this._outputTexture.getSize().height===s.height||this._outputTexture.resize(s,!1)}isReady(){return this._outputTexture.isReady()&&!(this._debugPassPP&&!this._debugPassPP.isReady())&&this._scene.iblCdfGenerator&&this._scene.iblCdfGenerator.getIcdfTexture().isReady()&&this._renderPipeline._getVoxelGridTexture().isReady()}dispose(){if(this._scene.geometryBufferRenderer&&this._renderWhenGBufferReady){this._scene.geometryBufferRenderer.getGBuffer().onAfterRenderObservable.removeCallback(this._renderWhenGBufferReady)}this._outputTexture.dispose(),this._debugPassPP&&this._debugPassPP.dispose()}}class W{get enabled(){return this._enabled}set enabled(e){this._enabled=e,this._outputTexture&&(this._outputTexture.isEnabled=e)}getOutputTexture(){return this._outputTexture}getDebugPassPP(){return this._debugPassPP||this._createDebugPass(),this._debugPassPP}get debugPassName(){return this._debugPassName}setWorldScale(e){this._worldScale=e}setDebugDisplayParams(e,s,t,i){this._debugSizeParams.set(e,s,t,i)}_createDebugPass(){if(!this._debugPassPP){const e=this._engine.isWebGPU,s={width:this._engine.getRenderWidth(),height:this._engine.getRenderHeight(),textureFormat:o.TEXTUREFORMAT_RGBA,textureType:o.TEXTURETYPE_UNSIGNED_BYTE,samplingMode:o.TEXTURE_NEAREST_SAMPLINGMODE,uniforms:["sizeParams"],samplers:["debugSampler"],engine:this._engine,reusable:!1,shaderLanguage:e?1:0,extraInitializations:(e,s)=>{e?s.push(import("./iblShadowDebug.fragment-5LIZhuIq.esm.min.js")):s.push(import("./iblShadowDebug.fragment-CbGXyUEv.esm.min.js"))}};this._debugPassPP=new c(this.debugPassName,"iblShadowDebug",s),this._debugPassPP.autoClear=!1,this._debugPassPP.onApplyObservable.add(e=>{e.setTexture("debugSampler",this._outputTexture),e.setVector4("sizeParams",this._debugSizeParams)})}}constructor(e,s){this._worldScale=1,this._blurParameters=new g(0,0,0,0),this._enabled=!0,this._debugPassName="Spatial Blur Debug Pass",this.debugEnabled=!1,this._debugSizeParams=new g(0,0,0,0),this._renderWhenGBufferReady=null,this._scene=e,this._engine=e.getEngine(),this._renderPipeline=s,this._createTextures()}_createTextures(){const e=this._engine.isWebGPU,s={type:o.TEXTURETYPE_UNSIGNED_BYTE,format:o.TEXTUREFORMAT_RGBA,samplingMode:o.TEXTURE_NEAREST_SAMPLINGMODE,generateDepthBuffer:!1,generateMipMaps:!1,shaderLanguage:e?1:0,extraInitializationsAsync:async()=>{e?await Promise.all([import("./iblShadowSpatialBlur.fragment-CXeBvt1w.esm.min.js")]):await Promise.all([import("./iblShadowSpatialBlur.fragment-DlSrWbSr.esm.min.js")])}};this._outputTexture=new v("spatialBlurPass",{width:this._engine.getRenderWidth(),height:this._engine.getRenderHeight()},"iblShadowSpatialBlur",this._scene,s,!1,!1,o.TEXTURETYPE_UNSIGNED_BYTE),this._outputTexture.refreshRate=-1,this._outputTexture.autoClear=!1,this._setBindings(),this._renderWhenGBufferReady=this._render.bind(this),this._renderPipeline.onVoxelizationCompleteObservable.addOnce(()=>{this._scene.geometryBufferRenderer&&this._scene.geometryBufferRenderer.getGBuffer().onAfterRenderObservable.add(this._renderWhenGBufferReady)})}_setBindings(){this._outputTexture.setTexture("voxelTracingSampler",this._renderPipeline._getVoxelTracingTexture());this._blurParameters.set(1,this._worldScale,0,0),this._outputTexture.setVector4("blurParameters",this._blurParameters);const e=this._scene.geometryBufferRenderer;if(!e)return!1;const s=e.getTextureIndex(M.SCREENSPACE_DEPTH_TEXTURE_TYPE);this._outputTexture.setTexture("depthSampler",e.getGBuffer().textures[s]);const t=e.getTextureIndex(M.NORMAL_TEXTURE_TYPE);return this._outputTexture.setTexture("worldNormalSampler",e.getGBuffer().textures[t]),!0}_render(){this.enabled&&this._outputTexture.isReady()&&this._outputTexture.getEffect()?.isReady()&&this._setBindings()&&this._outputTexture.render()}resize(e=1){const s={width:Math.max(1,Math.floor(this._engine.getRenderWidth()*e)),height:Math.max(1,Math.floor(this._engine.getRenderHeight()*e))};this._outputTexture.getSize().width===s.width&&this._outputTexture.getSize().height===s.height||this._outputTexture.resize(s,!1)}isReady(){return this._outputTexture.isReady()&&!(this._debugPassPP&&!this._debugPassPP.isReady())}dispose(){if(this._scene.geometryBufferRenderer&&this._renderWhenGBufferReady){this._scene.geometryBufferRenderer.getGBuffer().onAfterRenderObservable.removeCallback(this._renderWhenGBufferReady)}this._outputTexture.dispose(),this._debugPassPP&&this._debugPassPP.dispose()}}class z{get enabled(){return this._enabled}set enabled(e){this._enabled=e,this._outputTexture&&(this._outputTexture.isEnabled=e),this._oldAccumulationCopy&&(this._oldAccumulationCopy.isEnabled=e),this._oldPositionCopy&&(this._oldPositionCopy.isEnabled=e)}getOutputTexture(){return this._outputTexture}getDebugPassPP(){return this._debugPassPP||this._createDebugPass(),this._debugPassPP}get debugPassName(){return this._debugPassName}get remanence(){return this._remanence}set remanence(e){this._remanence=e}get reset(){return this._reset}set reset(e){this._reset=e}set isMoving(e){this._isMoving=e}setDebugDisplayParams(e,s,t,i){this._debugSizeParams.set(e,s,t,i)}_createDebugPass(){if(!this._debugPassPP){const e=this._engine.isWebGPU,s={width:this._engine.getRenderWidth(),height:this._engine.getRenderHeight(),textureFormat:o.TEXTUREFORMAT_RGBA,textureType:o.TEXTURETYPE_UNSIGNED_BYTE,samplingMode:o.TEXTURE_NEAREST_SAMPLINGMODE,uniforms:["sizeParams"],samplers:["debugSampler"],engine:this._engine,reusable:!1,shaderLanguage:e?1:0,extraInitializations:(e,s)=>{e?s.push(import("./iblShadowDebug.fragment-5LIZhuIq.esm.min.js")):s.push(import("./iblShadowDebug.fragment-CbGXyUEv.esm.min.js"))}};this._debugPassPP=new c(this.debugPassName,"iblShadowDebug",s),this._debugPassPP.autoClear=!1,this._debugPassPP.onApplyObservable.add(e=>{e.setTexture("debugSampler",this._outputTexture),e.setVector4("sizeParams",this._debugSizeParams)})}}constructor(e,t){this._accumulationParams=new g(0,0,0,0),this.debugEnabled=!1,this._enabled=!0,this.onReadyObservable=new s,this._debugPassName="Shadow Accumulation Debug Pass",this._remanence=.9,this._reset=!0,this._isMoving=!1,this._debugSizeParams=new g(0,0,0,0),this._renderWhenGBufferReady=null,this._scene=e,this._engine=e.getEngine(),this._renderPipeline=t,this._createTextures()}_createTextures(){const e=this._engine.isWebGPU,s={type:o.TEXTURETYPE_HALF_FLOAT,format:o.TEXTUREFORMAT_RGBA,samplingMode:o.TEXTURE_NEAREST_SAMPLINGMODE,generateDepthBuffer:!1,generateMipMaps:!1,shaderLanguage:e?1:0,extraInitializationsAsync:async()=>{e?await Promise.all([import("./iblShadowAccumulation.fragment-DKdwJvgn.esm.min.js")]):await Promise.all([import("./iblShadowAccumulation.fragment-DnJUvAb9.esm.min.js")])}};this._outputTexture=new v("shadowAccumulationPass",{width:this._engine.getRenderWidth(),height:this._engine.getRenderHeight()},"iblShadowAccumulation",this._scene,s),this._outputTexture.refreshRate=-1,this._outputTexture.autoClear=!1,this._outputTexture.onGeneratedObservable.addOnce(()=>{this.onReadyObservable.notifyObservers()}),this._setOutputTextureBindings(),this._renderWhenGBufferReady=this._render.bind(this),this._renderPipeline.onVoxelizationCompleteObservable.addOnce(()=>{this._scene.geometryBufferRenderer&&this._scene.geometryBufferRenderer.getGBuffer().onAfterRenderObservable.add(this._renderWhenGBufferReady)});const t={type:o.TEXTURETYPE_HALF_FLOAT,format:o.TEXTUREFORMAT_RGBA,samplingMode:o.TEXTURE_NEAREST_SAMPLINGMODE,generateDepthBuffer:!1,generateMipMaps:!1,shaderLanguage:e?1:0,extraInitializationsAsync:async()=>{e?await Promise.all([import("./pass.fragment-BNHPa40I.esm.min.js")]):await Promise.all([import("./pass.fragment-KUh_d6Eh.esm.min.js")])}};this._oldAccumulationCopy=new v("oldAccumulationRT",{width:this._engine.getRenderWidth(),height:this._engine.getRenderHeight()},"pass",this._scene,t,!1),this._oldAccumulationCopy.autoClear=!1,this._oldAccumulationCopy.refreshRate=1,this._oldAccumulationCopy.onBeforeGenerationObservable.add(this._setAccumulationCopyBindings.bind(this)),this._setAccumulationCopyBindings();const i={type:o.TEXTURETYPE_HALF_FLOAT,format:o.TEXTUREFORMAT_RGBA,samplingMode:o.TEXTURE_NEAREST_SAMPLINGMODE,generateDepthBuffer:!1,generateMipMaps:!1,shaderLanguage:e?1:0,extraInitializationsAsync:async()=>{e?await Promise.all([import("./pass.fragment-BNHPa40I.esm.min.js")]):await Promise.all([import("./pass.fragment-KUh_d6Eh.esm.min.js")])}};this._oldPositionCopy=new v("oldLocalPositionRT",{width:this._engine.getRenderWidth(),height:this._engine.getRenderHeight()},"pass",this._scene,i,!1),this._updatePositionCopy(),this._oldPositionCopy.autoClear=!1,this._oldPositionCopy.refreshRate=1,this._oldPositionCopy.onBeforeGenerationObservable.add(this._updatePositionCopy.bind(this))}_setOutputTextureBindings(){const e=this._isMoving?this.remanence:.99;this._accumulationParams.set(e,this.reset?1:0,this._renderPipeline.voxelGridSize,0),this._outputTexture.setTexture("spatialBlurSampler",this._renderPipeline._getSpatialBlurTexture()),this._outputTexture.setVector4("accumulationParameters",this._accumulationParams),this._outputTexture.setTexture("oldAccumulationSampler",this._oldAccumulationCopy?this._oldAccumulationCopy:this._renderPipeline._dummyTexture2d),this._outputTexture.setTexture("prevPositionSampler",this._oldPositionCopy?this._oldPositionCopy:this._renderPipeline._dummyTexture2d);const s=this._scene.geometryBufferRenderer;if(!s)return!1;const t=s.getTextureIndex(M.VELOCITY_LINEAR_TEXTURE_TYPE);this._outputTexture.setTexture("motionSampler",s.getGBuffer().textures[t]);const i=s.getTextureIndex(M.POSITION_TEXTURE_TYPE);return this._outputTexture.setTexture("positionSampler",s.getGBuffer().textures[i]),this.reset=!1,this._isMoving=!1,!0}_updatePositionCopy(){const e=this._scene.geometryBufferRenderer;if(e){const s=e.getTextureIndex(M.POSITION_TEXTURE_TYPE);this._oldPositionCopy.setTexture("textureSampler",e.getGBuffer().textures[s])}}_setAccumulationCopyBindings(){this._oldAccumulationCopy.setTexture("textureSampler",this._outputTexture)}_render(){this.enabled&&this._outputTexture.isReady()&&this._outputTexture.getEffect()?.isReady()&&this._setOutputTextureBindings()&&this._outputTexture.render()}resize(e=1){const s={width:Math.max(1,Math.floor(this._engine.getRenderWidth()*e)),height:Math.max(1,Math.floor(this._engine.getRenderHeight()*e))};this._outputTexture.getSize().width===s.width&&this._outputTexture.getSize().height===s.height||(this._outputTexture.resize(s,!1),this._oldAccumulationCopy.resize(s,!1),this._oldPositionCopy.resize({width:this._engine.getRenderWidth(),height:this._engine.getRenderHeight()},!1),this.reset=!0)}_disposeTextures(){this._oldAccumulationCopy.dispose(),this._oldPositionCopy.dispose(),this._outputTexture.dispose()}isReady(){return this._oldAccumulationCopy&&this._oldAccumulationCopy.isReady()&&this._oldPositionCopy&&this._oldPositionCopy.isReady()&&this._outputTexture.isReady()&&!(this._debugPassPP&&!this._debugPassPP.isReady())}dispose(){if(this._scene.geometryBufferRenderer&&this._renderWhenGBufferReady){this._scene.geometryBufferRenderer.getGBuffer().onAfterRenderObservable.removeCallback(this._renderWhenGBufferReady)}this._disposeTextures(),this._debugPassPP&&this._debugPassPP.dispose(),this.onReadyObservable.clear()}}class U extends h{get width(){return this._texture?this._texture.width:0}get height(){return this._texture?this._texture.height:0}get depth(){return this._texture?this._texture.depth:0}constructor(e,s,t,i,a,r,n=!0,l=!1,d=h.TRILINEAR_SAMPLINGMODE,u=o.TEXTURETYPE_UNSIGNED_BYTE,_){super(null,r,!n,l),this.format=a,this._texture=r.getEngine().createRawTexture3D(e,s,t,i,a,n,l,d,null,u,_),this.is3D=!0}update(e){this._texture&&this._getEngine().updateRawTexture3D(this._texture,e,this._texture.format,this._texture.invertY,null,this._texture.type)}}class F extends T{constructor(){super(...arguments),this.RENDER_WITH_IBL_SHADOWS=!1,this.COLORED_IBL_SHADOWS=!1}}let X=(()=>{var e,s;let t,i,a=G,r=[],n=[],h=[],l=[];return e=class extends a{get iblShadowsTexture(){return this._iblShadowsTexture}set iblShadowsTexture(e){this._iblShadowsTexture!==e&&(this._iblShadowsTexture=e,this._markAllSubMeshesAsTexturesDirty())}get isColored(){return this._isColored}set isColored(e){this._isColored!==e&&(this._isColored=e,this._markAllSubMeshesAsTexturesDirty())}get isEnabled(){return m(this,s,"f")}set isEnabled(e){x(this,s,e,"f")}_markAllSubMeshesAsTexturesDirty(){this._enable(this._isEnabled),this._internalMarkAllSubMeshesAsTexturesDirty()}isCompatible(){return!0}constructor(t){super(t,e.Name,310,new F),this.shadowOpacity=p(this,r,1),this._isEnabled=(p(this,n),!1),this._isColored=!1,s.set(this,p(this,h,!1)),this._internalMarkAllSubMeshesAsTexturesDirty=p(this,l),this._internalMarkAllSubMeshesAsTexturesDirty=t._dirtyCallbacks[o.MATERIAL_TextureDirtyFlag]}_isOpenPBRMaterial(){return"OpenPBRMaterial"===this._material.getClassName()}prepareDefines(e){e.RENDER_WITH_IBL_SHADOWS=this._isEnabled,e.COLORED_IBL_SHADOWS=this.isColored}getClassName(){return"IBLShadowsPluginMaterial"}getUniforms(e){const s={ubo:[]};return this._isOpenPBRMaterial()?s.fragment=1===e?"#ifdef RENDER_WITH_IBL_SHADOWS\n var shadowOpacity: f32;\n #endif":"#ifdef RENDER_WITH_IBL_SHADOWS\n uniform float shadowOpacity;\n #endif":(s.ubo.push({name:"renderTargetSize",size:2,type:"vec2"}),s.fragment=1===e?"#ifdef RENDER_WITH_IBL_SHADOWS\n var renderTargetSize: vec2f;\n var shadowOpacity: f32;\n #endif":"#ifdef RENDER_WITH_IBL_SHADOWS\n uniform vec2 renderTargetSize;\n uniform float shadowOpacity;\n #endif"),s.ubo.push({name:"shadowOpacity",size:1,type:"float"}),s}getSamplers(e){e.push("iblShadowsTexture")}bindForSubMesh(e){this._isEnabled&&this.iblShadowsTexture&&(e.bindTexture("iblShadowsTexture",this.iblShadowsTexture),e.updateFloat2("renderTargetSize",this._material.getScene().getEngine().getRenderWidth(),this._material.getScene().getEngine().getRenderHeight()),e.updateFloat("shadowOpacity",this.shadowOpacity))}getCustomCode(e,s){let t;return 1===s?(t={CUSTOM_FRAGMENT_DEFINITIONS:"\n #ifdef RENDER_WITH_IBL_SHADOWS\n var iblShadowsTextureSampler: sampler;\n var iblShadowsTexture: texture_2d<f32>;\n\n #ifdef COLORED_IBL_SHADOWS\n fn computeIndirectShadow() -> vec3f {\n var uv = fragmentInputs.position.xy / uniforms.renderTargetSize;\n var shadowValue: vec3f = textureSample(iblShadowsTexture, iblShadowsTextureSampler, uv).rgb;\n return mix(shadowValue, vec3f(1.0), 1.0 - uniforms.shadowOpacity);\n }\n #else\n fn computeIndirectShadow() -> vec2f {\n var uv = fragmentInputs.position.xy / uniforms.renderTargetSize;\n var shadowValue: vec2f = textureSample(iblShadowsTexture, iblShadowsTextureSampler, uv).rg;\n return mix(shadowValue, vec2f(1.0), 1.0 - uniforms.shadowOpacity);\n }\n #endif\n #endif\n "},this._material instanceof C?t.CUSTOM_FRAGMENT_BEFORE_FINALCOLORCOMPOSITION="\n #ifdef RENDER_WITH_IBL_SHADOWS\n #ifndef UNLIT\n #ifdef REFLECTION\n #ifdef COLORED_IBL_SHADOWS\n var shadowValue: vec3f = computeIndirectShadow();\n finalIrradiance *= shadowValue;\n finalRadianceScaled *= mix(vec3f(1.0), shadowValue, roughness);\n #else\n var shadowValue: vec2f = computeIndirectShadow();\n finalIrradiance *= vec3f(shadowValue.x);\n finalRadianceScaled *= vec3f(mix(pow(shadowValue.y, 4.0), shadowValue.x, roughness));\n #endif\n #endif\n #else\n finalDiffuse *= computeIndirectShadow().x;\n #endif\n #endif\n ":this._isOpenPBRMaterial()?t.CUSTOM_FRAGMENT_BEFORE_IBLLAYERCOMPOSITION="\n #ifdef RENDER_WITH_IBL_SHADOWS\n #ifndef UNLIT\n #ifdef REFLECTION\n #ifdef COLORED_IBL_SHADOWS\n var shadowValue: vec3f = computeIndirectShadow();\n ambient_occlusion = min(ambient_occlusion, shadowValue);\n #else\n var shadowValue: vec2f = computeIndirectShadow();\n ambient_occlusion = min(ambient_occlusion, vec3f(shadowValue.x));\n specular_ambient_occlusion = min(specular_ambient_occlusion, pow(shadowValue.y, 4.0));\n #endif\n #endif\n #else\n ambient_occlusion = min(ambient_occlusion, vec3f(computeIndirectShadow().x));\n #endif\n #endif\n ":t.CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR="\n #ifdef RENDER_WITH_IBL_SHADOWS\n #ifdef COLORED_IBL_SHADOWS\n var shadowValue: vec3f = computeIndirectShadow();\n color *= toGammaSpace(vec4f(shadowValue, 1.0f));\n #else\n var shadowValue: vec2f = computeIndirectShadow();\n color *= toGammaSpace(vec4f(shadowValue.x, shadowValue.x, shadowValue.x, 1.0f));\n #endif\n #endif\n "):(t={CUSTOM_FRAGMENT_DEFINITIONS:"\n #ifdef RENDER_WITH_IBL_SHADOWS\n uniform sampler2D iblShadowsTexture;\n #ifdef COLORED_IBL_SHADOWS\n vec3 computeIndirectShadow() {\n vec2 uv = gl_FragCoord.xy / renderTargetSize;\n vec3 shadowValue = texture2D(iblShadowsTexture, uv).rgb;\n return mix(shadowValue.rgb, vec3(1.0), 1.0 - shadowOpacity);\n }\n #else\n vec2 computeIndirectShadow() {\n vec2 uv = gl_FragCoord.xy / renderTargetSize;\n vec2 shadowValue = texture2D(iblShadowsTexture, uv).rg;\n return mix(shadowValue.rg, vec2(1.0), 1.0 - shadowOpacity);\n }\n #endif\n #endif\n "},this._material instanceof C?t.CUSTOM_FRAGMENT_BEFORE_FINALCOLORCOMPOSITION="\n #ifdef RENDER_WITH_IBL_SHADOWS\n #ifndef UNLIT\n #ifdef REFLECTION\n #ifdef COLORED_IBL_SHADOWS\n vec3 shadowValue = computeIndirectShadow();\n finalIrradiance.rgb *= shadowValue.rgb;\n finalRadianceScaled *= mix(vec3(1.0), shadowValue.rgb, roughness);\n #else\n vec2 shadowValue = computeIndirectShadow();\n finalIrradiance *= shadowValue.x;\n finalRadianceScaled *= mix(pow(shadowValue.y, 4.0), shadowValue.x, roughness);\n #endif\n #endif\n #else\n finalDiffuse *= computeIndirectShadow().x;\n #endif\n #endif\n ":this._isOpenPBRMaterial()?t.CUSTOM_FRAGMENT_BEFORE_IBLLAYERCOMPOSITION="\n #ifdef RENDER_WITH_IBL_SHADOWS\n #ifndef UNLIT\n #ifdef REFLECTION\n #ifdef COLORED_IBL_SHADOWS\n vec3 shadowValue = computeIndirectShadow();\n ambient_occlusion = min(ambient_occlusion, shadowValue);\n #else\n vec2 shadowValue = computeIndirectShadow();\n ambient_occlusion = min(ambient_occlusion, vec3(shadowValue.x));\n specular_ambient_occlusion = min(specular_ambient_occlusion, pow(shadowValue.y, 4.0));\n #endif\n #endif\n #else\n ambient_occlusion = min(ambient_occlusion, vec3(computeIndirectShadow().x));\n #endif\n #endif\n ":t.CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR="\n #ifdef RENDER_WITH_IBL_SHADOWS\n #ifdef COLORED_IBL_SHADOWS\n vec3 shadowValue = computeIndirectShadow();\n color.rgb *= toGammaSpace(shadowValue.rgb);\n #else\n vec2 shadowValue = computeIndirectShadow();\n color.rgb *= toGammaSpace(shadowValue.x);\n #endif\n #endif\n "),"vertex"===e?null:t}},s=new WeakMap,(()=>{const s="function"==typeof Symbol&&Symbol.metadata?Object.create(a[Symbol.metadata]??null):void 0;t=[b()],i=[b(),P("_markAllSubMeshesAsTexturesDirty")],f(e,null,i,{kind:"accessor",name:"isEnabled",static:!1,private:!1,access:{has:e=>"isEnabled"in e,get:e=>e.isEnabled,set:(e,s)=>{e.isEnabled=s}},metadata:s},h,l),f(null,null,t,{kind:"field",name:"shadowOpacity",static:!1,private:!1,access:{has:e=>"shadowOpacity"in e,get:e=>e.shadowOpacity,set:(e,s)=>{e.shadowOpacity=s}},metadata:s},r,n),s&&Object.defineProperty(e,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:s})})(),e.Name="IBLShadowsPluginMaterial",e})();class H extends D{resetAccumulation(){this._accumulationPass.reset=!0}get shadowOpacity(){return this._shadowOpacity}set shadowOpacity(e){this._shadowOpacity=e,this._setPluginParameters()}get coloredShadows(){return this._coloredShadows}set coloredShadows(e){this._coloredShadows=e,this._voxelTracingPass.coloredShadows=e,this._setPluginParameters()}get shadowRenderSizeFactor(){return this._renderSizeFactor}set shadowRenderSizeFactor(e){this._renderSizeFactor=Math.max(Math.min(e,1),0),this._voxelTracingPass.resize(e),this._spatialBlurPass.resize(e),this._accumulationPass.resize(e),this._setPluginParameters()}get voxelShadowOpacity(){return this._voxelTracingPass?.voxelShadowOpacity}set voxelShadowOpacity(e){this._voxelTracingPass&&(this._voxelTracingPass.voxelShadowOpacity=e)}get ssShadowOpacity(){return this._voxelTracingPass?.ssShadowOpacity}set ssShadowOpacity(e){this._voxelTracingPass&&(this._voxelTracingPass.ssShadowOpacity=e)}get ssShadowSampleCount(){return this._voxelTracingPass?.sssSamples}set ssShadowSampleCount(e){this._voxelTracingPass&&(this._voxelTracingPass.sssSamples=e)}get ssShadowStride(){return this._voxelTracingPass?.sssStride}set ssShadowStride(e){this._voxelTracingPass&&(this._voxelTracingPass.sssStride=e)}get ssShadowDistanceScale(){return this._sssMaxDistScale}set ssShadowDistanceScale(e){this._sssMaxDistScale=e,this._updateSsShadowParams()}get ssShadowThicknessScale(){return this._sssThicknessScale}set ssShadowThicknessScale(e){this._sssThicknessScale=e,this._updateSsShadowParams()}_getVoxelGridTexture(){const e=this._voxelRenderer?.getVoxelGrid();return e&&e.isReady()?e:this._dummyTexture3d}_getNoiseTexture(){const e=this._noiseTexture;return e&&e.isReady()?e:this._dummyTexture2d}_getVoxelTracingTexture(){const e=this._voxelTracingPass?.getOutputTexture();return e&&e.isReady()?e:this._dummyTexture2d}_getSpatialBlurTexture(){const e=this._spatialBlurPass.getOutputTexture();return e&&e.isReady()?e:this._dummyTexture2d}_getAccumulatedTexture(){const e=this._accumulationPass?.getOutputTexture();return e&&e.isReady()?e:this._dummyTexture2d}get gbufferDebugEnabled(){return this._gbufferDebugEnabled}set gbufferDebugEnabled(e){!e||this.allowDebugPasses?(this._gbufferDebugEnabled=e,e?this._enableEffect(this._getGBufferDebugPass().name,this.cameras):this._disableEffect(this._getGBufferDebugPass().name,this.cameras)):i.Warn("Can't enable G-Buffer debug view without setting allowDebugPasses to true.")}get cdfDebugEnabled(){return!!this.scene.iblCdfGenerator&&this.scene.iblCdfGenerator.debugEnabled}set cdfDebugEnabled(e){this.scene.iblCdfGenerator&&(!e||this.allowDebugPasses?e!==this.scene.iblCdfGenerator.debugEnabled&&(this.scene.iblCdfGenerator.debugEnabled=e,e?this._enableEffect(this.scene.iblCdfGenerator.debugPassName,this.cameras):this._disableEffect(this.scene.iblCdfGenerator.debugPassName,this.cameras)):i.Warn("Can't enable importance sampling debug view without setting allowDebugPasses to true."))}get voxelTracingDebugEnabled(){return this._voxelTracingPass?.debugEnabled}set voxelTracingDebugEnabled(e){this._voxelTracingPass&&(!e||this.allowDebugPasses?e!==this._voxelTracingPass.debugEnabled&&(this._voxelTracingPass.debugEnabled=e,e?this._enableEffect(this._voxelTracingPass.debugPassName,this.cameras):this._disableEffect(this._voxelTracingPass.debugPassName,this.cameras)):i.Warn("Can't enable voxel tracing debug view without setting allowDebugPasses to true."))}get spatialBlurPassDebugEnabled(){return this._spatialBlurPass.debugEnabled}set spatialBlurPassDebugEnabled(e){this._spatialBlurPass&&(!e||this.allowDebugPasses?e!==this._spatialBlurPass.debugEnabled&&(this._spatialBlurPass.debugEnabled=e,e?this._enableEffect(this._spatialBlurPass.debugPassName,this.cameras):this._disableEffect(this._spatialBlurPass.debugPassName,this.cameras)):i.Warn("Can't enable spatial blur debug view without setting allowDebugPasses to true."))}get accumulationPassDebugEnabled(){return this._accumulationPass?.debugEnabled}set accumulationPassDebugEnabled(e){this._accumulationPass&&(!e||this.allowDebugPasses?e!==this._accumulationPass.debugEnabled&&(this._accumulationPass.debugEnabled=e,e?this._enableEffect(this._accumulationPass.debugPassName,this.cameras):this._disableEffect(this._a