@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.
3 lines • 101 kB
JavaScript
import{h as e,C as t,T as s,P as i,O as r,M as a,i as n,L as o,a as l,E as h,j as d,k as u,V as _,S as c,l as g,m as f,n as p,o as m,p as T,q as x,r as E,s as b,t as P,A as R,_ as v,U as S,b as y,u as M,v as D,w as I,x as w,y as O,z as A,R as C,D as B,F as N,G as V,Q as L}from"./index-yNtOWHHe.esm.min.js";import{ShaderMaterial as U}from"./shaderMaterial-BYjGkKg9.esm.min.js";import"./engine.multiRender-DBPeBy46.esm.min.js";import{P as G}from"./iblCdfGenerator-DSqpfGUa.esm.min.js";import"./bumpFragment-C-x9aSQv.esm.min.js";import"./helperFunctions-9xvgSBwn.esm.min.js";import"./sceneUboDeclaration-DxcaNt9h.esm.min.js";import"./bumpVertex-B-7uTjQW.esm.min.js";import{R as F}from"./rawTexture-BOCcQuA1.esm.min.js";import{S as W}from"./standardMaterial-DbW5onZc.esm.min.js";import"./iblCdfGeneratorSceneComponent-fb0_e1-U.esm.min.js";class X extends e{get isSupported(){return this._engine?.getCaps().drawBuffersExtension??!1}get textures(){return this._textures}get count(){return this._count}get depthTexture(){return this._textures[this._textures.length-1]}set wrapU(e){if(this._textures)for(let t=0;t<this._textures.length;t++)this._textures[t].wrapU=e}set wrapV(e){if(this._textures)for(let t=0;t<this._textures.length;t++)this._textures[t].wrapV=e}constructor(e,s,i,r,a,n){const o=!(!a||!a.generateMipMaps)&&a.generateMipMaps,l=!(!a||!a.generateDepthTexture)&&a.generateDepthTexture,h=a&&a.depthTextureFormat?a.depthTextureFormat:t.TEXTUREFORMAT_DEPTH16,d=!a||void 0===a.doNotChangeAspectRatio||a.doNotChangeAspectRatio,u=!(!a||!a.drawOnlyOnFirstAttachmentByDefault)&&a.drawOnlyOnFirstAttachmentByDefault;if(super(e,s,r,o,d,void 0,void 0,void 0,void 0,void 0,void 0,void 0,!0),!this.isSupported)return void this.dispose();this._textureNames=n;const _=[],c=[],g=[],f=[],p=[],m=[],T=[],x=[];this._initTypes(i,_,c,g,f,p,m,T,x,a);const E=!a||void 0===a.generateDepthBuffer||a.generateDepthBuffer,b=!(!a||void 0===a.generateStencilBuffer)&&a.generateStencilBuffer,P=a&&a.samples?a.samples:1;this._multiRenderTargetOptions={samplingModes:c,generateMipMaps:o,generateDepthBuffer:E,generateStencilBuffer:b,generateDepthTexture:l,depthTextureFormat:h,types:_,textureCount:i,useSRGBBuffers:g,samples:P,formats:f,targetTypes:p,faceIndex:m,layerIndex:T,layerCounts:x,labels:n,label:e},this._count=i,this._drawOnlyOnFirstAttachmentByDefault=u,i>0&&(this._createInternalTextures(),this._createTextures(n))}_initTypes(e,i,r,a,n,o,l,h,d,u){for(let _=0;_<e;_++)u&&u.types&&void 0!==u.types[_]?i.push(u.types[_]):i.push(u&&u.defaultType?u.defaultType:t.TEXTURETYPE_UNSIGNED_BYTE),u&&u.samplingModes&&void 0!==u.samplingModes[_]?r.push(u.samplingModes[_]):r.push(s.BILINEAR_SAMPLINGMODE),u&&u.useSRGBBuffers&&void 0!==u.useSRGBBuffers[_]?a.push(u.useSRGBBuffers[_]):a.push(!1),u&&u.formats&&void 0!==u.formats[_]?n.push(u.formats[_]):n.push(t.TEXTUREFORMAT_RGBA),u&&u.targetTypes&&void 0!==u.targetTypes[_]?o.push(u.targetTypes[_]):o.push(t.TEXTURE_2D),u&&u.faceIndex&&void 0!==u.faceIndex[_]?l.push(u.faceIndex[_]):l.push(0),u&&u.layerIndex&&void 0!==u.layerIndex[_]?h.push(u.layerIndex[_]):h.push(0),u&&u.layerCounts&&void 0!==u.layerCounts[_]?d.push(u.layerCounts[_]):d.push(1)}_createInternaTextureIndexMapping(){const e={},t=[];if(!this._renderTarget)return t;const s=this._renderTarget.textures;for(let i=0;i<s.length;i++){const r=s[i];if(!r)continue;const a=e[r.uniqueId];void 0!==a?t[i]=a:e[r.uniqueId]=i}return t}_rebuild(e=!1,t=!1,s){if(this._count<1||e)return;const i=this._createInternaTextureIndexMapping();this.releaseInternalTextures(),this._createInternalTextures(),t&&(this._releaseTextures(),this._createTextures(s));const r=this._renderTarget.textures;for(let e=0;e<r.length;e++){const t=this._textures[e];void 0!==i[e]&&this._renderTarget.setTexture(r[i[e]],e),t._texture=r[e],t._texture&&(t._noMipmap=!t._texture.useMipMaps,t._useSRGBBuffer=t._texture._useSRGBBuffer)}1!==this.samples&&this._renderTarget.setSamples(this.samples,!this._drawOnlyOnFirstAttachmentByDefault,!0)}_createInternalTextures(){this._renderTarget=this._getEngine().createMultipleRenderTarget(this._size,this._multiRenderTargetOptions,!this._drawOnlyOnFirstAttachmentByDefault),this._texture=this._renderTarget.texture}_releaseTextures(){if(this._textures)for(let e=0;e<this._textures.length;e++)this._textures[e]._texture=null,this._textures[e].dispose()}_createTextures(e){const t=this._renderTarget.textures;this._textures=[];for(let i=0;i<t.length;i++){const r=new s(null,this.getScene());e?.[i]&&(r.name=e[i]),r._texture=t[i],r._texture&&(r._noMipmap=!r._texture.useMipMaps,r._useSRGBBuffer=r._texture._useSRGBBuffer),this._textures.push(r)}}setInternalTexture(e,i,r=!0){if(this.renderTarget&&(0===i&&(this._texture=e),this.renderTarget.setTexture(e,i,r),this.textures[i]||(this.textures[i]=new s(null,this.getScene()),this.textures[i].name=this._textureNames?.[i]??this.textures[i].name),this.textures[i]._texture=e,this.textures[i]._noMipmap=!e.useMipMaps,this.textures[i]._useSRGBBuffer=e._useSRGBBuffer,this._count=this.renderTarget.textures?this.renderTarget.textures.length:0,this._multiRenderTargetOptions.types&&(this._multiRenderTargetOptions.types[i]=e.type),this._multiRenderTargetOptions.samplingModes&&(this._multiRenderTargetOptions.samplingModes[i]=e.samplingMode),this._multiRenderTargetOptions.useSRGBBuffers&&(this._multiRenderTargetOptions.useSRGBBuffers[i]=e._useSRGBBuffer),this._multiRenderTargetOptions.targetTypes&&-1!==this._multiRenderTargetOptions.targetTypes[i])){let s=0;s=e.is2DArray?t.TEXTURE_2D_ARRAY:e.isCube?t.TEXTURE_CUBE_MAP:e.is3D?t.TEXTURE_3D:t.TEXTURE_2D,this._multiRenderTargetOptions.targetTypes[i]=s}}setLayerAndFaceIndex(e,t=-1,s=-1){this.textures[e]&&this.renderTarget&&(this._multiRenderTargetOptions.layerIndex&&(this._multiRenderTargetOptions.layerIndex[e]=t),this._multiRenderTargetOptions.faceIndex&&(this._multiRenderTargetOptions.faceIndex[e]=s),this.renderTarget.setLayerAndFaceIndex(e,t,s))}setLayerAndFaceIndices(e,t){this.renderTarget&&(this._multiRenderTargetOptions.layerIndex=e,this._multiRenderTargetOptions.faceIndex=t,this.renderTarget.setLayerAndFaceIndices(e,t))}get samples(){return this._samples}set samples(e){this._renderTarget?this._samples=this._renderTarget.setSamples(e):this._samples=e}resize(e){this._processSizeParameter(e),this._rebuild(!1,void 0,this._textureNames)}updateCount(e,t,s){this._multiRenderTargetOptions.textureCount=e,this._count=e;const i=[],r=[],a=[],n=[],o=[],l=[],h=[],d=[];this._textureNames=s,this._initTypes(e,i,r,a,n,o,l,h,d,t),this._multiRenderTargetOptions.types=i,this._multiRenderTargetOptions.samplingModes=r,this._multiRenderTargetOptions.useSRGBBuffers=a,this._multiRenderTargetOptions.formats=n,this._multiRenderTargetOptions.targetTypes=o,this._multiRenderTargetOptions.faceIndex=l,this._multiRenderTargetOptions.layerIndex=h,this._multiRenderTargetOptions.layerCounts=d,this._multiRenderTargetOptions.labels=s,this._rebuild(!1,!0,s)}_unbindFrameBuffer(e,t){this._renderTarget&&e.unBindMultiColorAttachmentFramebuffer(this._renderTarget,this.isCube,(()=>{this.onAfterRenderObservable.notifyObservers(t)}))}dispose(e=!1){this._releaseTextures(),e?this._texture=null:this.releaseInternalTextures(),super.dispose()}releaseInternalTextures(){const e=this._renderTarget?.textures;if(e){for(let t=e.length-1;t>=0;t--)this._textures[t]._texture=null;this._renderTarget?.dispose(),this._renderTarget=null}}}class z{getVoxelGrid(){return this._triPlanarVoxelization?this._voxelGridRT:this._voxelGridZaxis}getDebugPassPP(){return this._voxelDebugPass||this._createDebugPass(),this._voxelDebugPass}get triPlanarVoxelization(){return this._triPlanarVoxelization}set triPlanarVoxelization(e){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())}set voxelDebugAxis(e){this._voxelDebugAxis=e}get voxelDebugAxis(){return this._voxelDebugAxis}setDebugDisplayParams(e,t,s,i){this._debugSizeParams.set(e,t,s,i)}setDebugMipNumber(e){this._debugMipNumber=e}get debugPassName(){return this._debugPassName}get voxelDebugEnabled(){return this._voxelDebugEnabled}set voxelDebugEnabled(s){this._voxelDebugEnabled!==s&&(this._voxelDebugEnabled=s,s&&(this._voxelSlabDebugRT=new e("voxelSlabDebug",{width:this._engine.getRenderWidth(),height:this._engine.getRenderHeight()},this._scene,{generateDepthBuffer:!0,generateMipMaps:!1,type:t.TEXTURETYPE_UNSIGNED_BYTE,format:t.TEXTUREFORMAT_RGBA,samplingMode:t.TEXTURE_NEAREST_SAMPLINGMODE}),this._voxelSlabDebugRT.noPrePassRenderer=!0),this._voxelSlabDebugRT&&this._removeVoxelRTs([this._voxelSlabDebugRT]),this._voxelDebugEnabled?(this._addRTsForRender([this._voxelSlabDebugRT],this._includedMeshes,this._voxelDebugAxis,1,!0),this._setDebugBindingsBound=this._setDebugBindings.bind(this),this._scene.onBeforeRenderObservable.add(this._setDebugBindingsBound)):this._scene.onBeforeRenderObservable.removeCallback(this._setDebugBindingsBound))}_createDebugPass(){const e=this._engine.isWebGPU;if(!this._voxelDebugPass){const s={width:this._engine.getRenderWidth(),height:this._engine.getRenderHeight(),textureFormat:t.TEXTUREFORMAT_RGBA,textureType:t.TEXTURETYPE_UNSIGNED_BYTE,samplingMode:t.TEXTURE_NEAREST_SAMPLINGMODE,uniforms:["sizeParams","mipNumber"],samplers:["voxelTexture","voxelSlabTexture"],engine:this._engine,reusable:!1,shaderLanguage:e?1:0,extraInitializations:(e,t)=>{this._isVoxelGrid3D?e?t.push(import("./iblVoxelGrid3dDebug.fragment-Chhu5N3X.esm.min.js")):t.push(import("./iblVoxelGrid3dDebug.fragment-DAoM5jXx.esm.min.js")):e?t.push(import("./iblVoxelGrid2dArrayDebug.fragment-C_AvSE5e.esm.min.js")):t.push(import("./iblVoxelGrid2dArrayDebug.fragment-Ciy5Vrkx.esm.min.js"))}};this._voxelDebugPass=new i(this.debugPassName,this._isVoxelGrid3D?"iblVoxelGrid3dDebug":"iblVoxelGrid2dArrayDebug",s),this._voxelDebugPass.onApplyObservable.add((e=>{0===this._voxelDebugAxis?e.setTexture("voxelTexture",this._voxelGridXaxis):1===this._voxelDebugAxis?e.setTexture("voxelTexture",this._voxelGridYaxis):2===this._voxelDebugAxis?e.setTexture("voxelTexture",this._voxelGridZaxis):e.setTexture("voxelTexture",this.getVoxelGrid()),e.setTexture("voxelSlabTexture",this._voxelSlabDebugRT),e.setVector4("sizeParams",this._debugSizeParams),e.setFloat("mipNumber",this._debugMipNumber)}))}}constructor(e,t,s=6,i=!0){this._voxelMrtsXaxis=[],this._voxelMrtsYaxis=[],this._voxelMrtsZaxis=[],this._isVoxelGrid3D=!0,this.onVoxelizationCompleteObservable=new r,this._renderTargets=[],this._triPlanarVoxelization=!0,this._voxelizationInProgress=!1,this._invWorldScaleMatrix=a.Identity(),this._voxelResolution=64,this._voxelResolutionExp=6,this._mipArray=[],this._voxelDebugEnabled=!1,this._voxelDebugAxis=-1,this._debugSizeParams=new n(0,0,0,0),this._includedMeshes=[],this._debugMipNumber=0,this._debugPassName="Voxelization Debug Pass",this._scene=e,this._engine=e.getEngine(),this._triPlanarVoxelization=i,this._engine.getCaps().drawBuffersExtension||o.Error("Can't do voxel rendering without the draw buffers extension.");const d=this._engine.isWebGPU;this._maxDrawBuffers=this._engine.getCaps().maxDrawBuffers||0,this._copyMipEffectRenderer=new l(this._engine),this._copyMipEffectWrapper=new h({engine:this._engine,fragmentShader:"copyTexture3DLayerToTexture",useShaderStore:!0,uniformNames:["layerNum"],samplerNames:["textureSampler"],shaderLanguage:d?1:0,extraInitializationsAsync:async()=>{d?await import("./copyTexture3DLayerToTexture.fragment-DAeMT_nd.esm.min.js"):await import("./copyTexture3DLayerToTexture.fragment-BDH4zeeB.esm.min.js")}}),this.voxelResolutionExp=s}_generateMipMaps(){const e=Math.ceil(Math.log2(this._voxelResolution));for(let t=1;t<e+1;t++)this._generateMipMap(t)}_generateMipMap(e){const t=this._mipArray[e-1];t&&(t.setTexture("srcMip",1===e?this.getVoxelGrid():this._mipArray[e-2]),t.render())}_copyMipMaps(){const e=Math.ceil(Math.log2(this._voxelResolution));for(let t=1;t<e+1;t++)this._copyMipMap(t)}_copyMipMap(t){const s=this._mipArray[t-1];if(!s)return;const i=this.getVoxelGrid();let r;if(r=i instanceof e&&i.renderTarget?i.renderTarget:i._rtWrapper,r){this._copyMipEffectRenderer.saveStates();const e=s.getSize().width;for(let i=0;i<e;i++)this._engine.bindFramebuffer(r,0,e,e,!0,t,i),this._copyMipEffectRenderer.applyEffectWrapper(this._copyMipEffectWrapper),this._copyMipEffectWrapper.effect.setTexture("textureSampler",s),this._copyMipEffectWrapper.effect.setInt("layerNum",i),this._copyMipEffectRenderer.draw(),this._engine.unBindFramebuffer(r,!0);this._copyMipEffectRenderer.restoreStates()}}_computeNumberOfSlabs(){return Math.ceil(this._voxelResolution/this._maxDrawBuffers)}_createTextures(){const i=this._engine.isWebGPU,r={width:this._voxelResolution,height:this._voxelResolution,layers:this._isVoxelGrid3D?void 0:this._voxelResolution,depth:this._isVoxelGrid3D?this._voxelResolution:void 0},a={generateDepthBuffer:!1,generateMipMaps:!1,type:t.TEXTURETYPE_UNSIGNED_BYTE,format:t.TEXTUREFORMAT_R,samplingMode:t.TEXTURE_NEAREST_SAMPLINGMODE},n=this._computeNumberOfSlabs(),o={generateDepthBuffer:!1,generateMipMaps:!0,type:t.TEXTURETYPE_UNSIGNED_BYTE,format:t.TEXTUREFORMAT_R,samplingMode:t.TEXTURE_NEAREST_NEAREST_MIPNEAREST,shaderLanguage:i?1:0,extraInitializationsAsync:async()=>{i?await import("./iblCombineVoxelGrids.fragment-MclIqF-Q.esm.min.js"):await import("./iblCombineVoxelGrids.fragment-DJrXmQia.esm.min.js")}};this._triPlanarVoxelization?(this._voxelGridXaxis=new e("voxelGridXaxis",r,this._scene,a),this._voxelGridYaxis=new e("voxelGridYaxis",r,this._scene,a),this._voxelGridZaxis=new e("voxelGridZaxis",r,this._scene,a),this._voxelMrtsXaxis=this._createVoxelMRTs("x_axis_",this._voxelGridXaxis,n),this._voxelMrtsYaxis=this._createVoxelMRTs("y_axis_",this._voxelGridYaxis,n),this._voxelMrtsZaxis=this._createVoxelMRTs("z_axis_",this._voxelGridZaxis,n),this._voxelGridRT=new G("combinedVoxelGrid",r,"iblCombineVoxelGrids",this._scene,o,!1),this._scene.proceduralTextures.splice(this._scene.proceduralTextures.indexOf(this._voxelGridRT),1),this._voxelGridRT.setFloat("layer",0),this._voxelGridRT.setTexture("voxelXaxisSampler",this._voxelGridXaxis),this._voxelGridRT.setTexture("voxelYaxisSampler",this._voxelGridYaxis),this._voxelGridRT.setTexture("voxelZaxisSampler",this._voxelGridZaxis),this._voxelGridRT.autoClear=!1,this._voxelGridRT.wrapU=s.CLAMP_ADDRESSMODE,this._voxelGridRT.wrapV=s.CLAMP_ADDRESSMODE):(this._voxelGridZaxis=new e("voxelGridZaxis",r,this._scene,o),this._voxelMrtsZaxis=this._createVoxelMRTs("z_axis_",this._voxelGridZaxis,n));const l={generateDepthBuffer:!1,generateMipMaps:!1,type:t.TEXTURETYPE_UNSIGNED_BYTE,format:t.TEXTUREFORMAT_R,samplingMode:t.TEXTURE_NEAREST_SAMPLINGMODE,shaderLanguage:i?1:0,extraInitializationsAsync:async()=>{i?await import("./iblGenerateVoxelMip.fragment-CSakBcH0.esm.min.js"):await import("./iblGenerateVoxelMip.fragment-DdEGKI3E.esm.min.js")}};this._mipArray=new Array(Math.ceil(Math.log2(this._voxelResolution)));for(let e=1;e<=this._mipArray.length;e++){const t=this._voxelResolution>>e,i={width:t,height:t,depth:t};this._mipArray[e-1]=new G("voxelMip"+e,i,"iblGenerateVoxelMip",this._scene,l,!1),this._scene.proceduralTextures.splice(this._scene.proceduralTextures.indexOf(this._mipArray[e-1]),1);const r=this._mipArray[e-1];r.autoClear=!1,r.wrapU=s.CLAMP_ADDRESSMODE,r.wrapV=s.CLAMP_ADDRESSMODE,r.setTexture("srcMip",e>1?this._mipArray[e-2]:this.getVoxelGrid()),r.setInt("layerNum",0)}this._createVoxelMaterials()}_createVoxelMRTs(e,i,r){i.wrapU=s.CLAMP_ADDRESSMODE,i.wrapV=s.CLAMP_ADDRESSMODE,i.noPrePassRenderer=!0;const a=[],n=new Array(this._maxDrawBuffers).fill(this._isVoxelGrid3D?t.TEXTURE_3D:t.TEXTURE_2D_ARRAY);for(let s=0;s<r;s++){let r=new Array(this._maxDrawBuffers).fill(0);r=r.map(((e,t)=>s*this._maxDrawBuffers+t));let o=new Array(this._maxDrawBuffers).fill("");o=o.map(((t,i)=>"voxel_grid_"+e+(s*this._maxDrawBuffers+i)));const l=new X("mrt_"+e+s,{width:this._voxelResolution,height:this._voxelResolution,depth:this._isVoxelGrid3D?this._voxelResolution:void 0},this._maxDrawBuffers,this._scene,{types:new Array(this._maxDrawBuffers).fill(t.TEXTURETYPE_UNSIGNED_BYTE),samplingModes:new Array(this._maxDrawBuffers).fill(t.TEXTURE_TRILINEAR_SAMPLINGMODE),generateMipMaps:!1,targetTypes:n,formats:new Array(this._maxDrawBuffers).fill(t.TEXTUREFORMAT_R),faceIndex:new Array(this._maxDrawBuffers).fill(0),layerIndex:r,layerCounts:new Array(this._maxDrawBuffers).fill(this._voxelResolution),generateDepthBuffer:!1,generateStencilBuffer:!1},o);l.clearColor=new d(0,0,0,1),l.noPrePassRenderer=!0;for(let e=0;e<this._maxDrawBuffers;e++)l.setInternalTexture(i.getInternalTexture(),e);a.push(l)}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._voxelGridRT?.dispose()),this._voxelGridZaxis?.dispose();for(const e of this._mipArray)e.dispose();this._voxelMaterial?.dispose(),this._voxelSlabDebugMaterial?.dispose(),this._mipArray=[],this._voxelMrtsXaxis=[],this._voxelMrtsYaxis=[],this._voxelMrtsZaxis=[]}_createVoxelMaterials(){const e=this._engine.isWebGPU;this._voxelMaterial=new U("voxelization",this._scene,"iblVoxelGrid",{uniforms:["world","viewMatrix","invWorldScale","nearPlane","farPlane","stepSize"],defines:["MAX_DRAW_BUFFERS "+this._maxDrawBuffers],shaderLanguage:e?1:0,extraInitializationsAsync:async()=>{e?await Promise.all([import("./iblVoxelGrid.fragment-q97tUlTy.esm.min.js"),import("./iblVoxelGrid.vertex-BTAxR26N.esm.min.js")]):await Promise.all([import("./iblVoxelGrid.fragment-B6i5XfoH.esm.min.js"),import("./iblVoxelGrid.vertex-SfqHHvnQ.esm.min.js")])}}),this._voxelMaterial.cullBackFaces=!1,this._voxelMaterial.backFaceCulling=!1,this._voxelMaterial.depthFunction=u.ALWAYS,this._voxelSlabDebugMaterial=new U("voxelSlabDebug",this._scene,"iblVoxelSlabDebug",{uniforms:["world","viewMatrix","cameraViewMatrix","projection","invWorldScale","nearPlane","farPlane","stepSize"],defines:["MAX_DRAW_BUFFERS "+this._maxDrawBuffers],shaderLanguage:e?1:0,extraInitializationsAsync:async()=>{e?await Promise.all([import("./iblVoxelSlabDebug.fragment-CULRVrs5.esm.min.js"),import("./iblVoxelSlabDebug.vertex-CREQZdx8.esm.min.js")]):await Promise.all([import("./iblVoxelSlabDebug.fragment-C0cj6xJO.esm.min.js"),import("./iblVoxelSlabDebug.vertex-DTXrzsnu.esm.min.js")])}})}_setDebugBindings(){this._voxelSlabDebugMaterial.setMatrix("projection",this._scene.activeCamera.getProjectionMatrix()),this._voxelSlabDebugMaterial.setMatrix("cameraViewMatrix",this._scene.activeCamera.getViewMatrix())}isReady(){let e=this.getVoxelGrid().isReady();for(let t=0;t<this._mipArray.length;t++){const s=this._mipArray[t].isReady();e&&=s}return!(!e||this._voxelizationInProgress)}_stopVoxelization(){this._removeVoxelRTs(this._voxelMrtsXaxis),this._removeVoxelRTs(this._voxelMrtsYaxis),this._removeVoxelRTs(this._voxelMrtsZaxis)}_removeVoxelRTs(e){const t=this._renderTargets.findIndex((t=>t===e[0]));if(t>=0)this._renderTargets.splice(t,e.length);else{const t=this._scene.customRenderTargets.findIndex((t=>t===e[0]));t>=0&&this._scene.customRenderTargets.splice(t,e.length)}}updateVoxelGrid(e){this._stopVoxelization(),this._includedMeshes=e,this._voxelizationInProgress=!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),this._voxelDebugEnabled&&this._addRTsForRender([this._voxelSlabDebugRT],e,this._voxelDebugAxis,1,!0),this._renderVoxelGridBound=this._renderVoxelGrid.bind(this),this._scene.onAfterRenderObservable.add(this._renderVoxelGridBound)}_renderVoxelGrid(){if(this._voxelizationInProgress){let e=this.getVoxelGrid().isReady();for(let t=0;t<this._mipArray.length;t++){const s=this._mipArray[t].isReady();e&&=s}for(let t=0;t<this._renderTargets.length;t++){const s=this._renderTargets[t].isReadyForRendering();e&&=s}if(e){for(const e of this._renderTargets)e.render();this._stopVoxelization(),this._triPlanarVoxelization&&this._voxelGridRT.render(),this._generateMipMaps(),this._copyMipEffectWrapper.effect.whenCompiledAsync().then((()=>{this._copyMipMaps(),this._scene.onAfterRenderObservable.removeCallback(this._renderVoxelGridBound),this._voxelizationInProgress=!1,this.onVoxelizationCompleteObservable.notifyObservers()}))}}}_addRTsForRender(e,t,s,i=0,r=!1){const n=1/this._computeNumberOfSlabs();let o;o=0===i?this._voxelMaterial:this._voxelSlabDebugMaterial;for(let i=0;i<e.length;i++){const r=e[i];r.renderList=[];const l=i*n,h=(i+1)*n,d=n/this._maxDrawBuffers,u=new _(0,0,0);let c=new _(0,0,1);0===s?c=new _(1,0,0):1===s&&(c=new _(0,1,0));let g=new _(0,1,0);if(1===s&&(g=new _(1,0,0)),r.onBeforeRenderObservable.add((()=>{o.setMatrix("viewMatrix",a.LookAtLH(u,c,g)),o.setMatrix("invWorldScale",this._invWorldScaleMatrix),o.setFloat("nearPlane",l),o.setFloat("farPlane",h),o.setFloat("stepSize",d)})),0===t.length)return;for(const e of t)if(e){e.subMeshes&&e.subMeshes.length>0&&(r.renderList?.push(e),r.setMaterialForRendering(e,o));const t=e.getChildMeshes();for(const e of t)e.subMeshes&&e.subMeshes.length>0&&(r.renderList?.push(e),r.setMaterialForRendering(e,o))}}if(r)for(const t of e)-1===this._scene.customRenderTargets.indexOf(t)&&this._scene.customRenderTargets.push(t);else this._renderTargets=this._renderTargets.concat(e)}resize(){this._voxelSlabDebugRT?.resize({width:this._scene.getEngine().getRenderWidth(),height:this._scene.getEngine().getRenderHeight()})}dispose(){this._disposeVoxelTextures(),this._voxelSlabDebugRT&&(this._removeVoxelRTs([this._voxelSlabDebugRT]),this._voxelSlabDebugRT.dispose()),this._voxelDebugPass&&this._voxelDebugPass.dispose()}}const Y="mrtFragmentDeclaration";c.IncludesShadersStore[Y]||(c.IncludesShadersStore[Y]="#if defined(WEBGL2) || defined(WEBGPU) || defined(NATIVE)\nlayout(location=0) out vec4 glFragData[{X}];\n#endif\n");const H="geometryPixelShader",j="#extension GL_EXT_draw_buffers : require\n#if defined(BUMP) || !defined(NORMAL)\n#extension GL_OES_standard_derivatives : enable\n#endif\nprecision highp float;\n#ifdef BUMP\nvarying mat4 vWorldView;varying vec3 vNormalW;\n#else\nvarying vec3 vNormalV;\n#endif\nvarying vec4 vViewPos;\n#if defined(POSITION) || defined(BUMP)\nvarying vec3 vPositionW;\n#endif\n#if defined(VELOCITY) || defined(VELOCITY_LINEAR)\nvarying vec4 vCurrentPosition;varying vec4 vPreviousPosition;\n#endif\n#ifdef NEED_UV\nvarying vec2 vUV;\n#endif\n#ifdef BUMP\nuniform vec3 vBumpInfos;uniform vec2 vTangentSpaceParams;\n#endif\n#if defined(REFLECTIVITY)\n#if defined(ORMTEXTURE) || defined(SPECULARGLOSSINESSTEXTURE) || defined(REFLECTIVITYTEXTURE)\nuniform sampler2D reflectivitySampler;varying vec2 vReflectivityUV;\n#endif\n#ifdef ALBEDOTEXTURE\nvarying vec2 vAlbedoUV;uniform sampler2D albedoSampler;\n#endif\n#ifdef REFLECTIVITYCOLOR\nuniform vec3 reflectivityColor;\n#endif\n#ifdef ALBEDOCOLOR\nuniform vec3 albedoColor;\n#endif\n#ifdef METALLIC\nuniform float metallic;\n#endif\n#if defined(ROUGHNESS) || defined(GLOSSINESS)\nuniform float glossiness;\n#endif\n#endif\n#if defined(ALPHATEST) && defined(NEED_UV)\nuniform sampler2D diffuseSampler;\n#endif\n#include<clipPlaneFragmentDeclaration>\n#include<mrtFragmentDeclaration>[SCENE_MRT_COUNT]\n#include<bumpFragmentMainFunctions>\n#include<bumpFragmentFunctions>\n#include<helperFunctions>\nvoid main() {\n#include<clipPlaneFragment>\n#ifdef ALPHATEST\nif (texture2D(diffuseSampler,vUV).a<0.4)\ndiscard;\n#endif\nvec3 normalOutput;\n#ifdef BUMP\nvec3 normalW=normalize(vNormalW);\n#include<bumpFragment>\n#ifdef NORMAL_WORLDSPACE\nnormalOutput=normalW;\n#else\nnormalOutput=normalize(vec3(vWorldView*vec4(normalW,0.0)));\n#endif\n#else\nnormalOutput=normalize(vNormalV);\n#endif\n#ifdef ENCODE_NORMAL\nnormalOutput=normalOutput*0.5+0.5;\n#endif\n#ifdef DEPTH\ngl_FragData[DEPTH_INDEX]=vec4(vViewPos.z/vViewPos.w,0.0,0.0,1.0);\n#endif\n#ifdef NORMAL\ngl_FragData[NORMAL_INDEX]=vec4(normalOutput,1.0);\n#endif\n#ifdef SCREENSPACE_DEPTH\ngl_FragData[SCREENSPACE_DEPTH_INDEX]=vec4(gl_FragCoord.z,0.0,0.0,1.0);\n#endif\n#ifdef POSITION\ngl_FragData[POSITION_INDEX]=vec4(vPositionW,1.0);\n#endif\n#ifdef VELOCITY\nvec2 a=(vCurrentPosition.xy/vCurrentPosition.w)*0.5+0.5;vec2 b=(vPreviousPosition.xy/vPreviousPosition.w)*0.5+0.5;vec2 velocity=abs(a-b);velocity=vec2(pow(velocity.x,1.0/3.0),pow(velocity.y,1.0/3.0))*sign(a-b)*0.5+0.5;gl_FragData[VELOCITY_INDEX]=vec4(velocity,0.0,1.0);\n#endif\n#ifdef VELOCITY_LINEAR\nvec2 velocity=vec2(0.5)*((vPreviousPosition.xy/vPreviousPosition.w) -\n(vCurrentPosition.xy/vCurrentPosition.w));gl_FragData[VELOCITY_LINEAR_INDEX]=vec4(velocity,0.0,1.0);\n#endif\n#ifdef REFLECTIVITY\nvec4 reflectivity=vec4(0.0,0.0,0.0,1.0);\n#ifdef METALLICWORKFLOW\nfloat metal=1.0;float roughness=1.0;\n#ifdef ORMTEXTURE\nmetal*=texture2D(reflectivitySampler,vReflectivityUV).b;roughness*=texture2D(reflectivitySampler,vReflectivityUV).g;\n#endif\n#ifdef METALLIC\nmetal*=metallic;\n#endif\n#ifdef ROUGHNESS\nroughness*=(1.0-glossiness); \n#endif\nreflectivity.a-=roughness;vec3 color=vec3(1.0);\n#ifdef ALBEDOTEXTURE\ncolor=texture2D(albedoSampler,vAlbedoUV).rgb;\n#ifdef GAMMAALBEDO\ncolor=toLinearSpace(color);\n#endif\n#endif\n#ifdef ALBEDOCOLOR\ncolor*=albedoColor.xyz;\n#endif\nreflectivity.rgb=mix(vec3(0.04),color,metal);\n#else\n#if defined(SPECULARGLOSSINESSTEXTURE) || defined(REFLECTIVITYTEXTURE)\nreflectivity=texture2D(reflectivitySampler,vReflectivityUV);\n#ifdef GAMMAREFLECTIVITYTEXTURE\nreflectivity.rgb=toLinearSpace(reflectivity.rgb);\n#endif\n#else \n#ifdef REFLECTIVITYCOLOR\nreflectivity.rgb=toLinearSpace(reflectivityColor.xyz);reflectivity.a=1.0;\n#endif\n#endif\n#ifdef GLOSSINESSS\nreflectivity.a*=glossiness; \n#endif\n#endif\ngl_FragData[REFLECTIVITY_INDEX]=reflectivity;\n#endif\n}\n";c.ShadersStore[H]||(c.ShadersStore[H]=j);const k={name:H,shader:j};var Z=Object.freeze({__proto__:null,geometryPixelShader:k});const q="geometryVertexDeclaration";c.IncludesShadersStore[q]||(c.IncludesShadersStore[q]="uniform mat4 viewProjection;uniform mat4 view;");const K="geometryUboDeclaration";c.IncludesShadersStore[K]||(c.IncludesShadersStore[K]="#include<sceneUboDeclaration>\n");const $="geometryVertexShader",Q="precision highp float;\n#include<bonesDeclaration>\n#include<bakedVertexAnimationDeclaration>\n#include<morphTargetsVertexGlobalDeclaration>\n#include<morphTargetsVertexDeclaration>[0..maxSimultaneousMorphTargets]\n#include<instancesDeclaration>\n#include<__decl__geometryVertex>\n#include<clipPlaneVertexDeclaration>\nattribute vec3 position;attribute vec3 normal;\n#ifdef NEED_UV\nvarying vec2 vUV;\n#ifdef ALPHATEST\nuniform mat4 diffuseMatrix;\n#endif\n#ifdef BUMP\nuniform mat4 bumpMatrix;varying vec2 vBumpUV;\n#endif\n#ifdef REFLECTIVITY\nuniform mat4 reflectivityMatrix;uniform mat4 albedoMatrix;varying vec2 vReflectivityUV;varying vec2 vAlbedoUV;\n#endif\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#endif\n#ifdef BUMP\nvarying mat4 vWorldView;\n#endif\n#ifdef BUMP\nvarying vec3 vNormalW;\n#else\nvarying vec3 vNormalV;\n#endif\nvarying vec4 vViewPos;\n#if defined(POSITION) || defined(BUMP)\nvarying vec3 vPositionW;\n#endif\n#if defined(VELOCITY) || defined(VELOCITY_LINEAR)\nuniform mat4 previousViewProjection;varying vec4 vCurrentPosition;varying vec4 vPreviousPosition;\n#endif\n#define CUSTOM_VERTEX_DEFINITIONS\nvoid main(void)\n{vec3 positionUpdated=position;vec3 normalUpdated=normal;\n#ifdef UV1\nvec2 uvUpdated=uv;\n#endif\n#ifdef UV2\nvec2 uv2Updated=uv2;\n#endif\n#include<morphTargetsVertexGlobal>\n#include<morphTargetsVertex>[0..maxSimultaneousMorphTargets]\n#include<instancesVertex>\n#if (defined(VELOCITY) || defined(VELOCITY_LINEAR)) && !defined(BONES_VELOCITY_ENABLED)\nvCurrentPosition=viewProjection*finalWorld*vec4(positionUpdated,1.0);vPreviousPosition=previousViewProjection*finalPreviousWorld*vec4(positionUpdated,1.0);\n#endif\n#include<bonesVertex>\n#include<bakedVertexAnimation>\nvec4 worldPos=vec4(finalWorld*vec4(positionUpdated,1.0));\n#ifdef BUMP\nvWorldView=view*finalWorld;mat3 normalWorld=mat3(finalWorld);vNormalW=normalize(normalWorld*normalUpdated);\n#else\n#ifdef NORMAL_WORLDSPACE\nvNormalV=normalize(vec3(finalWorld*vec4(normalUpdated,0.0)));\n#else\nvNormalV=normalize(vec3((view*finalWorld)*vec4(normalUpdated,0.0)));\n#endif\n#endif\nvViewPos=view*worldPos;\n#if (defined(VELOCITY) || defined(VELOCITY_LINEAR)) && defined(BONES_VELOCITY_ENABLED)\nvCurrentPosition=viewProjection*finalWorld*vec4(positionUpdated,1.0);\n#if NUM_BONE_INFLUENCERS>0\nmat4 previousInfluence;previousInfluence=mPreviousBones[int(matricesIndices[0])]*matricesWeights[0];\n#if NUM_BONE_INFLUENCERS>1\npreviousInfluence+=mPreviousBones[int(matricesIndices[1])]*matricesWeights[1];\n#endif\n#if NUM_BONE_INFLUENCERS>2\npreviousInfluence+=mPreviousBones[int(matricesIndices[2])]*matricesWeights[2];\n#endif\n#if NUM_BONE_INFLUENCERS>3\npreviousInfluence+=mPreviousBones[int(matricesIndices[3])]*matricesWeights[3];\n#endif\n#if NUM_BONE_INFLUENCERS>4\npreviousInfluence+=mPreviousBones[int(matricesIndicesExtra[0])]*matricesWeightsExtra[0];\n#endif\n#if NUM_BONE_INFLUENCERS>5\npreviousInfluence+=mPreviousBones[int(matricesIndicesExtra[1])]*matricesWeightsExtra[1];\n#endif\n#if NUM_BONE_INFLUENCERS>6\npreviousInfluence+=mPreviousBones[int(matricesIndicesExtra[2])]*matricesWeightsExtra[2];\n#endif\n#if NUM_BONE_INFLUENCERS>7\npreviousInfluence+=mPreviousBones[int(matricesIndicesExtra[3])]*matricesWeightsExtra[3];\n#endif\nvPreviousPosition=previousViewProjection*finalPreviousWorld*previousInfluence*vec4(positionUpdated,1.0);\n#else\nvPreviousPosition=previousViewProjection*finalPreviousWorld*vec4(positionUpdated,1.0);\n#endif\n#endif\n#if defined(POSITION) || defined(BUMP)\nvPositionW=worldPos.xyz/worldPos.w;\n#endif\ngl_Position=viewProjection*finalWorld*vec4(positionUpdated,1.0);\n#include<clipPlaneVertex>\n#ifdef NEED_UV\n#ifdef UV1\n#if defined(ALPHATEST) && defined(ALPHATEST_UV1)\nvUV=vec2(diffuseMatrix*vec4(uvUpdated,1.0,0.0));\n#else\nvUV=uvUpdated;\n#endif\n#ifdef BUMP_UV1\nvBumpUV=vec2(bumpMatrix*vec4(uvUpdated,1.0,0.0));\n#endif\n#ifdef REFLECTIVITY_UV1\nvReflectivityUV=vec2(reflectivityMatrix*vec4(uvUpdated,1.0,0.0));\n#endif\n#ifdef ALBEDO_UV1\nvAlbedoUV=vec2(albedoMatrix*vec4(uvUpdated,1.0,0.0));\n#endif\n#endif\n#ifdef UV2\n#if defined(ALPHATEST) && defined(ALPHATEST_UV2)\nvUV=vec2(diffuseMatrix*vec4(uv2Updated,1.0,0.0));\n#else\nvUV=uv2Updated;\n#endif\n#ifdef BUMP_UV2\nvBumpUV=vec2(bumpMatrix*vec4(uv2Updated,1.0,0.0));\n#endif\n#ifdef REFLECTIVITY_UV2\nvReflectivityUV=vec2(reflectivityMatrix*vec4(uv2Updated,1.0,0.0));\n#endif\n#ifdef ALBEDO_UV2\nvAlbedoUV=vec2(albedoMatrix*vec4(uv2Updated,1.0,0.0));\n#endif\n#endif\n#endif\n#include<bumpVertex>\n}\n";c.ShadersStore[$]||(c.ShadersStore[$]=Q);const J={name:$,shader:Q};var ee=Object.freeze({__proto__:null,geometryVertexShader:J});const te=["world","mBones","viewProjection","diffuseMatrix","view","previousWorld","previousViewProjection","mPreviousBones","bumpMatrix","reflectivityMatrix","albedoMatrix","reflectivityColor","albedoColor","metallic","glossiness","vTangentSpaceParams","vBumpInfos","morphTargetInfluences","morphTargetCount","morphTargetTextureInfo","morphTargetTextureIndices","boneTextureWidth"];R(te);class se{get normalsAreUnsigned(){return this._normalsAreUnsigned}_linkPrePassRenderer(e){this._linkedWithPrePass=!0,this._prePassRenderer=e,this._multiRenderTarget&&(this._multiRenderTarget.onClearObservable.clear(),this._multiRenderTarget.onClearObservable.add((()=>{})))}_unlinkPrePassRenderer(){this._linkedWithPrePass=!1,this._createRenderTargets()}_resetLayout(){this._enableDepth=!0,this._enableNormal=!0,this._enablePosition=!1,this._enableReflectivity=!1,this._enableVelocity=!1,this._enableVelocityLinear=!1,this._enableScreenspaceDepth=!1,this._attachmentsFromPrePass=[]}_forceTextureType(e,t){e===se.POSITION_TEXTURE_TYPE?(this._positionIndex=t,this._enablePosition=!0):e===se.VELOCITY_TEXTURE_TYPE?(this._velocityIndex=t,this._enableVelocity=!0):e===se.VELOCITY_LINEAR_TEXTURE_TYPE?(this._velocityLinearIndex=t,this._enableVelocityLinear=!0):e===se.REFLECTIVITY_TEXTURE_TYPE?(this._reflectivityIndex=t,this._enableReflectivity=!0):e===se.DEPTH_TEXTURE_TYPE?(this._depthIndex=t,this._enableDepth=!0):e===se.NORMAL_TEXTURE_TYPE?(this._normalIndex=t,this._enableNormal=!0):e===se.SCREENSPACE_DEPTH_TEXTURE_TYPE&&(this._screenspaceDepthIndex=t,this._enableScreenspaceDepth=!0)}_setAttachments(e){this._attachmentsFromPrePass=e}_linkInternalTexture(e){this._multiRenderTarget.setInternalTexture(e,0,!1)}get renderList(){return this._multiRenderTarget.renderList}set renderList(e){this._multiRenderTarget.renderList=e}get isSupported(){return this._multiRenderTarget.isSupported}getTextureIndex(e){switch(e){case se.POSITION_TEXTURE_TYPE:return this._positionIndex;case se.VELOCITY_TEXTURE_TYPE:return this._velocityIndex;case se.VELOCITY_LINEAR_TEXTURE_TYPE:return this._velocityLinearIndex;case se.REFLECTIVITY_TEXTURE_TYPE:return this._reflectivityIndex;case se.DEPTH_TEXTURE_TYPE:return this._depthIndex;case se.NORMAL_TEXTURE_TYPE:return this._normalIndex;case se.SCREENSPACE_DEPTH_TEXTURE_TYPE:return this._screenspaceDepthIndex;default:return-1}}get enableDepth(){return this._enableDepth}set enableDepth(e){this._enableDepth=e,this._linkedWithPrePass||(this.dispose(),this._createRenderTargets())}get enableNormal(){return this._enableNormal}set enableNormal(e){this._enableNormal=e,this._linkedWithPrePass||(this.dispose(),this._createRenderTargets())}get enablePosition(){return this._enablePosition}set enablePosition(e){this._enablePosition=e,this._linkedWithPrePass||(this.dispose(),this._createRenderTargets())}get enableVelocity(){return this._enableVelocity}set enableVelocity(e){this._enableVelocity=e,e||(this._previousTransformationMatrices={}),this._linkedWithPrePass||(this.dispose(),this._createRenderTargets()),this._scene.needsPreviousWorldMatrices=e}get enableVelocityLinear(){return this._enableVelocityLinear}set enableVelocityLinear(e){this._enableVelocityLinear=e,this._linkedWithPrePass||(this.dispose(),this._createRenderTargets())}get enableReflectivity(){return this._enableReflectivity}set enableReflectivity(e){this._enableReflectivity=e,this._linkedWithPrePass||(this.dispose(),this._createRenderTargets())}get enableScreenspaceDepth(){return this._enableScreenspaceDepth}set enableScreenspaceDepth(e){this._enableScreenspaceDepth=e,this._linkedWithPrePass||(this.dispose(),this._createRenderTargets())}get scene(){return this._scene}get ratio(){return"object"==typeof this._ratioOrDimensions?1:this._ratioOrDimensions}get shaderLanguage(){return this._shaderLanguage}constructor(e,s=1,i=t.TEXTUREFORMAT_DEPTH16,r){this._previousTransformationMatrices={},this._previousBonesTransformationMatrices={},this.excludedSkinnedMeshesFromVelocity=[],this.renderTransparentMeshes=!0,this.generateNormalsInWorldSpace=!1,this._normalsAreUnsigned=!1,this._resizeObserver=null,this._enableDepth=!0,this._enableNormal=!0,this._enablePosition=!1,this._enableVelocity=!1,this._enableVelocityLinear=!1,this._enableReflectivity=!1,this._enableScreenspaceDepth=!1,this._clearColor=new d(0,0,0,0),this._clearDepthColor=new d(0,0,0,1),this._positionIndex=-1,this._velocityIndex=-1,this._velocityLinearIndex=-1,this._reflectivityIndex=-1,this._depthIndex=-1,this._normalIndex=-1,this._screenspaceDepthIndex=-1,this._linkedWithPrePass=!1,this.useSpecificClearForDepthTexture=!1,this._shaderLanguage=0,this._shadersLoaded=!1,this._scene=e,this._ratioOrDimensions=s,this._useUbo=e.getEngine().supportsUniformBuffers,this._depthFormat=i,this._textureTypesAndFormats=r||{},this._initShaderSourceAsync(),se._SceneComponentInitialization(this._scene),this._createRenderTargets()}async _initShaderSourceAsync(){this._scene.getEngine().isWebGPU&&!se.ForceGLSL?(this._shaderLanguage=1,await Promise.all([import("./geometry.vertex-BnV7zu3i.esm.min.js"),import("./geometry.fragment-CB3yA5uQ.esm.min.js")])):await Promise.all([Promise.resolve().then((function(){return ee})),Promise.resolve().then((function(){return Z}))]),this._shadersLoaded=!0}isReady(e,t){if(!this._shadersLoaded)return!1;const s=e.getMaterial();if(s&&s.disableDepthWrite)return!1;const i=[],r=[f.PositionKind,f.NormalKind],a=e.getMesh();let n=!1,o=!1;if(s){let e=!1;if(s.needAlphaTestingForMesh(a)&&s.getAlphaTestTexture()&&(i.push("#define ALPHATEST"),i.push(`#define ALPHATEST_UV${s.getAlphaTestTexture().coordinatesIndex+1}`),e=!0),(s.bumpTexture||s.normalTexture)&&g.BumpTextureEnabled){const t=s.bumpTexture||s.normalTexture;i.push("#define BUMP"),i.push(`#define BUMP_UV${t.coordinatesIndex+1}`),e=!0}if(this._enableReflectivity){let t=!1;"PBRMetallicRoughnessMaterial"===s.getClassName()?(s.metallicRoughnessTexture&&(i.push("#define ORMTEXTURE"),i.push(`#define REFLECTIVITY_UV${s.metallicRoughnessTexture.coordinatesIndex+1}`),i.push("#define METALLICWORKFLOW"),e=!0,t=!0),null!=s.metallic&&(i.push("#define METALLIC"),i.push("#define METALLICWORKFLOW"),t=!0),null!=s.roughness&&(i.push("#define ROUGHNESS"),i.push("#define METALLICWORKFLOW"),t=!0),t&&(s.baseTexture&&(i.push("#define ALBEDOTEXTURE"),i.push(`#define ALBEDO_UV${s.baseTexture.coordinatesIndex+1}`),s.baseTexture.gammaSpace&&i.push("#define GAMMAALBEDO"),e=!0),s.baseColor&&i.push("#define ALBEDOCOLOR"))):"PBRSpecularGlossinessMaterial"===s.getClassName()?(s.specularGlossinessTexture?(i.push("#define SPECULARGLOSSINESSTEXTURE"),i.push(`#define REFLECTIVITY_UV${s.specularGlossinessTexture.coordinatesIndex+1}`),e=!0,s.specularGlossinessTexture.gammaSpace&&i.push("#define GAMMAREFLECTIVITYTEXTURE")):s.specularColor&&i.push("#define REFLECTIVITYCOLOR"),null!=s.glossiness&&i.push("#define GLOSSINESS")):"PBRMaterial"===s.getClassName()?(s.metallicTexture&&(i.push("#define ORMTEXTURE"),i.push(`#define REFLECTIVITY_UV${s.metallicTexture.coordinatesIndex+1}`),i.push("#define METALLICWORKFLOW"),e=!0,t=!0),null!=s.metallic&&(i.push("#define METALLIC"),i.push("#define METALLICWORKFLOW"),t=!0),null!=s.roughness&&(i.push("#define ROUGHNESS"),i.push("#define METALLICWORKFLOW"),t=!0),t?(s.albedoTexture&&(i.push("#define ALBEDOTEXTURE"),i.push(`#define ALBEDO_UV${s.albedoTexture.coordinatesIndex+1}`),s.albedoTexture.gammaSpace&&i.push("#define GAMMAALBEDO"),e=!0),s.albedoColor&&i.push("#define ALBEDOCOLOR")):(s.reflectivityTexture?(i.push("#define SPECULARGLOSSINESSTEXTURE"),i.push(`#define REFLECTIVITY_UV${s.reflectivityTexture.coordinatesIndex+1}`),s.reflectivityTexture.gammaSpace&&i.push("#define GAMMAREFLECTIVITYTEXTURE"),e=!0):s.reflectivityColor&&i.push("#define REFLECTIVITYCOLOR"),null!=s.microSurface&&i.push("#define GLOSSINESS"))):"StandardMaterial"===s.getClassName()&&(s.specularTexture&&(i.push("#define REFLECTIVITYTEXTURE"),i.push(`#define REFLECTIVITY_UV${s.specularTexture.coordinatesIndex+1}`),s.specularTexture.gammaSpace&&i.push("#define GAMMAREFLECTIVITYTEXTURE"),e=!0),s.specularColor&&i.push("#define REFLECTIVITYCOLOR"))}e&&(i.push("#define NEED_UV"),a.isVerticesDataPresent(f.UVKind)&&(r.push(f.UVKind),i.push("#define UV1"),n=!0),a.isVerticesDataPresent(f.UV2Kind)&&(r.push(f.UV2Kind),i.push("#define UV2"),o=!0))}this._enableDepth&&(i.push("#define DEPTH"),i.push("#define DEPTH_INDEX "+this._depthIndex)),this._enableNormal&&(i.push("#define NORMAL"),i.push("#define NORMAL_INDEX "+this._normalIndex)),this._enablePosition&&(i.push("#define POSITION"),i.push("#define POSITION_INDEX "+this._positionIndex)),this._enableVelocity&&(i.push("#define VELOCITY"),i.push("#define VELOCITY_INDEX "+this._velocityIndex),-1===this.excludedSkinnedMeshesFromVelocity.indexOf(a)&&i.push("#define BONES_VELOCITY_ENABLED")),this._enableVelocityLinear&&(i.push("#define VELOCITY_LINEAR"),i.push("#define VELOCITY_LINEAR_INDEX "+this._velocityLinearIndex),-1===this.excludedSkinnedMeshesFromVelocity.indexOf(a)&&i.push("#define BONES_VELOCITY_ENABLED")),this._enableReflectivity&&(i.push("#define REFLECTIVITY"),i.push("#define REFLECTIVITY_INDEX "+this._reflectivityIndex)),this._enableScreenspaceDepth&&-1!==this._screenspaceDepthIndex&&(i.push("#define SCREENSPACE_DEPTH_INDEX "+this._screenspaceDepthIndex),i.push("#define SCREENSPACE_DEPTH")),this.generateNormalsInWorldSpace&&i.push("#define NORMAL_WORLDSPACE"),this._normalsAreUnsigned&&i.push("#define ENCODE_NORMAL"),a.useBones&&a.computeBonesUsingShaders&&a.skeleton?(r.push(f.MatricesIndicesKind),r.push(f.MatricesWeightsKind),a.numBoneInfluencers>4&&(r.push(f.MatricesIndicesExtraKind),r.push(f.MatricesWeightsExtraKind)),i.push("#define NUM_BONE_INFLUENCERS "+a.numBoneInfluencers),i.push("#define BONETEXTURE "+a.skeleton.isUsingTextureForMatrices),i.push("#define BonesPerMesh "+(a.skeleton.bones.length+1))):(i.push("#define NUM_BONE_INFLUENCERS 0"),i.push("#define BONETEXTURE false"),i.push("#define BonesPerMesh 0"));const l=a.morphTargetManager?p(a.morphTargetManager,i,r,a,!0,!0,!1,n,o,!1):0;t&&(i.push("#define INSTANCES"),m(r,this._enableVelocity||this._enableVelocityLinear),e.getRenderingMesh().hasThinInstances&&i.push("#define THIN_INSTANCES")),this._linkedWithPrePass?i.push("#define SCENE_MRT_COUNT "+this._attachmentsFromPrePass.length):i.push("#define SCENE_MRT_COUNT "+this._multiRenderTarget.textures.length),T(s,this._scene,i);const h=this._scene.getEngine(),d=e._getDrawWrapper(void 0,!0),u=d.defines,_=i.join("\n");return u!==_&&d.setEffect(h.createEffect("geometry",{attributes:r,uniformsNames:te,samplers:["diffuseSampler","bumpSampler","reflectivitySampler","albedoSampler","morphTargets","boneSampler"],defines:_,onCompiled:null,fallbacks:null,onError:null,uniformBuffersNames:["Scene"],indexParameters:{buffersCount:this._multiRenderTarget.textures.length-1,maxSimultaneousMorphTargets:l},shaderLanguage:this.shaderLanguage},h),_),d.effect.isReady()}getGBuffer(){return this._multiRenderTarget}get samples(){return this._multiRenderTarget.samples}set samples(e){this._multiRenderTarget.samples=e}dispose(){if(this._resizeObserver){this._scene.getEngine().onResizeObservable.remove(this._resizeObserver),this._resizeObserver=null}this.getGBuffer().dispose()}_assignRenderTargetIndices(){const e=[],t=[];let s=0;return this._enableDepth&&(this._depthIndex=s,s++,e.push("gBuffer_Depth"),t.push(this._textureTypesAndFormats[se.DEPTH_TEXTURE_TYPE])),this._enableNormal&&(this._normalIndex=s,s++,e.push("gBuffer_Normal"),t.push(this._textureTypesAndFormats[se.NORMAL_TEXTURE_TYPE])),this._enablePosition&&(this._positionIndex=s,s++,e.push("gBuffer_Position"),t.push(this._textureTypesAndFormats[se.POSITION_TEXTURE_TYPE])),this._enableVelocity&&(this._velocityIndex=s,s++,e.push("gBuffer_Velocity"),t.push(this._textureTypesAndFormats[se.VELOCITY_TEXTURE_TYPE])),this._enableVelocityLinear&&(this._velocityLinearIndex=s,s++,e.push("gBuffer_VelocityLinear"),t.push(this._textureTypesAndFormats[se.VELOCITY_LINEAR_TEXTURE_TYPE])),this._enableReflectivity&&(this._reflectivityIndex=s,s++,e.push("gBuffer_Reflectivity"),t.push(this._textureTypesAndFormats[se.REFLECTIVITY_TEXTURE_TYPE])),this._enableScreenspaceDepth&&(this._screenspaceDepthIndex=s,s++,e.push("gBuffer_ScreenspaceDepth"),t.push(this._textureTypesAndFormats[se.SCREENSPACE_DEPTH_TEXTURE_TYPE])),[s,e,t]}_createRenderTargets(){const e=this._scene.getEngine(),[i,r,n]=this._assignRenderTargetIndices();let o=t.TEXTURETYPE_UNSIGNED_BYTE;e._caps.textureFloat&&e._caps.textureFloatLinearFiltering?o=t.TEXTURETYPE_FLOAT:e._caps.textureHalfFloat&&e._caps.textureHalfFloatLinearFiltering&&(o=t.TEXTURETYPE_HALF_FLOAT);const l=void 0!==this._ratioOrDimensions.width?this._ratioOrDimensions:{width:e.getRenderWidth()*this._ratioOrDimensions,height:e.getRenderHeight()*this._ratioOrDimensions},h=[],d=[];for(const e of n)e?(h.push(e.textureType),d.push(e.textureFormat)):(h.push(o),d.push(t.TEXTUREFORMAT_RGBA));if(this._normalsAreUnsigned=h[se.NORMAL_TEXTURE_TYPE]===t.TEXTURETYPE_UNSIGNED_INT_2_10_10_10_REV||h[se.NORMAL_TEXTURE_TYPE]===t.TEXTURETYPE_UNSIGNED_INT_10F_11F_11F_REV,this._multiRenderTarget=new X("gBuffer",l,i,this._scene,{generateMipMaps:!1,generateDepthTexture:!0,types:h,formats:d,depthTextureFormat:this._depthFormat},r.concat("gBuffer_DepthBuffer")),!this.isSupported)return;this._multiRenderTarget.wrapU=s.CLAMP_ADDRESSMODE,this._multiRenderTarget.wrapV=s.CLAMP_ADDRESSMODE,this._multiRenderTarget.refreshRate=1,this._multiRenderTarget.renderParticles=!1,this._multiRenderTarget.renderList=null;const u=[!0],_=[!1],c=[!0];for(let e=1;e<i;++e)u.push(!0),c.push(!1),_.push(!0);const f=e.buildTextureLayout(u),p=e.buildTextureLayout(_),m=e.buildTextureLayout(c);this._multiRenderTarget.onClearObservable.add((e=>{e.bindAttachments(this.useSpecificClearForDepthTexture?p:f),e.clear(this._clearColor,!0,!0,!0),this.useSpecificClearForDepthTexture&&(e.bindAttachments(m),e.clear(this._clearDepthColor,!0,!0,!0)),e.bindAttachments(f)})),this._resizeObserver=e.onResizeObservable.add((()=>{if(this._multiRenderTarget){const t=void 0!==this._ratioOrDimensions.width?this._ratioOrDimensions:{width:e.getRenderWidth()*this._ratioOrDimensions,height:e.getRenderHeight()*this._ratioOrDimensions};this._multiRenderTarget.resize(t)}}));const T=e=>{const t=e.getRenderingMesh(),s=e.getEffectiveMesh(),i=this._scene,r=i.getEngine(),n=e.getMaterial();if(!n)return;if(s._internalAbstractMeshDataInfo._isActiveIntermediate=!1,(this._enableVelocity||this._enableVelocityLinear)&&!this._previousTransformationMatrices[s.uniqueId]&&(this._previousTransformationMatrices[s.uniqueId]={world:a.Identity(),viewProjection:i.getTransformMatrix()},t.skeleton)){const e=t.skeleton.getTransformMatrices(t);this._previousBonesTransformationMatrices[t.uniqueId]=this._copyBonesTransformationMatrices(e,new Float32Array(e.length))}const o=t._getInstancesRenderList(e._id,!!e.getReplacementMesh());if(o.mustReturn)return;const l=r.getCaps().instancedArrays&&(null!==o.visibleInstances[e._id]||t.hasThinInstances),h=s.getWorldMatrix();if(this.isReady(e,l)){const a=e._getDrawWrapper();if(!a)return;const d=a.effect;let u;r.enableEffect(a),l||t._bind(e,d,n.fillMode),this._useUbo?(x(d,this._scene.getSceneUniformBuffer()),this._scene.finalizeSceneUbo()):(d.setMatrix("viewProjection",i.getTransformMatrix()),d.setMatrix("view",i.getViewMatrix()));if(t._instanceDataStorage.isFrozen||!n.backFaceCulling&&null===n.sideOrientation)u=t._effectiveSideOrientation;else{const e=s._getWorldMatrixDeterminant();u=n._getEffectiveOrientation(t),e<0&&(u=u===P.ClockWiseSideOrientation?P.CounterClockWiseSideOrientation:P.ClockWiseSideOrientation)}if(n._preBind(a,u),n.needAlphaTestingForMesh(s)){const e=n.getAlphaTestTexture();e&&(d.setTexture("diffuseSampler",e),d.setMatrix("diffuseMatrix",e.getTextureMatrix()))}if((n.bumpTexture||n.normalTexture)&&i.getEngine().getCaps().standardDerivatives&&g.BumpTextureEnabled){const e=n.bumpTexture||n.normalTexture;d.setFloat3("vBumpInfos",e.coordinatesIndex,1/e.level,n.parallaxScaleBias),d.setMatrix("bumpMatrix",e.getTextureMatrix()),d.setTexture("bumpSampler",e),d.setFloat2("vTangentSpaceParams",n.invertNormalMapX?-1:1,n.invertNormalMapY?-1:1)}if(this._enableReflectivity&&("PBRMetallicRoughnessMaterial"===n.getClassName()?(null!==n.metallicRoughnessTexture&&(d.setTexture("reflectivitySampler",n.metallicRoughnessTexture),d.setMatrix("reflectivityMatrix",n.metallicRoughnessTexture.getTextureMatrix())),null!==n.metallic&&d.setFloat("metallic",n.metallic),null!==n.roughness&&d.setFloat("glossiness",1-n.roughness),null!==n.baseTexture&&(d.setTexture("albedoSampler",n.baseTexture),d.setMatrix("albedoMatrix",n.baseTexture.getTextureMatrix())),null!==n.baseColor&&d.setColor3("albedoColor",n.baseColor)):"PBRSpecularGlossinessMaterial"===n.getClassName()?(null!==n.specularGlossinessTexture?(d.setTexture("reflectivitySampler",n.specularGlossinessTexture),d.setMatrix("reflectivityMatrix",n.specularGlossinessTexture.getTextureMatrix())):null!==n.specularColor&&d.setColor3("reflectivityColor",n.specularColor),null!==n.glossiness&&d.setFloat("glossiness",n.glossiness)):"PBRMaterial"===n.getClassName()?(null!==n.metallicTexture&&(d.setTexture("reflectivitySampler",n.metallicTexture),d.setMatrix("reflectivityMatrix",n.metallicTexture.getTextureMatrix())),null!==n.metallic&&d.setFloat("metallic",n.metallic),null!==n.roughness&&d.setFloat("glossiness",1-n.roughness),null!==n.roughness||null!==n.metallic||null!==n.metallicTexture?(null!==n.albedoTexture&&(d.setTexture("albedoSampler",n.albedoTexture),d.setMatrix("albedoMatrix",n.albedoTexture.getTextureMatrix())),null!==n.albedoColor&&d.setColor3("albedoColor",n.albedoColor)):(null!==n.reflectivityTexture?(d.setTexture("reflectivitySampler",n.reflectivityTexture),d.setMatrix("reflectivityMatrix",n.reflectivityTexture.getTextureMatrix())):null!==n.reflectivityColor&&d.setColor3("reflectivityColor",n.reflectivityColor),null!==n.microSurface&&d.setFloat("glossiness",n.microSurface))):"StandardMaterial"===n.getClassName()&&(null!==n.specularTexture&&(d.setTexture("reflectivitySampler",n.specularTexture),d.setMatrix("reflectivityMatrix",n.specularTexture.getTextureMatrix())),null!==n.specularColor&&d.setColor3("reflectivityColor",n.specularColor))),E(d,n,this._scene),t.useBones&&t.computeBonesUsingShaders&&t.skeleton){const e=t.skeleton;if(e.isUsingTextureForMatrices&&d.getUniformIndex("boneTextureWidth")>-1){const s=e.getTransformMatrixTexture(t);d.setTexture("boneSampler",s),d.setFloat("boneTextureWidth",4*(e.bones.length+1))}else d.setMatrices("mBones",t.skeleton.getTransformMatrices(t));(this._enableVelocity||this._enableVelocityLinear)&&d.setMatrices("mPreviousBones",this._previousBonesTransformationMatrices[t.uniqueId])}b(t,d),t.morphTargetManager&&t.morphTargetManager.isUsingTextureForTargets&&t.morphTargetManager._bind(d),(this._enableVelocity||this._enableVelocityLinear)&&(d.setMatrix("previousWorld",this._previousTransformationMatrices[s.uniqueId].world),d.setMatrix("previousViewProjection",this._previousTransformationMatrices[s.uniqueId].viewProjection)),l&&t.hasThinInstances&&d.setMatrix("world",h),t._processRendering(s,e,d,n.fillMode,o,l,((e,t)=>{e||d.setMatrix("world",t)}))}(this._enableVelocity||this._enableVelocityLinear)&&(this._previousTransformationMatrices[s.uniqueId].world=h.clone(),this._previousTransformationMatrices[s.uniqueId].viewProjection=this._scene.getTransformMatrix().clone(),t.skeleton&&this._copyBonesTransformationMatrices(t.skeleton.getTransformMatrices(t),this._previousBonesTransformationMatrices[s.uniqueId]))};this._multiRenderTarget.customIsReadyFunction=(t,s,i)=>{if((i||0===s)&&t.subMeshes)for(let s=0;s<t.subMeshes.length;++s){const i=t.subMeshes[s],r=i.getMaterial(),a=i.getRenderingMesh();if(!r)continue;const n=a._getInstancesRenderList(i._id,!!i.getReplacementMesh()),o=e.getCaps().instancedArrays&&(null!==n.visibleInstances[i._id]||a.hasThinInstances);if(!this.isReady(i,o))return!1}return!0},this._multiRenderTarget.customRenderFunction=(t,s,i,r)=>{let a;if(this._linkedWithPrePass){if(!this._prePassRenderer.enabled)return;this._scene.getEngine().bindAttachments(this._attachmentsFromPrePass)}if(r.length){for(e.setColorWrite(!1),a=0;a<r.length;a++)T(r.data[a]);e.setColorWrite(!0)}for(a=0;a<t.length;a++)T(t.data[a]);for(e.setDepthWrite(!1),a=0;a<s.length;a++)T(s.data[a]);if(this.renderTransparentMeshes)for(a=0;a<i.length;a++)T(i.data[a]);e.setDepthWrite(!0)}}_copyBonesTransformationMatrices(e,t){for(let s=0;s<e.length;s++)t[s]=e[s];return t}}se.ForceGLSL=!1,se.DEPTH_TEXTURE_TYPE=0,se.NORMAL_TEXTURE_TYPE=1,se.POSITION_TEXTURE_TYPE=2,se.VELOCITY_TEXTURE_TYPE=3,se.REFLECTIVITY_TEXTURE_TYPE=4,se.SCREENSPACE_DEPTH_TEXTURE_TYPE=5,se.VELOCITY_LINEAR_TEXTURE_TYPE=6,se._SceneComponentInitialization=e=>{throw v("GeometryBufferRendererSceneComponent")};class ie{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 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,t,s,i){this._debugSizeParams.set(e,t,s,i)}_createDebugPass(){const e=this._engine.isWebGPU;if(!this._debugPassPP){const t={width:this._engine.getRenderWidth(),height:this._engine.getRenderHeight(),uniforms:["sizeParams"],samplers:["debugSampler"],engine:this._engine,reusable:!0,shaderLanguage:e?1:0,extraInitializations:(e,t)=>{e?t.push(import("./iblShadowDebug.fragment-DaW7g_j7.esm.min.js")):t.push(import("./iblShadowDebug.fragment-DwyR3Ap3.esm.min.js"))}};this._debugPassPP=new i(this.debugPassName,"iblShadowDebug",t),this._debugPassPP.autoClear=!1,this._debugPassPP.onApplyObservable.add((e=>{e.setTexture("debugSampler",this._outputTexture),e.setVector4("sizeParams",this._debugSizeParams)}))}}constructor(e,t){this._voxelShadowOpacity=1,this._sssSamples=16,this._sssStride=8,this._sssMaxDist=.05,this._sssThickness=.5,this._ssShadowOpacity=1,this._cameraInvView=a.Identity(),this._cameraInvProj=a.Identity(),this._invWorldScaleMatrix=a.Identity(),this._frameId=0,this._sampleDirections=4,this._shadowParameters=new n(0,0,0,0),this._sssParameters=new n(0,0,0,0),this._opacityParameters=new n(0,0,0,0),this._voxelBiasParameters=new n(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 n(0,0,0,0),this._renderWhenGBufferReady=null,this._scene=e,this._engine=e.getEngine(),this._renderPipeline=t,this._createTextures()}_createTextures(){const e=this._createDefines(),s=this._engine.isWebGPU,i={type:t.TEXTURETYPE_UNSIGNED_BYTE,format:t.TEXTUREFORMAT_RGBA,samplingMode:t.TEXTURE_NEAREST_SAMPLINGMODE,generateDepthBuffer:!1,shaderLanguage:s?1:0,extraInitializationsAsync:async()=>{s?await Promise.all([import("./iblShadowVoxelTracing.fragment-xKPvjTpd.esm.min.js")]):await Promise.all([import("./iblShadowVoxelTracing.fragment-BU3Tz9a9.esm.min.js")])}};this._outputTexture=new G("voxelTracingPass",{width:this._engine.getRenderWidth(),height:this._engine.getRenderHeight()},"iblShadowVoxelTracing",this._scene,i),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.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"),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 t=0;this._scene.environmentTexture&&(t=this._scene.environmentTexture.rotationY??0),t=this._scene.useRightHandedSystem?-(t+.5*Math.PI):t-.5*Math.PI,t%=2*Math.PI,this._shadowParameters.set(this._sampleDirections,this._frameId,1,t),this._outputTexture.setVector4("shadowParameters",this._shadowParameters);const s=this._renderPipeline._getVoxelGridTexture(),i=Math.floor(Math.log2(s.getSize().width));this._voxelBiasParameters.set(this._voxelNormalBias,this._voxelDirectionBias,i,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",s),this._outputTexture.setTexture("blueNoiseSampler",this._renderPipeline._getNoiseTexture());const r=this._scene.iblCdfGenerator;if(!r)return o.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 a=this._scene.geometryBufferRenderer;if(!a)return o.Warn("IBLShadowsVoxelTracingPass: Can't bind for render because GeometryBufferRenderer is not enabled."),!1;const n=a.getTextureIndex(se.SCREENSPACE_DEPTH_TEXTURE_TYPE);this._outputTexture.setTexture("depthSampler",a.getGBuffer().textures[n]);const l=a.getTextureIndex(se.NORMAL_TEXTURE_TYPE);return this._outputTexture.setTexture("worldNormalSampler",a.getGBuffer().textures[l]),!0}_render(){this.enabled&&this._outputTexture.isReady()&&this._outputTexture.getEffect()?.isReady()&&this._setBindings(this._scene.activeCamera)&&this._outputTexture.render()}resize(e=1){const t={width:Math.max(1,Math.floor(this._engine.getRenderWidth()*e)),height:Math.max(1,Math.floor(this._engine.getRenderHeight()*e))};this._outputTexture.getSize().width===t.width&&this._outputTexture.getSize().height===t.height||this._outputTexture.resize(t,!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 re{getOutputTexture(){return this._outputTexture}getDebugPassPP(){return this._debugPassPP||this._createDebugPass(),this._debugPassPP}get debugPassName(){return this._debugPassName}setWorldScale(e){this._worldScale=e}setDebugDisplayParams(e,t,s,i){this._debugSizeParams.set(e,t,s,i)}_createDebugPass(){if(!this._debugPassPP){const e=this._engine.isWebGPU,s={width:this._engine.getRenderWidth(),height:this._engine.getRenderHeight(),textureFormat:t.TEXTUREFORMAT_RGBA,textureType:t.TEXTURETYPE_UNSIGNED_BYTE,samplingMode:t.TEXTURE_NEAREST_SAMPLINGMODE,uniforms:["sizeParams"],samplers:["debugSampler"],engine:this._engine,reusable:!1,shaderLanguage:e?1:0,extraInitializations:(e,t)=>{e?t.push(import("./iblShadowDebug.fragment-DaW7g_j7.esm.min.js")):t.push(import("./iblShadowDebug.fragment-DwyR3Ap3.esm.min.js"))}};this._debugPassPP=new i(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._worldScale=1,this._blurParameters=new n(0,0,0,0),this.enabled=!0,this._debugPassName="Spatial Blur Debug Pass",this.debugEnabled=!1,this._debugSizeParams=new n(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:t.TEXTURETYPE_UNSIGNED_BYTE,format:t.TEXTUREFORMAT_RGBA,samplingMode:t.TEXTURE_NEAREST_SAMPLINGMODE,generateDepthBuffer:!1,generateMipMaps:!1,shaderLanguage:e?1:0,extraInitializationsAsync:async()=>{e?await Promise.all([import("./iblShadowSpatialBlur.fragment-u-Ese-4J.esm.min.js")]):await Promise.all([import("./iblShadowSpatialBlur.fragment-Dmvjh_0a.esm.min.js")])}};this._outputTexture=new G("spatialBlurPass",{width:this._engine.getRenderWidth(),height:this._engine.getRenderHeight()},"iblShadowSpatialBlur",this._scene,s,!1,!1,t.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.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 t=e.getTextureIndex(se.SCREENSPACE_DEPTH_TEXTURE_TYPE);this._outputTexture.setTexture("depthSampler",e.getGBuffer().textures[t]);const s=e.getTextureIndex(se.NORMAL_TEXTURE_TYPE);return this._outputTexture.setTexture("worldNormalSampler",e.getGBuffer().textures[s]),!0}_render(){this.enabled&&this._outputTexture.isReady()&&this._outputTexture.getEffect()?.isReady()&&this._setBindings()&&this._outputTexture.render()}resize(e=1){const t={width:Math.max(1,Math.floor(this._engine.getRenderWidth()*e)),height:Math.max(1,Math.floor(this._engine.getRenderHeight()*e))};this._outputTexture.getSize().width===t.width&&this._outputTexture.getSize().height===t.height||this._outputTexture.resize(t,!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 ae{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,t,s,i){this._debugSizeParams.set(e,t,s,i)}_createDebugPass(){if(!this._debugPassPP){const e=this._engine.isWebGPU,s={width:this._engine.getRenderWidth(),height:this._engine.getRenderHeight(),textureFormat:t.TEXTUREFORMAT_RGBA,textureType:t.TEXTURETYPE_UNSIGNED_BYTE,samplingMode:t.TEXTURE_NEAREST_SAMPLINGMODE,uniforms:["sizeParams"],samplers:["debugSampler"],engine:this._engine,reusable:!1,shaderLanguage:e?1:0,extraInitializations:(e,t)=>{e?t.push(import("./iblShadowDebug.fragment-DaW7g_j7.esm.min.js")):t.push(import("./iblShadowDebug.fragment-DwyR3Ap3.esm.min.js"))}};this._debugPassPP=new i(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 n(0,0,0,0),this.debugEnabled=!1,this.enabled=!0,this.onReadyObservable=new r,this._debugPassName="Shadow Accumulation Debug Pass",this._remanence=.9,this._reset=!0,this._isMoving=!1,this._debugSizeParams=new n(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:t.TEXTURETYPE_HALF_FLOAT,format:t.TEXTUREFORMAT_RGBA,samplingMode:t.TEXTURE_NEAREST_SAMPLINGMODE,generateDepthBuffer:!1,generateMipMaps:!1,shaderLanguage:e?1:0,extraInitializationsAsync:async()=>{e?await Promise.all([import("./iblShadowAccumulation.fragment-BxUUhz_P.esm.min.js")]):await Promise.all([import("./iblShadowAccumulation.fragment-C5V20koc.esm.min.js")])}};this._outputTexture=new G("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.getGBuffer().onAfterRenderObservable.add(this._renderWhenGBufferReady)}));const i={type:t.TEXTURETYPE_HALF_FLOAT,format:t.TEXTUREFORMAT_RGBA,samplingMode:t.TEXTURE_NEAREST_SAMPLINGMODE,generateDepthBuffer:!1,generateMipMaps:!1,shaderLanguage:e?1:0,extraInitializationsAsync:async()=>{e?await Promise.all([import("./pass.fragment-C1eC_8nX.esm.min.js")]):await Promise.all([import("./pass.fragment-DUvbXFMW.esm.min.js")])}};this._oldAccumulationCopy=new G("oldAccumulationRT",{width:this._engine.getRenderWidth(),height:this._engine.getRenderHeight()},"pass",this._scene,i,!1),this._oldAccumulationCopy.autoClear=!1,this._oldAccumulationCopy.refreshRate=1,this._oldAccumulationCopy.onBeforeGenerationObservable.add(this._setAccumulationCopyBindings.bind(this)),this._setAccumulationCopyBindings();const r={type:t.TEXTURETYPE_HALF_FLOAT,format:t.TEXTUREFORMAT_RGBA,samplingMode:t.TEXTURE_NEAREST_SAMPLINGMODE,generateDepthBuffer:!1,generateMipMaps:!1,shaderLanguage:e?1:0,extraInitializationsAsync:async()=>{e?await Promise.all([import("./pass.fragment-C1eC_8nX.esm.min.js")]):await Promise.all([import("./pass.fragment-DUvbXFMW.esm.min.js")])}};this._oldPositionCopy=new G("oldLocalPositionRT",{width:this._engine.getRenderWidth(),height:this._engine.getRenderHeight()},"pass",this._scene,r,!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 t=this._scene.geometryBufferRenderer;if(!t)return!1;const s=t.getTextureIndex(se.VELOCITY_LINEAR_TEXTURE_TYPE);this._outputTexture.setTexture("motionSampler",t.getGBuffer().textures[s]);const i=t.getTextureIndex(se.POSITION_TEXTURE_TYPE);return this._outputTexture.setTexture("positionSampler",t.getGBuffer().textures[i]),this.reset=!1,this._isMoving=!1,!0}_updatePositionCopy(){const e=this._scene.geometryBufferRenderer,t=e.getTextureIndex(se.POSITION_TEXTURE_TYPE);this._oldPositionCopy.setTexture("textureSampler",e.getGBuffer().textures[t])}_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 t={width:Math.max(1,Math.floor(this._engine.getRenderWidth()*e)),height:Math.max(1,Math.floor(this._engine.getRenderHeight()*e))};this._outputTexture.getSize().width===t.width&&this._outputTexture.getSize().height===t.height||(this._outputTexture.resize(t,!1),this._oldAccumulationCopy.resize(t,!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 ne{get name(){return this._name}get cameras(){return this._cameras}get engine(){return this._engine}constructor(e,t){this._engine=e,this.uniqueId=S.UniqueId,this._name=t,this._renderEffects={},this._renderEffectsForIsolatedPass=new Array,this._cameras=[]}getClassName(){return"PostProcessRenderPipeline"}get isSupported(){for(const e in this._renderEffects)if(Object.prototype.hasOwnProperty.call(this._renderEffects,e)&&!this._renderEffects[e].isSupported)return!1;return!0}addEffect(e){this._renderEffects[e._name]=e}_rebuild(){}_enableEffect(e,t){const s=this._renderEffects[e];s&&s._enable(y.MakeArray(t||this._cameras))}_disableEffect(e,t){const s=this._renderEffects[e];s&&s._disable(y.MakeArray(t||this._cameras))}_attachCameras(e,t){const s=y.MakeArray(e||this._cameras);if(!s)return;const i=[];let r;for(r=0;r<s.length;r++){const e=s[r];e&&(-1===this._cameras.indexOf(e)?this._cameras.push(e):t&&i.push(r))}for(r=0;r<i.length;r++)s.splice(i[r],1);for(const e in this._renderEffects)Object.prototype.hasOwnProperty.call(this._renderEffects,e)&&this._renderEffects[e]._attachCameras(s)}_detachCameras(e){const t=y.MakeArray(e||this._cameras);if(t){for(const e in this._renderEffects)Object.prototype.hasOwnProperty.call(this._renderEffects,e)&&this._renderEffects[e]._detachCameras(t);for(let e=0;e<t.length;e++)this._cameras.splice(this._cameras.indexOf(t[e]),1)}}_update(){for(const e in this._renderEffects)Object.prototype.hasOwnProperty.call(this._renderEffects,e)&&this._renderEffects[e]._update();for(let e=0;e<this._cameras.length;e++){if(!this._cameras[e])continue;const t=this._cameras[e].name;this._renderEffectsForIsolatedPass[t]&&this._renderEffectsForIsolatedPass[t]._update()}}_reset(){this._renderEffects={},this._renderEffectsForIsolatedPass=new Array}_enableMSAAOnFirstPostProcess(e){if(!this._engine._features.supportMSAA)return!1;const t=Object.keys(this._renderEffects);if(t.length>0){const s=this._renderEffects[t[0]].getPostProcesses();s&&(s[0].samples=e)}return!0}_adaptPostProcessesToViewPort(){const e=Object.keys(this._renderEffects);for(const t of e){const e=this._renderEffects[t].getPostProcesses();if(e)for(const t of e)t.adaptScaleToCurrentViewport=!0}}setPrePassRenderer(e){return!1}dispose(){}}M([D()],ne.prototype,"_name",void 0);class oe{constructor(e,t,s,i=!0){this._name=t,this._singleInstance=i,this._getPostProcesses=s,this._cameras={},this._indicesForCamera={},this._postProcesses={}}get isSupported(){for(const e in this._postProcesses)if(Object.prototype.hasOwnProperty.call(this._postProcesses,e)){const t=this._postProcesses[e];for(let e=0;e<t.length;e++)if(!t[e].isSupported)return!1}return!0}_update(){}_attachCameras(e){let t;const s=y.MakeArray(e||this._cameras);if(s)for(let e=0;e<s.length;e++){const i=s[e];if(!i)continue;const r=i.name;if(t=this._singleInstance?0:r,!this._postProcesses[t]){const e=this._getPostProcesses();e&&(this._postProcesses[t]=Array.isArray(e)?e:[e])}this._indicesForCamera[r]||(this._indicesForCamera[r]=[]);const a=this._postProcesses[t];for(const e of a){const t=i.attachPostProcess(e);this._indicesForCamera[r].push(t)}this._cameras[r]||(this._cameras[r]=i)}}_detachCameras(e){const t=y.MakeArray(e||this._cameras);if(t)for(let e=0;e<t.length;e++){const s=t[e],i=s.name,r=this._postProcesses[this._singleInstance?0:i];if(r)for(const e of r)s.detachPostProcess(e);this._cameras[i]&&(this._cameras[i]=null),delete this._indicesForCamera[i]}}_enable(e){const t=y.MakeArray(e||this._cameras);if(t)for(let e=0;e<t.length;e++){const s=t[e],i=s.name,r=this._singleInstance?0:i;for(let a=0;a<this._indicesForCamera[i].length;a++){const n=this._indicesForCamera[i][a],o=s._postProcesses[n];null==o&&t[e].attachPostProcess(this._postProcesses[r][a],n)}}}_disable(e){const t=y.MakeArray(e||this._cameras);if(t)for(let e=0;e<t.length;e++){const s=t[e],i=s.name,r=this._postProcesses[this._singleInstance?0:i];for(const e of r)s.detachPostProcess(e)}}getPostProcesses(e){return this._singleInstance?this._postProcesses[0]:e?this._postProcesses[e.name]:null}}class le extends s{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,i,r,a,n,o,l=!0,h=!1,d=s.TRILINEAR_SAMPLINGMODE,u=t.TEXTURETYPE_UNSIGNED_BYTE,_){super(null,o,!l,h),this.format=n,this._texture=o.getEngine().createRawTexture3D(e,i,r,a,n,l,h,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 he extends O{constructor(){super(...arguments),this.RENDER_WITH_IBL_SHADOWS=!1,this.COLORED_IBL_SHADOWS=!1}}class de extends I{get isColored(){return this._isColored}set isColored(e){this._isColored!==e&&(this._isColored=e,this._markAllSubMeshesAsTexturesDirty())}_markAllSubMeshesAsTexturesDirty(){this._enable(this._isEnabled),this._internalMarkAllSubMeshesAsTexturesDirty()}isCompatible(){return!0}constructor(e){super(e,de.Name,310,new he),this.shadowOpacity=1,this._isEnabled=!1,this._isColored=!1,this.isEnabled=!1,this._internalMarkAllSubMeshesAsTexturesDirty=e._dirtyCallbacks[t.MATERIAL_TextureDirtyFlag]}prepareDefines(e){e.RENDER_WITH_IBL_SHADOWS=this._isEnabled,e.COLORED_IBL_SHADOWS=this.isColored}getClassName(){return"IBLShadowsPluginMaterial"}getUniforms(){return{ubo:[{name:"renderTargetSize",size:2,type:"vec2"},{name:"shadowOpacity",size:1,type:"float"}],fragment:"#ifdef RENDER_WITH_IBL_SHADOWS\n uniform vec2 renderTargetSize;\n uniform float shadowOpacity;\n #endif"}}getSamplers(e){e.push("iblShadowsTexture")}bindForSubMesh(e){this._isEnabled&&(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,t){let s;return 1===t?(s={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 w?s.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 ":s.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 "):(s={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 w?s.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 ":s.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:s}}de.Name="IBLShadowsPluginMaterial",M([D()],de.prototype,"shadowOpacity",void 0),M([D(),A("_markAllSubMeshesAsTexturesDirty")],de.prototype,"isEnabled",void 0),C("BABYLON.IBLShadowsPluginMaterial",de),Object.defineProperty(B.prototype,"geometryBufferRenderer",{get:function(){return this._geometryBufferRenderer},set:function(e){e&&e.isSupported&&(this._geometryBufferRenderer=e)},enumerable:!0,configurable:!0}),B.prototype.enableGeometryBufferRenderer=function(e=1,s=t.TEXTUREFORMAT_DEPTH16,i){return this._geometryBufferRenderer||(this._geometryBufferRenderer=new se(this,e,s,i),this._geometryBufferRenderer.isSupported||(this._geometryBufferRenderer=null)),this._geometryBufferRenderer},B.prototype.disableGeometryBufferRenderer=function(){this._geometryBufferRenderer&&(this._geometryBufferRenderer.dispose(),this._geometryBufferRenderer=null)};class ue{constructor(e){this.name=N.NAME_GEOMETRYBUFFERRENDERER,this.scene=e}register(){this.scene._gatherRenderTargetsStage.registerStep(N.STEP_GATHERRENDERTARGETS_GEOMETRYBUFFERRENDERER,this,this._gatherRenderTargets)}rebuild(){}dispose(){}_gatherRenderTargets(e){this.scene._geometryBufferRenderer&&e.push(this.scene._geometryBufferRenderer.getGBuffer())}}se._SceneComponentInitialization=e=>{let t=e._getComponent(N.NAME_GEOMETRYBUFFERRENDERER);t||(t=new ue(e),e._addComponent(t))};class _e extends ne{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)):o.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)):o.Warn("Can't enable importance sampling debug view without setting allowDebugPasses to true."))}get voxelDebugEnabled(){return this._voxelRenderer?.voxelDebugEnabled}set voxelDebugEnabled(e){this._voxelRenderer&&(!e||this.allowDebugPasses?(this._voxelRenderer.voxelDebugEnabled=e,e?this._enableEffect(this._voxelRenderer.debugPassName,this.cameras):this._disableEffect(this._voxelRenderer.debugPassName,this.cameras)):o.Warn("Can't enable voxel debug view without setting allowDebugPasses to true."))}get voxelDebugAxis(){return this._voxelRenderer?.voxelDebugAxis}set voxelDebugAxis(e){this._voxelRenderer&&(this._voxelRenderer.voxelDebugAxis=e)}set voxelDebugDisplayMip(e){this._voxelRenderer&&this._voxelRenderer.setDebugMipNumber(e)}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)):o.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)):o.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._accumulationPass.debugPassName,this.cameras)):o.Warn("Can't enable accumulation pass debug view without setting allowDebugPasses to true."))}addShadowCastingMesh(e){if(Array.isArray(e))for(const t of e)t&&-1===this._shadowCastingMeshes.indexOf(t)&&this._shadowCastingMeshes.push(t);else e&&-1===this._shadowCastingMeshes.indexOf(e)&&this._shadowCastingMeshes.push(e)}removeShadowCastingMesh(e){if(Array.isArray(e))for(const t of e){const e=this._shadowCastingMeshes.indexOf(t);-1!==e&&this._shadowCastingMeshes.splice(e,1)}else{const t=this._shadowCastingMeshes.indexOf(e);-1!==t&&this._shadowCastingMeshes.splice(t,1)}}clearShadowCastingMeshes(){this._shadowCastingMeshes.length=0}get resolutionExp(){return this._voxelRenderer.voxelResolutionExp}set resolutionExp(e){e!==this._voxelRenderer.voxelResolutionExp&&(this._voxelRenderer.isVoxelizationInProgress()?o.Warn("Can't change the resolution of the voxel grid while voxelization is in progress."):(this._voxelRenderer.voxelResolutionExp=Math.max(1,Math.min(e,8)),this._accumulationPass.reset=!0))}get sampleDirections(){return this._voxelTracingPass?.sampleDirections}set sampleDirections(e){this._voxelTracingPass&&(this._voxelTracingPass.sampleDirections=e)}get shadowRemanence(){return this._accumulationPass?.remanence}set shadowRemanence(e){this._accumulationPass&&(this._accumulationPass.remanence=e)}get envRotation(){return this._voxelTracingPass?.envRotation}set envRotation(e){this._voxelTracingPass&&(this._voxelTracingPass.envRotation=e,this._accumulationPass.reset=!0)}get allowDebugPasses(){return this._allowDebugPasses}set allowDebugPasses(e){this._allowDebugPasses!==e&&(this._allowDebugPasses=e,e&&this.scene.iblCdfGenerator?this.scene.iblCdfGenerator.isReady()?this._createDebugPasses():this.scene.iblCdfGenerator.onGeneratedObservable.addOnce((()=>{this._createDebugPasses()})):this._disposeDebugPasses())}static get IsSupported(){const e=V.LastCreatedEngine;return!!e&&e._features.supportIBLShadows}toggleShadow(e){this._enabled=e,this._voxelTracingPass.enabled=e,this._spatialBlurPass.enabled=e,this._accumulationPass.enabled=e;for(const t of this._materialsWithRenderPlugin)if(t.pluginManager){t.pluginManager.getPlugin(de.Name).isEnabled=e}this._setPluginParameters()}updateVoxelization(){0!==this._shadowCastingMeshes.length?(this._voxelRenderer.updateVoxelGrid(this._shadowCastingMeshes),this._voxelRenderer.onVoxelizationCompleteObservable.addOnce((()=>{this.onVoxelizationCompleteObservable.notifyObservers()})),this._updateSsShadowParams()):o.Warn("IBL Shadows: updateVoxelization called with no shadow-casting meshes to voxelize.")}updateSceneBounds(){const e={min:new _(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),max:new _(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE)};for(const t of this._shadowCastingMeshes){const s=t.getHierarchyBoundingVectors(!0);e.min=_.Minimize(e.min,s.min),e.max=_.Maximize(e.max,s.max)}const t=e.max.subtract(e.min);if(this.voxelGridSize=Math.max(t.x,t.y,t.z),0===this._shadowCastingMeshes.length||!isFinite(this.voxelGridSize)||0===this.voxelGridSize)return o.Warn("IBL Shadows: Scene size is invalid. Can't update bounds."),void(this.voxelGridSize=1);const s=this.voxelGridSize/2,i=e.max.add(e.min).multiplyByFloats(-.5,-.5,-.5),r=a.Compose(new _(1/s,1/s,1/s),new L,new _(0,0,0));a.Compose(new _(1,1,1),new L,i).multiplyToRef(r,r),this._voxelTracingPass.setWorldScaleMatrix(r),this._voxelRenderer.setWorldScaleMatrix(r),this._spatialBlurPass.setWorldScale(2*s),this._updateSsShadowParams()}constructor(e,i,a={},l){super(i.getEngine(),e),this._allowDebugPasses=!1,this._debugPasses=[],this._shadowCastingMeshes=[],this._shadowOpacity=.8,this._enabled=!0,this._coloredShadows=!1,this._materialsWithRenderPlugin=[],this.onShadowTextureReadyObservable=new r,this.onNewIblReadyObservable=new r,this.onVoxelizationCompleteObservable=new r,this.voxelGridSize=1,this._renderSizeFactor=1,this._gbufferDebugEnabled=!1,this._gBufferDebugSizeParams=new n(0,0,0,0),this.scene=i,this._cameras=l||[i.activeCamera];const h=new Uint8Array([0,0,0,255]);this._dummyTexture2d=new F(h,1,1,u.TEXTUREFORMAT_RGBA,i,!1),this._dummyTexture3d=new le(h,1,1,1,u.TEXTUREFORMAT_RGBA,i,!1);const d={};d[se.SCREENSPACE_DEPTH_TEXTURE_TYPE]={textureFormat:t.TEXTUREFORMAT_R,textureType:t.TEXTURETYPE_FLOAT},d[se.VELOCITY_LINEAR_TEXTURE_TYPE]={textureFormat:t.TEXTUREFORMAT_RG,textureType:t.TEXTURETYPE_HALF_FLOAT},d[se.POSITION_TEXTURE_TYPE]={textureFormat:t.TEXTUREFORMAT_RGBA,textureType:t.TEXTURETYPE_HALF_FLOAT},d[se.NORMAL_TEXTURE_TYPE]={textureFormat:t.TEXTUREFORMAT_RGBA,textureType:t.TEXTURETYPE_HALF_FLOAT};const _=i.enableGeometryBufferRenderer(void 0,t.TEXTUREFORMAT_DEPTH32_FLOAT,d);_?(this._geometryBufferRenderer=_,this._geometryBufferRenderer.enableScreenspaceDepth=!0,this._geometryBufferRenderer.enableVelocityLinear=!0,this._geometryBufferRenderer.enablePosition=!0,this._geometryBufferRenderer.enableNormal=!0,this._geometryBufferRenderer.generateNormalsInWorldSpace=!0,this.scene.enableIblCdfGenerator(),this.shadowOpacity=a.shadowOpacity||.8,this._voxelRenderer=new z(this.scene,this,a?a.resolutionExp:6,void 0===a.triPlanarVoxelization||a.triPlanarVoxelization),this._voxelTracingPass=new ie(this.scene,this),this._spatialBlurPass=new re(this.scene,this),this._accumulationPass=new ae(this.scene,this),this._accumulationPass.onReadyObservable.addOnce((()=>{this.onShadowTextureReadyObservable.notifyObservers()})),this.sampleDirections=a.sampleDirections||2,this.voxelShadowOpacity=a.voxelShadowOpacity??1,this.envRotation=a.envRotation??0,this.shadowRenderSizeFactor=a.shadowRenderSizeFactor||1,this.ssShadowOpacity=void 0===a.ssShadowsEnabled||a.ssShadowsEnabled?1:0,this.ssShadowDistanceScale=a.ssShadowDistanceScale||1.25,this.ssShadowSampleCount=a.ssShadowSampleCount||16,this.ssShadowStride=a.ssShadowStride||8,this.ssShadowThicknessScale=a.ssShadowThicknessScale||1,this.shadowRemanence=a.shadowRemanence??.75,this._noiseTexture=new s("https://assets.babylonjs.com/textures/blue_noise/blue_noise_rgb.png",this.scene,!1,!0,t.TEXTURE_NEAREST_SAMPLINGMODE),i.postProcessRenderPipelineManager.addPipeline(this),this.scene.onActiveCameraChanged.add(this._listenForCameraChanges.bind(this)),this.scene.onBeforeRenderObservable.add(this._updateBeforeRender.bind(this)),this._listenForCameraChanges(),this.scene.getEngine().onResizeObservable.add(this._handleResize.bind(this)),this.scene.iblCdfGenerator&&this.scene.iblCdfGenerator.onGeneratedObservable.add((()=>{this._setPluginParameters(),this.onNewIblReadyObservable.notifyObservers()}))):o.Error("Geometry buffer renderer is required for IBL shadows to work.")}_handleResize(){this._voxelRenderer.resize(),this._voxelTracingPass.resize(this.shadowRenderSizeFactor),this._spatialBlurPass.resize(this.shadowRenderSizeFactor),this._accumulationPass.resize(this.shadowRenderSizeFactor),this._setPluginParameters()}_getGBufferDebugPass(){if(this._gbufferDebugPass)return this._gbufferDebugPass;const e=this.engine.isWebGPU,s={width:this.scene.getEngine().getRenderWidth(),height:this.scene.getEngine().getRenderHeight(),samplingMode:t.TEXTURE_NEAREST_SAMPLINGMODE,engine:this.scene.getEngine(),textureType:t.TEXTURETYPE_UNSIGNED_BYTE,textureFormat:t.TEXTUREFORMAT_RGBA,uniforms:["sizeParams"],samplers:["depthSampler","normalSampler","positionSampler","velocitySampler"],reusable:!1,shaderLanguage:e?1:0,extraInitializations:(e,t)=>{e?t.push(import("./iblShadowGBufferDebug.fragment-D3AnOIzY.esm.min.js")):t.push(import("./iblShadowGBufferDebug.fragment-CJMmHA1r.esm.min.js"))}};return this._gbufferDebugPass=new i("iblShadowGBufferDebug","iblShadowGBufferDebug",s),this.engine.isWebGPU&&(this._gbufferDebugPass.samples=this.engine.currentSampleCount??1),this._gbufferDebugPass.autoClear=!1,this._gbufferDebugPass.onApplyObservable.add((e=>{const t=this._geometryBufferRenderer.getTextureIndex(se.SCREENSPACE_DEPTH_TEXTURE_TYPE);e.setTexture("depthSampler",this._geometryBufferRenderer.getGBuffer().textures[t]);const s=this._geometryBufferRenderer.getTextureIndex(se.NORMAL_TEXTURE_TYPE);e.setTexture("normalSampler",this._geometryBufferRenderer.getGBuffer().textures[s]);const i=this._geometryBufferRenderer.getTextureIndex(se.POSITION_TEXTURE_TYPE);e.setTexture("positionSampler",this._geometryBufferRenderer.getGBuffer().textures[i]);const r=this._geometryBufferRenderer.getTextureIndex(se.VELOCITY_LINEAR_TEXTURE_TYPE);e.setTexture("velocitySampler",this._geometryBufferRenderer.getGBuffer().textures[r]),e.setVector4("sizeParams",this._gBufferDebugSizeParams),this.scene.activeCamera&&e.setFloat("maxDepth",this.scene.activeCamera.maxZ)})),this._gbufferDebugPass}_createDebugPasses(){this.scene.iblCdfGenerator?this._debugPasses=[{pass:this.scene.iblCdfGenerator.getDebugPassPP(),enabled:this.cdfDebugEnabled}]:this._debugPasses=[],this._debugPasses.push({pass:this._voxelRenderer.getDebugPassPP(),enabled:this.voxelDebugEnabled},{pass:this._voxelTracingPass.getDebugPassPP(),enabled:this.voxelTracingDebugEnabled},{pass:this._spatialBlurPass.getDebugPassPP(),enabled:this.spatialBlurPassDebugEnabled},{pass:this._accumulationPass.getDebugPassPP(),enabled:this.accumulationPassDebugEnabled},{pass:this._getGBufferDebugPass(),enabled:this.gbufferDebugEnabled});for(let e=0;e<this._debugPasses.length;e++)this._debugPasses[e].pass&&this.addEffect(new oe(this.scene.getEngine(),this._debugPasses[e].pass.name,(()=>this._debugPasses[e].pass),!0));const e=this.cameras.slice();this.scene.postProcessRenderPipelineManager.detachCamerasFromRenderPipeline(this.name,this.cameras),this.scene.postProcessRenderPipelineManager.attachCamerasToRenderPipeline(this.name,e);for(let e=0;e<this._debugPasses.length;e++)this._debugPasses[e].pass&&(this._debugPasses[e].enabled?this._enableEffect(this._debugPasses[e].pass.name,this.cameras):this._disableEffect(this._debugPasses[e].pass.name,this.cameras))}_disposeEffectPasses(){this.scene.postProcessRenderPipelineManager.detachCamerasFromRenderPipeline(this.name,this.cameras),this._disposeDebugPasses(),this._reset()}_disposeDebugPasses(){for(let e=0;e<this._debugPasses.length;e++)this._disableEffect(this._debugPasses[e].pass.name,this.cameras),this._debugPasses[e].pass.dispose();this._debugPasses=[]}_updateDebugPasses(){let e=0;this._gbufferDebugEnabled&&e++,this.cdfDebugEnabled&&e++,this.voxelDebugEnabled&&e++,this.voxelTracingDebugEnabled&&e++,this.spatialBlurPassDebugEnabled&&e++,this.accumulationPassDebugEnabled&&e++;const t=Math.ceil(Math.sqrt(e)),s=Math.ceil(e/t),i=1/s,r=1/t;let a=0,n=0;this.gbufferDebugEnabled&&(this._gBufferDebugSizeParams.set(a,n,s,t),a-=i,a<=-1&&(a=0,n-=r)),this.cdfDebugEnabled&&this.scene.iblCdfGenerator&&(this.scene.iblCdfGenerator.setDebugDisplayParams(a,n,s,t),a-=i,a<=-1&&(a=0,n-=r)),this.voxelDebugEnabled&&(this._voxelRenderer.setDebugDisplayParams(a,n,s,t),a-=i,a<=-1&&(a=0,n-=r)),this.voxelTracingDebugEnabled&&(this._voxelTracingPass.setDebugDisplayParams(a,n,s,t),a-=i,a<=-1&&(a=0,n-=r)),this.spatialBlurPassDebugEnabled&&(this._spatialBlurPass.setDebugDisplayParams(a,n,s,t),a-=i,a<=-1&&(a=0,n-=r)),this.accumulationPassDebugEnabled&&(this._accumulationPass.setDebugDisplayParams(a,n,s,t),a-=i,a<=-1&&(a=0,n-=r))}_updateSsShadowParams(){this._voxelTracingPass.sssMaxDist=this._sssMaxDistScale*this.voxelGridSize/(1<<this.resolutionExp),this._voxelTracingPass.sssThickness=.005*this._sssThicknessScale*this.voxelGridSize}addShadowReceivingMaterial(e){if(e)if(Array.isArray(e))for(const t of e)this._addShadowSupportToMaterial(t);else this._addShadowSupportToMaterial(e);else for(const e of this.scene.materials)this._addShadowSupportToMaterial(e)}removeShadowReceivingMaterial(e){if(Array.isArray(e))for(const t of e){const e=this._materialsWithRenderPlugin.indexOf(t);if(-1!==e){this._materialsWithRenderPlugin.splice(e,1);const s=t.pluginManager?.getPlugin(de.Name);s.isEnabled=!1}}else{const t=this._materialsWithRenderPlugin.indexOf(e);if(-1!==t){this._materialsWithRenderPlugin.splice(t,1);e.pluginManager.getPlugin(de.Name).isEnabled=!1}}}clearShadowReceivingMaterials(){for(const e of this._materialsWithRenderPlugin){const t=e.pluginManager?.getPlugin(de.Name);t&&(t.isEnabled=!1)}this._materialsWithRenderPlugin.length=0}_addShadowSupportToMaterial(e){if(!(e instanceof w||e instanceof W))return;let t=e.pluginManager?.getPlugin(de.Name);t||(t=new de(e)),-1===this._materialsWithRenderPlugin.indexOf(e)&&(this._enabled&&(t.iblShadowsTexture=this._getAccumulatedTexture().getInternalTexture(),t.shadowOpacity=this.shadowOpacity),t.isEnabled=this._enabled,t.isColored=this._coloredShadows,this._materialsWithRenderPlugin.push(e))}_setPluginParameters(){if(this._enabled)for(const e of this._materialsWithRenderPlugin)if(e.pluginManager){const t=e.pluginManager.getPlugin(de.Name);t.iblShadowsTexture=this._getAccumulatedTexture().getInternalTexture(),t.shadowOpacity=this.shadowOpacity,t.isColored=this._coloredShadows}}_updateBeforeRender(){this._updateDebugPasses()}_listenForCameraChanges(){this.scene.activeCamera?.onViewMatrixChangedObservable.add((()=>{this._accumulationPass.isMoving=!0}))}isReady(){return this._noiseTexture.isReady()&&this._voxelRenderer.isReady()&&this.scene.iblCdfGenerator&&this.scene.iblCdfGenerator.isReady()&&(!this._voxelTracingPass||this._voxelTracingPass.isReady())&&(!this._spatialBlurPass||this._spatialBlurPass.isReady())&&(!this._accumulationPass||this._accumulationPass.isReady())}getClassName(){return"IBLShadowsRenderPipeline"}dispose(){const e=this._materialsWithRenderPlugin.splice(0);for(const t of e)this.removeShadowReceivingMaterial(t);this._disposeEffectPasses(),this._noiseTexture.dispose(),this._voxelRenderer.dispose(),this._voxelTracingPass.dispose(),this._spatialBlurPass.dispose(),this._accumulationPass.dispose(),this._dummyTexture2d.dispose(),this._dummyTexture3d.dispose(),this.onNewIblReadyObservable.clear(),this.onShadowTextureReadyObservable.clear(),this.onVoxelizationCompleteObservable.clear(),super.dispose()}}export{_e as IblShadowsRenderPipeline};
//# sourceMappingURL=iblShadowsRenderPipeline-BMoywkcb.esm.min.js.map