@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 (2 loc) • 33.8 kB
JavaScript
import{m as e,C as t,a_ as s,l as i,o as r,aP as a,q as n,a$ as o,s as h,O as l,V as d,M as u,az as p,aA as c,b0 as _,b1 as f,b2 as g,b3 as S,b4 as M,aL as E,T,ah as m,aq as w,am as L,b5 as x,a7 as I,a4 as P,b6 as b,b7 as A,b8 as F,ae as O,b9 as R,ba as B}from"./index-BPURObVq.esm.min.js";import{RegisterShadowGeneratorSceneComponent as C}from"./shadowGeneratorSceneComponent-BCt7XsPW.esm.min.js";let N=(()=>{var l;let d,u,p,c=a,_=[];return l=class extends c{get direction(){return this._effectWrapper.direction}set direction(e){this._effectWrapper.direction=e}set kernel(e){this._effectWrapper.kernel=e}get kernel(){return this._effectWrapper.kernel}set packedFloat(e){this._effectWrapper.packedFloat=e}get packedFloat(){return this._effectWrapper.packedFloat}getClassName(){return"BlurPostProcess"}constructor(r,a,n,o,h=null,l=e.BILINEAR_SAMPLINGMODE,d,u,p=t.TEXTURETYPE_UNSIGNED_BYTE,c="",f=!1,g=t.TEXTUREFORMAT_RGBA){const S="number"==typeof o?f:!!o.blockCompilation,M={uniforms:s.Uniforms,samplers:s.Samplers,size:"number"==typeof o?o:void 0,camera:h,samplingMode:l,engine:d,reusable:u,textureType:p,vertexUrl:s.VertexUrl,indexParameters:{varyingCount:0,depCount:0},textureFormat:g,defines:c,...o,blockCompilation:!0};super(r,s.FragmentUrl,{effectWrapper:"number"!=typeof o&&o.effectWrapper?void 0:new s(r,d,void 0,void 0,M),...M}),i(this,_),this._effectWrapper.options.blockCompilation=S,this.direction=a,this.onApplyObservable.add(()=>{this._effectWrapper.textureWidth=this._outputTexture?this._outputTexture.width:this.width,this._effectWrapper.textureHeight=this._outputTexture?this._outputTexture.height:this.height}),this.kernel=n}updateEffect(e=null,t=null,s=null,i,r,a){this._effectWrapper._updateParameters(r,a)}static _Parse(e,t,s,i){return r.Parse(()=>new l(e.name,e.direction,e.kernel,e.options,t,e.renderTargetSamplingMode,s.getEngine(),e.reusable,e.textureType,void 0,!1),e,s,i)}},(()=>{const e="function"==typeof Symbol&&Symbol.metadata?Object.create(c[Symbol.metadata]??null):void 0;d=[o()],u=[h()],p=[h()],n(l,null,d,{kind:"getter",name:"direction",static:!1,private:!1,access:{has:e=>"direction"in e,get:e=>e.direction},metadata:e},null,_),n(l,null,u,{kind:"setter",name:"kernel",static:!1,private:!1,access:{has:e=>"kernel"in e,set:(e,t)=>{e.kernel=t}},metadata:e},null,_),n(l,null,p,{kind:"setter",name:"packedFloat",static:!1,private:!1,access:{has:e=>"packedFloat"in e,set:(e,t)=>{e.packedFloat=t}},metadata:e},null,_),e&&Object.defineProperty(l,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:e})})(),l})();class D{get bias(){return this._bias}set bias(e){this._bias=e}get normalBias(){return this._normalBias}set normalBias(e){this._normalBias=e}get blurBoxOffset(){return this._blurBoxOffset}set blurBoxOffset(e){this._blurBoxOffset!==e&&(this._blurBoxOffset=e,this._disposeBlurPostProcesses())}get blurScale(){return this._blurScale}set blurScale(e){this._blurScale!==e&&(this._blurScale=e,this._disposeBlurPostProcesses())}get blurKernel(){return this._blurKernel}set blurKernel(e){this._blurKernel!==e&&(this._blurKernel=e,this._disposeBlurPostProcesses())}get useKernelBlur(){return this._useKernelBlur}set useKernelBlur(e){this._useKernelBlur!==e&&(this._useKernelBlur=e,this._disposeBlurPostProcesses())}get depthScale(){return void 0!==this._depthScale?this._depthScale:this._light.getDepthScale()}set depthScale(e){this._depthScale=e}_validateFilter(e){return e}get filter(){return this._filter}set filter(e){if(e=this._validateFilter(e),this._light.needCube()){if(e===D.FILTER_BLUREXPONENTIALSHADOWMAP)return void(this.useExponentialShadowMap=!0);if(e===D.FILTER_BLURCLOSEEXPONENTIALSHADOWMAP)return void(this.useCloseExponentialShadowMap=!0);if(e===D.FILTER_PCF||e===D.FILTER_PCSS)return void(this.usePoissonSampling=!0)}e!==D.FILTER_PCF&&e!==D.FILTER_PCSS||this._scene.getEngine()._features.supportShadowSamplers?this._filter!==e&&(this._filter=e,this._disposeBlurPostProcesses(),this._applyFilterValues(),this._light._markMeshesAsLightDirty()):this.usePoissonSampling=!0}get usePoissonSampling(){return this.filter===D.FILTER_POISSONSAMPLING}set usePoissonSampling(e){const t=this._validateFilter(D.FILTER_POISSONSAMPLING);(e||this.filter===D.FILTER_POISSONSAMPLING)&&(this.filter=e?t:D.FILTER_NONE)}get useExponentialShadowMap(){return this.filter===D.FILTER_EXPONENTIALSHADOWMAP}set useExponentialShadowMap(e){const t=this._validateFilter(D.FILTER_EXPONENTIALSHADOWMAP);(e||this.filter===D.FILTER_EXPONENTIALSHADOWMAP)&&(this.filter=e?t:D.FILTER_NONE)}get useBlurExponentialShadowMap(){return this.filter===D.FILTER_BLUREXPONENTIALSHADOWMAP}set useBlurExponentialShadowMap(e){const t=this._validateFilter(D.FILTER_BLUREXPONENTIALSHADOWMAP);(e||this.filter===D.FILTER_BLUREXPONENTIALSHADOWMAP)&&(this.filter=e?t:D.FILTER_NONE)}get useCloseExponentialShadowMap(){return this.filter===D.FILTER_CLOSEEXPONENTIALSHADOWMAP}set useCloseExponentialShadowMap(e){const t=this._validateFilter(D.FILTER_CLOSEEXPONENTIALSHADOWMAP);(e||this.filter===D.FILTER_CLOSEEXPONENTIALSHADOWMAP)&&(this.filter=e?t:D.FILTER_NONE)}get useBlurCloseExponentialShadowMap(){return this.filter===D.FILTER_BLURCLOSEEXPONENTIALSHADOWMAP}set useBlurCloseExponentialShadowMap(e){const t=this._validateFilter(D.FILTER_BLURCLOSEEXPONENTIALSHADOWMAP);(e||this.filter===D.FILTER_BLURCLOSEEXPONENTIALSHADOWMAP)&&(this.filter=e?t:D.FILTER_NONE)}get usePercentageCloserFiltering(){return this.filter===D.FILTER_PCF}set usePercentageCloserFiltering(e){const t=this._validateFilter(D.FILTER_PCF);(e||this.filter===D.FILTER_PCF)&&(this.filter=e?t:D.FILTER_NONE)}get filteringQuality(){return this._filteringQuality}set filteringQuality(e){this._filteringQuality!==e&&(this._filteringQuality=e,this._disposeBlurPostProcesses(),this._applyFilterValues(),this._light._markMeshesAsLightDirty())}get useContactHardeningShadow(){return this.filter===D.FILTER_PCSS}set useContactHardeningShadow(e){const t=this._validateFilter(D.FILTER_PCSS);(e||this.filter===D.FILTER_PCSS)&&(this.filter=e?t:D.FILTER_NONE)}get contactHardeningLightSizeUVRatio(){return this._contactHardeningLightSizeUVRatio}set contactHardeningLightSizeUVRatio(e){this._contactHardeningLightSizeUVRatio=e}get darkness(){return this._darkness}set darkness(e){this.setDarkness(e)}getDarkness(){return this._darkness}setDarkness(e){return this._darkness=e>=1?1:e<=0?0:e,this}get transparencyShadow(){return this._transparencyShadow}set transparencyShadow(e){this.setTransparencyShadow(e)}setTransparencyShadow(e){return this._transparencyShadow=e,this}getShadowMap(){return this._shadowMap}getShadowMapForRendering(){return this._shadowMap2?this._shadowMap2:this._shadowMap}getClassName(){return D.CLASSNAME}addShadowCaster(e,t=!0){if(!this._shadowMap)return this;if(this._shadowMap.renderList||(this._shadowMap.renderList=[]),-1===this._shadowMap.renderList.indexOf(e)&&this._shadowMap.renderList.push(e),t)for(const t of e.getChildMeshes())-1===this._shadowMap.renderList.indexOf(t)&&this._shadowMap.renderList.push(t);return this}removeShadowCaster(e,t=!0){if(!this._shadowMap||!this._shadowMap.renderList)return this;const s=this._shadowMap.renderList.indexOf(e);if(-1!==s&&this._shadowMap.renderList.splice(s,1),t)for(const t of e.getChildren())this.removeShadowCaster(t);return this}getLight(){return this._light}get shaderLanguage(){return this._shaderLanguage}_getCamera(){return this._camera??this._scene.activeCamera}get mapSize(){return this._mapSize}set mapSize(e){this._mapSize=e,this._light._markMeshesAsLightDirty(),this.recreateShadowMap()}get light(){return this._light}set light(e){this._light!==e&&(this.dispose(!1),this._light=e,this._createInstance())}get useFloat32TextureType(){return this._usefullFloatFirst}set useFloat32TextureType(e){this._usefullFloatFirst!==e&&(this.dispose(!1),this._usefullFloatFirst=e,this._createInstance())}get camera(){return this._camera}set camera(e){this._camera!==e&&(this.dispose(!1),this._camera=e,this._createInstance())}get useRedTextureFormat(){return this._useRedTextureType}set useRedTextureFormat(e){this._useRedTextureType!==e&&(this.dispose(!1),this._useRedTextureType=e,this._createInstance())}constructor(e,t,s,i,r,a=!1){this.onBeforeShadowMapRenderObservable=new l,this.onAfterShadowMapRenderObservable=new l,this.onBeforeShadowMapRenderMeshObservable=new l,this.onAfterShadowMapRenderMeshObservable=new l,this.doNotSerialize=!1,this._bias=5e-5,this._normalBias=0,this._blurBoxOffset=1,this._blurScale=2,this._blurKernel=1,this._useKernelBlur=!1,this._filter=D.FILTER_NONE,this._filteringQuality=D.QUALITY_HIGH,this._contactHardeningLightSizeUVRatio=.1,this._darkness=0,this._transparencyShadow=!1,this.enableSoftTransparentShadow=!1,this.useOpacityTextureForTransparentShadow=!1,this.frustumEdgeFalloff=0,this._shaderLanguage=0,this.forceBackFacesOnly=!1,this._lightDirection=d.Zero(),this._viewMatrix=u.Zero(),this._projectionMatrix=u.Zero(),this._transformMatrix=u.Zero(),this._cachedPosition=new d(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),this._cachedDirection=new d(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),this._currentFaceIndex=0,this._currentFaceIndexCache=0,this._defaultTextureMatrix=u.Identity(),this._shadersLoaded=!1,this._mapSize=e,this._light=t,this._usefullFloatFirst=!!s,this._scene=t.getScene(),this._camera=i??null,this._useRedTextureType=!!r,this._forceGLSL=a,this._createInstance()}_createInstance(){this._initShaderSourceAsync(this._forceGLSL);let e=this._light._shadowGenerators;e||(e=this._light._shadowGenerators=new Map),e.set(this._camera,this),this.id=this._light.id,this._useUBO=this._scene.getEngine().supportsUniformBuffers,this._useUBO&&(this._sceneUBOs=[this._scene.createSceneUniformBuffer(`Scene for Shadow Generator (light "${this._light.name}")`,{forceMono:!0})]),C(D),D._SceneComponentInitialization(this._scene),p();const s=this._scene.getEngine().getCaps();this._usefullFloatFirst?s.textureFloatRender&&s.textureFloatLinearFiltering?this._textureType=t.TEXTURETYPE_FLOAT:s.textureHalfFloatRender&&s.textureHalfFloatLinearFiltering?this._textureType=t.TEXTURETYPE_HALF_FLOAT:this._textureType=t.TEXTURETYPE_UNSIGNED_BYTE:s.textureHalfFloatRender&&s.textureHalfFloatLinearFiltering?this._textureType=t.TEXTURETYPE_HALF_FLOAT:s.textureFloatRender&&s.textureFloatLinearFiltering?this._textureType=t.TEXTURETYPE_FLOAT:this._textureType=t.TEXTURETYPE_UNSIGNED_BYTE,this._initializeGenerator(),this._applyFilterValues()}_initializeGenerator(){this._light._markMeshesAsLightDirty(),this._initializeShadowMap()}_createTargetRenderTexture(){const e=this._scene.getEngine();this._shadowMap?.dispose(),e._features.supportDepthStencilTexture?(this._shadowMap=new c(this._light.name+"_shadowMap",this._mapSize,this._scene,!1,!0,this._textureType,this._light.needCube(),void 0,!1,!1,void 0,this._useRedTextureType?t.TEXTUREFORMAT_RED:t.TEXTUREFORMAT_RGBA),this._shadowMap.createDepthStencilTexture(e.useReverseDepthBuffer?t.GREATER:t.LESS,!0,void 0,void 0,void 0,`DepthStencilForShadowGenerator-${this._light.name}`)):this._shadowMap=new c(this._light.name+"_shadowMap",this._mapSize,this._scene,!1,!0,this._textureType,this._light.needCube()),this._shadowMap.noPrePassRenderer=!0}_initializeShadowMap(){if(this._createTargetRenderTexture(),null===this._shadowMap)return;this._shadowMap.wrapU=e.CLAMP_ADDRESSMODE,this._shadowMap.wrapV=e.CLAMP_ADDRESSMODE,this._shadowMap.anisotropicFilteringLevel=1,this._shadowMap.updateSamplingMode(e.BILINEAR_SAMPLINGMODE),this._shadowMap.renderParticles=!1,this._shadowMap.ignoreCameraViewport=!0,this._storedUniqueId&&(this._shadowMap.uniqueId=this._storedUniqueId),this._shadowMap.customRenderFunction=(e,t,s,i)=>this._renderForShadowMap(e,t,s,i),this._shadowMap.customIsReadyFunction=(e,t,s)=>{if(!s||!e.subMeshes)return!0;let i=!0;for(const t of e.subMeshes){const e=t.getRenderingMesh(),s=this._scene.getEngine(),r=t.getMaterial();if(!r||0===t.verticesCount||this.customAllowRendering&&!this.customAllowRendering(t))continue;const a=e._getInstancesRenderList(t._id,!!t.getReplacementMesh());if(a.mustReturn)continue;const n=s.getCaps().instancedArrays&&(null!==a.visibleInstances[t._id]&&void 0!==a.visibleInstances[t._id]||e.hasThinInstances),o=r.needAlphaBlendingForMesh(e);i=this.isReady(t,n,o)&&i}return i};const t=this._scene.getEngine();this._shadowMap.onBeforeBindObservable.add(()=>{this._currentSceneUBO=this._scene.getSceneUniformBuffer(),t._enableGPUDebugMarkers&&t._debugPushGroup?.(`Shadow map generation for pass id ${t.currentRenderPassId}`)}),this._shadowMap.onBeforeRenderObservable.add(e=>{this._sceneUBOs&&this._scene.setSceneUniformBuffer(this._sceneUBOs[0]),this._currentFaceIndex=e,this._filter===D.FILTER_PCF&&t.setColorWrite(!1),this.getTransformMatrix(),_.eyeAtCamera=!1,this._scene.setTransformMatrix(this._viewMatrix,this._projectionMatrix),this._sceneUBOs&&(this._scene.getSceneUniformBuffer().unbindEffect(),this._scene.finalizeSceneUbo())}),this._shadowMap.onAfterUnbindObservable.add(()=>{if(this._sceneUBOs&&this._scene.setSceneUniformBuffer(this._currentSceneUBO),_.eyeAtCamera=!0,this._scene.updateTransformMatrix(),this._filter===D.FILTER_PCF&&t.setColorWrite(!0),!this.useBlurExponentialShadowMap&&!this.useBlurCloseExponentialShadowMap)return void t._debugPopGroup?.();const e=this.getShadowMapForRendering();e&&(this._scene.postProcessManager.directRender(this._blurPostProcesses,e.renderTarget,!0),t.unBindFramebuffer(e.renderTarget,!0)),t._enableGPUDebugMarkers&&t._debugPopGroup?.()});const s=new f(0,0,0,0),i=new f(1,1,1,1);this._shadowMap.onClearObservable.add(e=>{this._filter===D.FILTER_PCF?e.clear(i,!1,!0,!1):this.useExponentialShadowMap||this.useBlurExponentialShadowMap?e.clear(s,!0,!0,!1):e.clear(i,!0,!0,!1)}),this._shadowMap.onResizeObservable.add(e=>{this._storedUniqueId=this._shadowMap.uniqueId,this._mapSize=e.getRenderSize(),this._light._markMeshesAsLightDirty(),this.recreateShadowMap()});for(let e=g.MIN_RENDERINGGROUPS;e<g.MAX_RENDERINGGROUPS;e++)this._shadowMap.setRenderingAutoClearDepthStencil(e,!1)}async _initShaderSourceAsync(e=!1){!this._scene.getEngine().isWebGPU||e||D.ForceGLSL?await Promise.all([import("./shadowMap.fragment-DzoWjjXo.esm.min.js"),import("./shadowMap.vertex-Bz5mhxJC.esm.min.js"),import("./depthBoxBlur.fragment-CHy80enr.esm.min.js"),import("./shadowMapFragmentSoftTransparentShadow-DmLkXcDZ.esm.min.js")]):(this._shaderLanguage=1,await Promise.all([import("./shadowMap.fragment-D_NAiBht.esm.min.js"),import("./shadowMap.vertex-BDssCPK8.esm.min.js"),import("./depthBoxBlur.fragment-igMvbpEA.esm.min.js"),import("./shadowMapFragmentSoftTransparentShadow-b_ty-OS9.esm.min.js")])),this._shadersLoaded=!0}_initializeBlurRTTAndPostProcesses(){const s=this._scene.getEngine(),i=this._mapSize/this.blurScale;this.useKernelBlur&&1===this.blurScale||(this._shadowMap2=new c(this._light.name+"_shadowMap2",i,this._scene,!1,!0,this._textureType,void 0,void 0,!1),this._shadowMap2.wrapU=e.CLAMP_ADDRESSMODE,this._shadowMap2.wrapV=e.CLAMP_ADDRESSMODE,this._shadowMap2.updateSamplingMode(e.BILINEAR_SAMPLINGMODE)),this.useKernelBlur?(this._kernelBlurXPostprocess=new N(this._light.name+"KernelBlurX",new S(1,0),this.blurKernel,1,null,e.BILINEAR_SAMPLINGMODE,s,!1,this._textureType),this._kernelBlurXPostprocess.width=i,this._kernelBlurXPostprocess.height=i,this._kernelBlurXPostprocess.externalTextureSamplerBinding=!0,this._kernelBlurXPostprocess.onApplyObservable.add(e=>{e.setTexture("textureSampler",this._shadowMap)}),this._kernelBlurYPostprocess=new N(this._light.name+"KernelBlurY",new S(0,1),this.blurKernel,1,null,e.BILINEAR_SAMPLINGMODE,s,!1,this._textureType),this._kernelBlurXPostprocess.autoClear=!1,this._kernelBlurYPostprocess.autoClear=!1,this._textureType===t.TEXTURETYPE_UNSIGNED_BYTE&&(this._kernelBlurXPostprocess.packedFloat=!0,this._kernelBlurYPostprocess.packedFloat=!0),this._blurPostProcesses=[this._kernelBlurXPostprocess,this._kernelBlurYPostprocess]):(this._boxBlurPostprocess=new a(this._light.name+"DepthBoxBlur","depthBoxBlur",["screenSize","boxOffset"],[],1,null,e.BILINEAR_SAMPLINGMODE,s,!1,"#define OFFSET "+this._blurBoxOffset,this._textureType,void 0,void 0,void 0,void 0,this._shaderLanguage),this._boxBlurPostprocess.externalTextureSamplerBinding=!0,this._boxBlurPostprocess.onApplyObservable.add(e=>{e.setFloat2("screenSize",i,i),e.setTexture("textureSampler",this._shadowMap)}),this._boxBlurPostprocess.autoClear=!1,this._blurPostProcesses=[this._boxBlurPostprocess])}_renderForShadowMap(e,t,s,i){let r;if(i.length)for(r=0;r<i.length;r++)this._renderSubMeshForShadowMap(i.data[r]);for(r=0;r<e.length;r++)this._renderSubMeshForShadowMap(e.data[r]);for(r=0;r<t.length;r++)this._renderSubMeshForShadowMap(t.data[r]);if(this._transparencyShadow)for(r=0;r<s.length;r++)this._renderSubMeshForShadowMap(s.data[r],!0);else for(r=0;r<s.length;r++)s.data[r].getEffectiveMesh()._internalAbstractMeshDataInfo._isActiveIntermediate=!1}_bindCustomEffectForRenderSubMeshForShadowMap(e,t,s){t.setMatrix("viewProjection",this.getTransformMatrix())}_renderSubMeshForShadowMap(e,s=!1){const i=e.getRenderingMesh(),r=e.getEffectiveMesh(),a=this._scene,n=a.getEngine(),o=e.getMaterial();if(r._internalAbstractMeshDataInfo._isActiveIntermediate=!1,!o||0===e.verticesCount||e._renderId===a.getRenderId())return;const h=a.useRightHandedSystem,l=r._getWorldMatrixDeterminant()<0;let d=o._getEffectiveOrientation(i);(l&&!h||!l&&h)&&(d=d===t.MATERIAL_ClockWiseSideOrientation?t.MATERIAL_CounterClockWiseSideOrientation:t.MATERIAL_ClockWiseSideOrientation);const u=d===t.MATERIAL_ClockWiseSideOrientation;n.setState(o.backFaceCulling,void 0,void 0,u,o.cullBackFaces);const p=i._getInstancesRenderList(e._id,!!e.getReplacementMesh());if(p.mustReturn)return;const c=n.getCaps().instancedArrays&&(null!==p.visibleInstances[e._id]&&void 0!==p.visibleInstances[e._id]||i.hasThinInstances);if(!this.customAllowRendering||this.customAllowRendering(e))if(this.isReady(e,c,s)){e._renderId=a.getRenderId();const t=o.shadowDepthWrapper,h=t?.getEffect(e,this,n.currentRenderPassId)??e._getDrawWrapper(),l=M.GetEffect(h);n.enableEffect(h),c||i._bind(e,l,o.fillMode),this.getTransformMatrix(),l.setFloat3("biasAndScaleSM",this.bias,this.normalBias,this.depthScale),this.getLight().getTypeID()===E.LIGHTTYPEID_DIRECTIONALLIGHT?l.setVector3("lightDataSM",this._cachedDirection):l.setVector3("lightDataSM",this._cachedPosition.subtractToRef(this._scene.floatingOriginOffset,T.Vector3[0]));const d=this._getCamera();if(l.setFloat2("depthValuesSM",this.getLight().getDepthMinZ(d),this.getLight().getDepthMinZ(d)+this.getLight().getDepthMaxZ(d)),s&&this.enableSoftTransparentShadow&&l.setFloat2("softTransparentShadowSM",r.visibility*o.alpha,this._opacityTexture?.getAlphaFromRGB?1:0),t)e._setMainDrawWrapperOverride(h),t.standalone?t.baseMaterial.bindForSubMesh(r.getWorldMatrix(),i,e):o.bindForSubMesh(r.getWorldMatrix(),i,e),e._setMainDrawWrapperOverride(null);else{this._opacityTexture&&(l.setTexture("diffuseSampler",this._opacityTexture),l.setMatrix("diffuseMatrix",this._opacityTexture.getTextureMatrix()||this._defaultTextureMatrix)),m(i,l),w(i,l),i.morphTargetManager&&i.morphTargetManager.isUsingTextureForTargets&&i.morphTargetManager._bind(l);const t=e.getMesh().bakedVertexAnimationManager;t&&t.isEnabled&&t.bind(l,c),L(l,o,a)}this._useUBO||t||this._bindCustomEffectForRenderSubMeshForShadowMap(e,l,r),x(l,this._scene.getSceneUniformBuffer()),this._scene.getSceneUniformBuffer().bindUniformBuffer();const u=r.getWorldMatrix();c&&(r.getMeshUniformBuffer().bindToEffect(l,"Mesh"),r.transferToEffect(u)),this.forceBackFacesOnly&&n.setState(!0,0,!1,!0,o.cullBackFaces),this.onBeforeShadowMapRenderMeshObservable.notifyObservers(i),this.onBeforeShadowMapRenderObservable.notifyObservers(l),i._processRendering(r,e,l,o.fillMode,p,c,(e,t)=>{r===i||e?(r.getMeshUniformBuffer().bindToEffect(l,"Mesh"),r.transferToEffect(e?t:u)):(i.getMeshUniformBuffer().bindToEffect(l,"Mesh"),i.transferToEffect(t))}),this.forceBackFacesOnly&&n.setState(!0,0,!1,!1,o.cullBackFaces),this.onAfterShadowMapRenderObservable.notifyObservers(l),this.onAfterShadowMapRenderMeshObservable.notifyObservers(i)}else this._shadowMap&&this._shadowMap.resetRefreshCounter()}_applyFilterValues(){this._shadowMap&&(this.filter===D.FILTER_NONE||this.filter===D.FILTER_PCSS?this._shadowMap.updateSamplingMode(e.NEAREST_SAMPLINGMODE):this._shadowMap.updateSamplingMode(e.BILINEAR_SAMPLINGMODE))}forceCompilation(e,t){const s={useInstances:!1,...t},i=this.getShadowMap();if(!i)return void(e&&e(this));const r=i.renderList;if(!r)return void(e&&e(this));const a=[];for(const e of r)a.push(...e.subMeshes);if(0===a.length)return void(e&&e(this));let n=0;const o=()=>{if(this._scene&&this._scene.getEngine()){for(;this.isReady(a[n],s.useInstances,a[n].getMaterial()?.needAlphaBlendingForMesh(a[n].getMesh())??!1);)if(n++,n>=a.length)return void(e&&e(this));setTimeout(o,16)}};o()}async forceCompilationAsync(e){return await new Promise(t=>{this.forceCompilation(()=>{t()},e)})}_isReadyCustomDefines(e,t,s){}_prepareShadowDefines(e,s,i,r){i.push("#define SM_LIGHTTYPE_"+this._light.getClassName().toUpperCase()),i.push("#define SM_FLOAT "+(this._textureType!==t.TEXTURETYPE_UNSIGNED_BYTE?"1":"0")),i.push("#define SM_ESM "+(this.useExponentialShadowMap||this.useBlurExponentialShadowMap?"1":"0")),i.push("#define SM_DEPTHTEXTURE "+(this.usePercentageCloserFiltering||this.useContactHardeningShadow?"1":"0"));const a=e.getMesh();return i.push("#define SM_NORMALBIAS "+(this.normalBias&&a.isVerticesDataPresent(I.NormalKind)?"1":"0")),i.push("#define SM_DIRECTIONINLIGHTDATA "+(this.getLight().getTypeID()===E.LIGHTTYPEID_DIRECTIONALLIGHT?"1":"0")),i.push("#define SM_USEDISTANCE "+(this._light.needCube()?"1":"0")),i.push("#define SM_SOFTTRANSPARENTSHADOW "+(this.enableSoftTransparentShadow&&r?"1":"0")),this._isReadyCustomDefines(i,e,s),i}isReady(e,t,s){if(!this._shadersLoaded)return!1;const i=e.getMaterial(),r=i?.shadowDepthWrapper;if(this._opacityTexture=null,!i)return!1;const a=[];if(this._prepareShadowDefines(e,t,a,s),r){if(!r.isReadyForSubMesh(e,a,this,t,this._scene.getEngine().currentRenderPassId))return!1}else{const s=e._getDrawWrapper(void 0,!0);let r=s.effect,n=s.defines;const o=[I.PositionKind],h=e.getMesh();let l=!1,d=!1,u=!1;const p=!1;this.normalBias&&h.isVerticesDataPresent(I.NormalKind)&&(o.push(I.NormalKind),a.push("#define NORMAL"),l=!0,h.nonUniformScaling&&a.push("#define NONUNIFORMSCALING"));const c=i.needAlphaTestingForMesh(h);if((c||i.needAlphaBlendingForMesh(h))&&(this.useOpacityTextureForTransparentShadow?this._opacityTexture=i.opacityTexture:this._opacityTexture=i.getAlphaTestTexture(),this._opacityTexture)){if(!this._opacityTexture.isReady())return!1;const e=i.alphaCutOff??D.DEFAULT_ALPHA_CUTOFF;a.push("#define ALPHATEXTURE"),c&&a.push(`#define ALPHATESTVALUE ${e}${e%1==0?".":""}`),h.isVerticesDataPresent(I.UVKind)&&(o.push(I.UVKind),a.push("#define UV1"),d=!0),h.isVerticesDataPresent(I.UV2Kind)&&1===this._opacityTexture.coordinatesIndex&&(o.push(I.UV2Kind),a.push("#define UV2"),u=!0)}const _=new P;if(h.useBones&&h.computeBonesUsingShaders&&h.skeleton){o.push(I.MatricesIndicesKind),o.push(I.MatricesWeightsKind),h.numBoneInfluencers>4&&(o.push(I.MatricesIndicesExtraKind),o.push(I.MatricesWeightsExtraKind));const e=h.skeleton;a.push("#define NUM_BONE_INFLUENCERS "+h.numBoneInfluencers),h.numBoneInfluencers>0&&_.addCPUSkinningFallback(0,h),e.isUsingTextureForMatrices?a.push("#define BONETEXTURE"):a.push("#define BonesPerMesh "+(e.bones.length+1))}else a.push("#define NUM_BONE_INFLUENCERS 0");const f=h.morphTargetManager?b(h.morphTargetManager,a,o,h,!0,l,!1,d,u,p):0;if(A(i,this._scene,a),t&&(a.push("#define INSTANCES"),F(o),e.getRenderingMesh().hasThinInstances&&a.push("#define THIN_INSTANCES")),this.customShaderOptions&&this.customShaderOptions.defines)for(const e of this.customShaderOptions.defines)-1===a.indexOf(e)&&a.push(e);const g=h.bakedVertexAnimationManager;g&&g.isEnabled&&(a.push("#define BAKED_VERTEX_ANIMATION_TEXTURE"),t&&o.push("bakedVertexAnimationSettingsInstanced"));const S=a.join("\n");if(n!==S){n=S;let e="shadowMap";const t=["world","mBones","viewProjection","diffuseMatrix","lightDataSM","depthValuesSM","biasAndScaleSM","morphTargetInfluences","morphTargetCount","boneTextureInfo","softTransparentShadowSM","morphTargetTextureInfo","morphTargetTextureIndices","bakedVertexAnimationSettings","bakedVertexAnimationTextureSizeInverted","bakedVertexAnimationTime","bakedVertexAnimationTexture"],i=["diffuseSampler","boneSampler","morphTargets","bakedVertexAnimationTexture"],a=["Scene","Mesh"];if(O(t),this.customShaderOptions){if(e=this.customShaderOptions.shaderName,this.customShaderOptions.attributes)for(const e of this.customShaderOptions.attributes)-1===o.indexOf(e)&&o.push(e);if(this.customShaderOptions.uniforms)for(const e of this.customShaderOptions.uniforms)-1===t.indexOf(e)&&t.push(e);if(this.customShaderOptions.samplers)for(const e of this.customShaderOptions.samplers)-1===i.indexOf(e)&&i.push(e)}const h=this._scene.getEngine();r=h.createEffect(e,{attributes:o,uniformsNames:t,uniformBuffersNames:a,samplers:i,defines:S,fallbacks:_,onCompiled:null,onError:null,indexParameters:{maxSimultaneousMorphTargets:f},shaderLanguage:this._shaderLanguage},h),s.setEffect(r,n)}if(!r.isReady())return!1}return(this.useBlurExponentialShadowMap||this.useBlurCloseExponentialShadowMap)&&(this._blurPostProcesses&&this._blurPostProcesses.length||this._initializeBlurRTTAndPostProcesses()),!(this._kernelBlurXPostprocess&&!this._kernelBlurXPostprocess.isReady())&&(!(this._kernelBlurYPostprocess&&!this._kernelBlurYPostprocess.isReady())&&!(this._boxBlurPostprocess&&!this._boxBlurPostprocess.isReady()))}prepareDefines(e,t){const s=this._scene,i=this._light;s.shadowsEnabled&&i.shadowEnabled&&(e["SHADOW"+t]=!0,this.useContactHardeningShadow?(e["SHADOWPCSS"+t]=!0,this._filteringQuality===D.QUALITY_LOW?e["SHADOWLOWQUALITY"+t]=!0:this._filteringQuality===D.QUALITY_MEDIUM&&(e["SHADOWMEDIUMQUALITY"+t]=!0)):this.usePercentageCloserFiltering?(e["SHADOWPCF"+t]=!0,this._filteringQuality===D.QUALITY_LOW?e["SHADOWLOWQUALITY"+t]=!0:this._filteringQuality===D.QUALITY_MEDIUM&&(e["SHADOWMEDIUMQUALITY"+t]=!0)):this.usePoissonSampling?e["SHADOWPOISSON"+t]=!0:this.useExponentialShadowMap||this.useBlurExponentialShadowMap?e["SHADOWESM"+t]=!0:(this.useCloseExponentialShadowMap||this.useBlurCloseExponentialShadowMap)&&(e["SHADOWCLOSEESM"+t]=!0),i.needCube()&&(e["SHADOWCUBE"+t]=!0))}bindShadowLight(e,t){const s=this._light,i=this._scene;if(!i.shadowsEnabled||!s.shadowEnabled)return;const r=this._getCamera(),a=this.getShadowMap();if(!a)return;if(!s.needCube()){const s=i.floatingOriginOffset,r=this.getTransformMatrix(),a=i.floatingOriginMode?R(s,this._viewMatrix,this._projectionMatrix,T.Matrix[0]):r;t.setMatrix("lightMatrix"+e,a)}const n=this.getShadowMapForRendering();this._filter===D.FILTER_PCF?(t.setDepthStencilTexture("shadowTexture"+e,n),s._uniformBuffer.updateFloat4("shadowsInfo",this.getDarkness(),a.getSize().width,1/a.getSize().width,this.frustumEdgeFalloff,e)):this._filter===D.FILTER_PCSS?(t.setDepthStencilTexture("shadowTexture"+e,n),t.setTexture("depthTexture"+e,n),s._uniformBuffer.updateFloat4("shadowsInfo",this.getDarkness(),1/a.getSize().width,this._contactHardeningLightSizeUVRatio*a.getSize().width,this.frustumEdgeFalloff,e)):(t.setTexture("shadowTexture"+e,n),s._uniformBuffer.updateFloat4("shadowsInfo",this.getDarkness(),this.blurScale/a.getSize().width,this.depthScale,this.frustumEdgeFalloff,e)),s._uniformBuffer.updateFloat2("depthValues",this.getLight().getDepthMinZ(r),this.getLight().getDepthMinZ(r)+this.getLight().getDepthMaxZ(r),e)}get viewMatrix(){return this._viewMatrix}get projectionMatrix(){return this._projectionMatrix}getTransformMatrix(){const e=this._scene;if(this._currentRenderId===e.getRenderId()&&this._currentFaceIndexCache===this._currentFaceIndex)return this._transformMatrix;this._currentRenderId=e.getRenderId(),this._currentFaceIndexCache=this._currentFaceIndex;let t=this._light.position;if(this._light.computeTransformedInformation()&&(t=this._light.transformedPosition),d.NormalizeToRef(this._light.getShadowDirection(this._currentFaceIndex),this._lightDirection),1===Math.abs(d.Dot(this._lightDirection,d.Up()))&&(this._lightDirection.z=1e-13),this._light.needProjectionMatrixCompute()||!this._cachedPosition||!this._cachedDirection||!t.equals(this._cachedPosition)||!this._lightDirection.equals(this._cachedDirection)){this._cachedPosition.copyFrom(t),this._cachedDirection.copyFrom(this._lightDirection),u.LookAtLHToRef(t,t.add(this._lightDirection),d.Up(),this._viewMatrix);const e=this.getShadowMap();if(e){const t=e.renderList;t&&this._light.setShadowProjectionMatrix(this._projectionMatrix,this._viewMatrix,t)}this._viewMatrix.multiplyToRef(this._projectionMatrix,this._transformMatrix)}return this._transformMatrix}recreateShadowMap(){const e=this._shadowMap;if(!e)return;const t=e.renderList;if(this._disposeRTTandPostProcesses(),this._initializeGenerator(),this.filter=this._filter,this._applyFilterValues(),t){this._shadowMap.renderList||(this._shadowMap.renderList=[]);for(const e of t)this._shadowMap.renderList.push(e)}else this._shadowMap.renderList=null}_disposeBlurPostProcesses(){this._shadowMap2&&(this._shadowMap2.dispose(),this._shadowMap2=null),this._boxBlurPostprocess&&(this._boxBlurPostprocess.dispose(),this._boxBlurPostprocess=null),this._kernelBlurXPostprocess&&(this._kernelBlurXPostprocess.dispose(),this._kernelBlurXPostprocess=null),this._kernelBlurYPostprocess&&(this._kernelBlurYPostprocess.dispose(),this._kernelBlurYPostprocess=null),this._blurPostProcesses=[]}_disposeRTTandPostProcesses(){this._shadowMap&&(this._shadowMap.dispose(),this._shadowMap=null),this._disposeBlurPostProcesses()}_disposeSceneUBOs(){if(this._sceneUBOs){for(const e of this._sceneUBOs)e.dispose();this._sceneUBOs=[]}}dispose(e=!0){if(this._disposeRTTandPostProcesses(),this._disposeSceneUBOs(),this._light){if(this._light._shadowGenerators){const e=this._light._shadowGenerators.entries();for(let t=e.next();!0!==t.done;t=e.next()){const[e,s]=t.value;s===this&&this._light._shadowGenerators.delete(e)}0===this._light._shadowGenerators.size&&(this._light._shadowGenerators=null)}this._light._markMeshesAsLightDirty()}e&&(this.onBeforeShadowMapRenderMeshObservable.clear(),this.onBeforeShadowMapRenderObservable.clear(),this.onAfterShadowMapRenderMeshObservable.clear(),this.onAfterShadowMapRenderObservable.clear())}serialize(){const e={},t=this.getShadowMap();if(!t)return e;if(e.className=this.getClassName(),e.lightId=this._light.id,e.cameraId=this._camera?.id,e.id=this.id,e.mapSize=t.getRenderSize(),e.forceBackFacesOnly=this.forceBackFacesOnly,e.darkness=this.getDarkness(),e.transparencyShadow=this._transparencyShadow,e.frustumEdgeFalloff=this.frustumEdgeFalloff,e.bias=this.bias,e.normalBias=this.normalBias,e.usePercentageCloserFiltering=this.usePercentageCloserFiltering,e.useContactHardeningShadow=this.useContactHardeningShadow,e.contactHardeningLightSizeUVRatio=this.contactHardeningLightSizeUVRatio,e.filteringQuality=this.filteringQuality,e.useExponentialShadowMap=this.useExponentialShadowMap,e.useBlurExponentialShadowMap=this.useBlurExponentialShadowMap,e.useCloseExponentialShadowMap=this.useBlurExponentialShadowMap,e.useBlurCloseExponentialShadowMap=this.useBlurExponentialShadowMap,e.usePoissonSampling=this.usePoissonSampling,e.depthScale=this.depthScale,e.blurBoxOffset=this.blurBoxOffset,e.blurKernel=this.blurKernel,e.blurScale=this.blurScale,e.useKernelBlur=this.useKernelBlur,e.renderList=[],t.renderList)for(let s=0;s<t.renderList.length;s++){const i=t.renderList[s];e.renderList.push(i.id)}return e}static Parse(e,t,s){const i=t.getLightById(e.lightId),r=void 0!==e.cameraId?t.getCameraById(e.cameraId):null,a=s?s(e.mapSize,i,r):new D(e.mapSize,i,void 0,r),n=a.getShadowMap();if(e.renderList.length&&n){const s=new Set(e.renderList);let i=n.renderList;i||(i=n.renderList=[]);const r=t.meshes;for(const e of r)s.has(e.id)&&i.push(e)}return void 0!==e.id&&(a.id=e.id),a.forceBackFacesOnly=!!e.forceBackFacesOnly,void 0!==e.darkness&&a.setDarkness(e.darkness),e.transparencyShadow&&a.setTransparencyShadow(!0),void 0!==e.frustumEdgeFalloff&&(a.frustumEdgeFalloff=e.frustumEdgeFalloff),void 0!==e.bias&&(a.bias=e.bias),void 0!==e.normalBias&&(a.normalBias=e.normalBias),e.usePercentageCloserFiltering?a.usePercentageCloserFiltering=!0:e.useContactHardeningShadow?a.useContactHardeningShadow=!0:e.usePoissonSampling?a.usePoissonSampling=!0:e.useExponentialShadowMap?a.useExponentialShadowMap=!0:e.useBlurExponentialShadowMap?a.useBlurExponentialShadowMap=!0:e.useCloseExponentialShadowMap?a.useCloseExponentialShadowMap=!0:e.useBlurCloseExponentialShadowMap?a.useBlurCloseExponentialShadowMap=!0:e.useVarianceShadowMap?a.useExponentialShadowMap=!0:e.useBlurVarianceShadowMap&&(a.useBlurExponentialShadowMap=!0),void 0!==e.contactHardeningLightSizeUVRatio&&(a.contactHardeningLightSizeUVRatio=e.contactHardeningLightSizeUVRatio),void 0!==e.filteringQuality&&(a.filteringQuality=e.filteringQuality),e.depthScale&&(a.depthScale=e.depthScale),e.blurScale&&(a.blurScale=e.blurScale),e.blurBoxOffset&&(a.blurBoxOffset=e.blurBoxOffset),e.useKernelBlur&&(a.useKernelBlur=e.useKernelBlur),e.blurKernel&&(a.blurKernel=e.blurKernel),a}}D.CLASSNAME="ShadowGenerator",D.ForceGLSL=!1,D.FILTER_NONE=0,D.FILTER_EXPONENTIALSHADOWMAP=1,D.FILTER_POISSONSAMPLING=2,D.FILTER_BLUREXPONENTIALSHADOWMAP=3,D.FILTER_CLOSEEXPONENTIALSHADOWMAP=4,D.FILTER_BLURCLOSEEXPONENTIALSHADOWMAP=5,D.FILTER_PCF=6,D.FILTER_PCSS=7,D.QUALITY_HIGH=0,D.QUALITY_MEDIUM=1,D.QUALITY_LOW=2,D.DEFAULT_ALPHA_CUTOFF=.5,D._SceneComponentInitialization=e=>{throw B("ShadowGeneratorSceneComponent")},D._CascadedShadowGeneratorParser=null;export{D as ShadowGenerator};
//# sourceMappingURL=shadowGenerator-DGYa6LR1.esm.min.js.map