@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) • 35.3 kB
JavaScript
import{E as e,k as t,P as s,T as i,C as r,Y as a,u as n,a5 as o,v as h,R as l,O as d,V as u,M as p,h as _,j as c,a6 as f,a7 as g,J as S,a8 as M,s as E,r as m,q as T,m as w,$ as L,n as x,p as P,o as I,A as B,_ as A}from"./index-Bw2N6w1y.esm.min.js";class F extends e{_gatherImports(e,t){e?(this._webGPUReady=!0,t.push(Promise.all([import("./kernelBlur.fragment-66QP8ubN.esm.min.js"),import("./kernelBlur.vertex-BI1ir6p4.esm.min.js")]))):t.push(Promise.all([import("./kernelBlur.fragment-B5r8A6R2.esm.min.js"),import("./kernelBlur.vertex-BnEkTYAZ.esm.min.js")]))}constructor(e,s=null,i,r,a){const n=!!a?.blockCompilation;super({...a,name:e,engine:s||t.LastCreatedEngine,useShaderStore:!0,useAsPostProcess:!0,fragmentShader:F.FragmentUrl,uniforms:F.Uniforms,samplers:F.Samplers,vertexUrl:F.VertexUrl,blockCompilation:!0}),this._packedFloat=!1,this._staticDefines="",this.textureWidth=0,this.textureHeight=0,this._staticDefines=a?Array.isArray(a.defines)?a.defines.join("\n"):a.defines||"":"",this.options.blockCompilation=n,void 0!==i&&(this.direction=i),void 0!==r&&(this.kernel=r)}set kernel(e){this._idealKernel!==e&&(e=Math.max(e,1),this._idealKernel=e,this._kernel=this._nearestBestKernel(e),this.options.blockCompilation||this._updateParameters())}get kernel(){return this._idealKernel}set packedFloat(e){this._packedFloat!==e&&(this._packedFloat=e,this.options.blockCompilation||this._updateParameters())}get packedFloat(){return this._packedFloat}bind(e=!1){super.bind(e),this._drawWrapper.effect.setFloat2("delta",1/this.textureWidth*this.direction.x,1/this.textureHeight*this.direction.y)}_updateParameters(e,t){const s=this._kernel,i=(s-1)/2;let r=[],a=[],n=0;for(let e=0;e<s;e++){const t=e/(s-1),o=this._gaussianWeight(2*t-1);r[e]=e-i,a[e]=o,n+=o}for(let e=0;e<a.length;e++)a[e]/=n;const o=[],h=[],l=[];for(let e=0;e<=i;e+=2){const t=Math.min(e+1,Math.floor(i));if(e===t)l.push({o:r[e],w:a[e]});else{const s=t===i,n=a[e]+a[t]*(s?.5:1),o=r[e]+1/(1+a[e]/a[t]);0===o?(l.push({o:r[e],w:a[e]}),l.push({o:r[e+1],w:a[e+1]})):(l.push({o:o,w:n}),l.push({o:-o,w:n}))}}for(let e=0;e<l.length;e++)h[e]=l[e].o,o[e]=l[e].w;r=h,a=o;const d=this.options.engine.getCaps().maxVaryingVectors-(1===this.options.shaderLanguage?1:0),u=Math.max(d,0)-1;let p=Math.min(r.length,u),_="";_+=this._staticDefines,-1!=this._staticDefines.indexOf("DOF")&&(_+=`#define CENTER_WEIGHT ${this._glslFloat(a[p-1])}\n`,p--);for(let e=0;e<p;e++)_+=`#define KERNEL_OFFSET${e} ${this._glslFloat(r[e])}\n`,_+=`#define KERNEL_WEIGHT${e} ${this._glslFloat(a[e])}\n`;let c=0;for(let e=u;e<r.length;e++)_+=`#define KERNEL_DEP_OFFSET${c} ${this._glslFloat(r[e])}\n`,_+=`#define KERNEL_DEP_WEIGHT${c} ${this._glslFloat(a[e])}\n`,c++;this.packedFloat&&(_+="#define PACKEDFLOAT 1"),this.options.blockCompilation=!1,this.updateEffect(_,null,null,{varyingCount:p,depCount:c},e,t)}_nearestBestKernel(e){const t=Math.round(e);for(const e of[t,t-1,t+1,t-2,t+2])if(e%2!=0&&Math.floor(e/2)%2==0&&e>0)return Math.max(e,3);return Math.max(t,3)}_gaussianWeight(e){const t=1/3,s=-e*e/(2*t*t);return 1/(Math.sqrt(2*Math.PI)*t)*Math.exp(s)}_glslFloat(e,t=8){return e.toFixed(t).replace(/0+$/,"")}}F.VertexUrl="kernelBlur",F.FragmentUrl="kernelBlur",F.Uniforms=["delta","direction"],F.Samplers=["circleOfConfusionSampler"];class O extends s{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(e,t,s,a,n=null,o=i.BILINEAR_SAMPLINGMODE,h,l,d=r.TEXTURETYPE_UNSIGNED_BYTE,u="",p=!1,_=r.TEXTUREFORMAT_RGBA){const c="number"==typeof a?p:!!a.blockCompilation,f={uniforms:F.Uniforms,samplers:F.Samplers,size:"number"==typeof a?a:void 0,camera:n,samplingMode:o,engine:h,reusable:l,textureType:d,vertexUrl:F.VertexUrl,indexParameters:{varyingCount:0,depCount:0},textureFormat:_,defines:u,...a,blockCompilation:!0};super(e,F.FragmentUrl,{effectWrapper:"number"!=typeof a&&a.effectWrapper?void 0:new F(e,h,void 0,void 0,f),...f}),this._effectWrapper.options.blockCompilation=c,this.direction=t,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=s}updateEffect(e=null,t=null,s=null,i,r,a){this._effectWrapper._updateParameters(r,a)}static _Parse(e,t,s,i){return a.Parse((()=>new O(e.name,e.direction,e.kernel,e.options,t,e.renderTargetSamplingMode,s.getEngine(),e.reusable,e.textureType,void 0,!1)),e,s,i)}}n([o()],O.prototype,"direction",null),n([h()],O.prototype,"kernel",null),n([h()],O.prototype,"packedFloat",null),l("BABYLON.BlurPostProcess",O);class R{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===R.FILTER_BLUREXPONENTIALSHADOWMAP)return void(this.useExponentialShadowMap=!0);if(e===R.FILTER_BLURCLOSEEXPONENTIALSHADOWMAP)return void(this.useCloseExponentialShadowMap=!0);if(e===R.FILTER_PCF||e===R.FILTER_PCSS)return void(this.usePoissonSampling=!0)}e!==R.FILTER_PCF&&e!==R.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===R.FILTER_POISSONSAMPLING}set usePoissonSampling(e){const t=this._validateFilter(R.FILTER_POISSONSAMPLING);(e||this.filter===R.FILTER_POISSONSAMPLING)&&(this.filter=e?t:R.FILTER_NONE)}get useExponentialShadowMap(){return this.filter===R.FILTER_EXPONENTIALSHADOWMAP}set useExponentialShadowMap(e){const t=this._validateFilter(R.FILTER_EXPONENTIALSHADOWMAP);(e||this.filter===R.FILTER_EXPONENTIALSHADOWMAP)&&(this.filter=e?t:R.FILTER_NONE)}get useBlurExponentialShadowMap(){return this.filter===R.FILTER_BLUREXPONENTIALSHADOWMAP}set useBlurExponentialShadowMap(e){const t=this._validateFilter(R.FILTER_BLUREXPONENTIALSHADOWMAP);(e||this.filter===R.FILTER_BLUREXPONENTIALSHADOWMAP)&&(this.filter=e?t:R.FILTER_NONE)}get useCloseExponentialShadowMap(){return this.filter===R.FILTER_CLOSEEXPONENTIALSHADOWMAP}set useCloseExponentialShadowMap(e){const t=this._validateFilter(R.FILTER_CLOSEEXPONENTIALSHADOWMAP);(e||this.filter===R.FILTER_CLOSEEXPONENTIALSHADOWMAP)&&(this.filter=e?t:R.FILTER_NONE)}get useBlurCloseExponentialShadowMap(){return this.filter===R.FILTER_BLURCLOSEEXPONENTIALSHADOWMAP}set useBlurCloseExponentialShadowMap(e){const t=this._validateFilter(R.FILTER_BLURCLOSEEXPONENTIALSHADOWMAP);(e||this.filter===R.FILTER_BLURCLOSEEXPONENTIALSHADOWMAP)&&(this.filter=e?t:R.FILTER_NONE)}get usePercentageCloserFiltering(){return this.filter===R.FILTER_PCF}set usePercentageCloserFiltering(e){const t=this._validateFilter(R.FILTER_PCF);(e||this.filter===R.FILTER_PCF)&&(this.filter=e?t:R.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===R.FILTER_PCSS}set useContactHardeningShadow(e){const t=this._validateFilter(R.FILTER_PCSS);(e||this.filter===R.FILTER_PCSS)&&(this.filter=e?t:R.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 R.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()}constructor(e,t,s,i,a,n=!1){this.onBeforeShadowMapRenderObservable=new d,this.onAfterShadowMapRenderObservable=new d,this.onBeforeShadowMapRenderMeshObservable=new d,this.onAfterShadowMapRenderMeshObservable=new d,this.doNotSerialize=!1,this._bias=5e-5,this._normalBias=0,this._blurBoxOffset=1,this._blurScale=2,this._blurKernel=1,this._useKernelBlur=!1,this._filter=R.FILTER_NONE,this._filteringQuality=R.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=u.Zero(),this._viewMatrix=p.Zero(),this._projectionMatrix=p.Zero(),this._transformMatrix=p.Zero(),this._cachedPosition=new u(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),this._cachedDirection=new u(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),this._currentFaceIndex=0,this._currentFaceIndexCache=0,this._defaultTextureMatrix=p.Identity(),this._shadersLoaded=!1,this._mapSize=e,this._light=t,this._scene=t.getScene(),this._camera=i??null,this._useRedTextureType=!!a,this._initShaderSourceAsync(n);let o=t._shadowGenerators;o||(o=t._shadowGenerators=new Map),o.set(this._camera,this),this.id=t.id,this._useUBO=this._scene.getEngine().supportsUniformBuffers,this._useUBO&&(this._sceneUBOs=[],this._sceneUBOs.push(this._scene.createSceneUniformBuffer(`Scene for Shadow Generator (light "${this._light.name}")`))),R._SceneComponentInitialization(this._scene);const h=this._scene.getEngine().getCaps();s?h.textureFloatRender&&h.textureFloatLinearFiltering?this._textureType=r.TEXTURETYPE_FLOAT:h.textureHalfFloatRender&&h.textureHalfFloatLinearFiltering?this._textureType=r.TEXTURETYPE_HALF_FLOAT:this._textureType=r.TEXTURETYPE_UNSIGNED_BYTE:h.textureHalfFloatRender&&h.textureHalfFloatLinearFiltering?this._textureType=r.TEXTURETYPE_HALF_FLOAT:h.textureFloatRender&&h.textureFloatLinearFiltering?this._textureType=r.TEXTURETYPE_FLOAT:this._textureType=r.TEXTURETYPE_UNSIGNED_BYTE,this._initializeGenerator(),this._applyFilterValues()}_initializeGenerator(){this._light._markMeshesAsLightDirty(),this._initializeShadowMap()}_createTargetRenderTexture(){const e=this._scene.getEngine();e._features.supportDepthStencilTexture?(this._shadowMap=new _(this._light.name+"_shadowMap",this._mapSize,this._scene,!1,!0,this._textureType,this._light.needCube(),void 0,!1,!1,void 0,this._useRedTextureType?r.TEXTUREFORMAT_RED:r.TEXTUREFORMAT_RGBA),this._shadowMap.createDepthStencilTexture(e.useReverseDepthBuffer?r.GREATER:r.LESS,!0,void 0,void 0,void 0,`DepthStencilForShadowGenerator-${this._light.name}`)):this._shadowMap=new _(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=i.CLAMP_ADDRESSMODE,this._shadowMap.wrapV=i.CLAMP_ADDRESSMODE,this._shadowMap.anisotropicFilteringLevel=1,this._shadowMap.updateSamplingMode(i.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 e=this._scene.getEngine();this._shadowMap.onBeforeBindObservable.add((()=>{this._currentSceneUBO=this._scene.getSceneUniformBuffer(),e._debugPushGroup?.(`shadow map generation for pass id ${e.currentRenderPassId}`,1)})),this._shadowMap.onBeforeRenderObservable.add((t=>{this._sceneUBOs&&this._scene.setSceneUniformBuffer(this._sceneUBOs[0]),this._currentFaceIndex=t,this._filter===R.FILTER_PCF&&e.setColorWrite(!1),this.getTransformMatrix(),this._scene.setTransformMatrix(this._viewMatrix,this._projectionMatrix),this._useUBO&&(this._scene.getSceneUniformBuffer().unbindEffect(),this._scene.finalizeSceneUbo())})),this._shadowMap.onAfterUnbindObservable.add((()=>{if(this._sceneUBOs&&this._scene.setSceneUniformBuffer(this._currentSceneUBO),this._scene.updateTransformMatrix(),this._filter===R.FILTER_PCF&&e.setColorWrite(!0),!this.useBlurExponentialShadowMap&&!this.useBlurCloseExponentialShadowMap)return void e._debugPopGroup?.(1);const t=this.getShadowMapForRendering();t&&(this._scene.postProcessManager.directRender(this._blurPostProcesses,t.renderTarget,!0),e.unBindFramebuffer(t.renderTarget,!0)),e._debugPopGroup?.(1)}));const t=new c(0,0,0,0),s=new c(1,1,1,1);this._shadowMap.onClearObservable.add((e=>{this._filter===R.FILTER_PCF?e.clear(s,!1,!0,!1):this.useExponentialShadowMap||this.useBlurExponentialShadowMap?e.clear(t,!0,!0,!1):e.clear(s,!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=f.MIN_RENDERINGGROUPS;e<f.MAX_RENDERINGGROUPS;e++)this._shadowMap.setRenderingAutoClearDepthStencil(e,!1)}async _initShaderSourceAsync(e=!1){!this._scene.getEngine().isWebGPU||e||R.ForceGLSL?await Promise.all([import("./shadowMap.fragment-Dn69AfBP.esm.min.js"),import("./shadowMap.vertex-l-3GRWW_.esm.min.js"),import("./depthBoxBlur.fragment-WMA7sv2u.esm.min.js"),import("./shadowMapFragmentSoftTransparentShadow-DSqir0SI.esm.min.js")]):(this._shaderLanguage=1,await Promise.all([import("./shadowMap.fragment-BtpBR4ze.esm.min.js"),import("./shadowMap.vertex-DDdoqzOi.esm.min.js"),import("./depthBoxBlur.fragment-CqqnIt5_.esm.min.js"),import("./shadowMapFragmentSoftTransparentShadow-BJoAdttf.esm.min.js")])),this._shadersLoaded=!0}_initializeBlurRTTAndPostProcesses(){const e=this._scene.getEngine(),t=this._mapSize/this.blurScale;this.useKernelBlur&&1===this.blurScale||(this._shadowMap2=new _(this._light.name+"_shadowMap2",t,this._scene,!1,!0,this._textureType,void 0,void 0,!1),this._shadowMap2.wrapU=i.CLAMP_ADDRESSMODE,this._shadowMap2.wrapV=i.CLAMP_ADDRESSMODE,this._shadowMap2.updateSamplingMode(i.BILINEAR_SAMPLINGMODE)),this.useKernelBlur?(this._kernelBlurXPostprocess=new O(this._light.name+"KernelBlurX",new g(1,0),this.blurKernel,1,null,i.BILINEAR_SAMPLINGMODE,e,!1,this._textureType),this._kernelBlurXPostprocess.width=t,this._kernelBlurXPostprocess.height=t,this._kernelBlurXPostprocess.externalTextureSamplerBinding=!0,this._kernelBlurXPostprocess.onApplyObservable.add((e=>{e.setTexture("textureSampler",this._shadowMap)})),this._kernelBlurYPostprocess=new O(this._light.name+"KernelBlurY",new g(0,1),this.blurKernel,1,null,i.BILINEAR_SAMPLINGMODE,e,!1,this._textureType),this._kernelBlurXPostprocess.autoClear=!1,this._kernelBlurYPostprocess.autoClear=!1,this._textureType===r.TEXTURETYPE_UNSIGNED_BYTE&&(this._kernelBlurXPostprocess.packedFloat=!0,this._kernelBlurYPostprocess.packedFloat=!0),this._blurPostProcesses=[this._kernelBlurXPostprocess,this._kernelBlurYPostprocess]):(this._boxBlurPostprocess=new s(this._light.name+"DepthBoxBlur","depthBoxBlur",["screenSize","boxOffset"],[],1,null,i.BILINEAR_SAMPLINGMODE,e,!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",t,t),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,t=!1){const s=e.getRenderingMesh(),i=e.getEffectiveMesh(),a=this._scene,n=a.getEngine(),o=e.getMaterial();if(i._internalAbstractMeshDataInfo._isActiveIntermediate=!1,!o||0===e.verticesCount||e._renderId===a.getRenderId())return;const h=a.useRightHandedSystem,l=i._getWorldMatrixDeterminant()<0;let d=o._getEffectiveOrientation(s);(l&&!h||!l&&h)&&(d=d===r.MATERIAL_ClockWiseSideOrientation?r.MATERIAL_CounterClockWiseSideOrientation:r.MATERIAL_ClockWiseSideOrientation);const u=d===r.MATERIAL_ClockWiseSideOrientation;n.setState(o.backFaceCulling,void 0,void 0,u,o.cullBackFaces);const p=s._getInstancesRenderList(e._id,!!e.getReplacementMesh());if(p.mustReturn)return;const _=n.getCaps().instancedArrays&&(null!==p.visibleInstances[e._id]&&void 0!==p.visibleInstances[e._id]||s.hasThinInstances);if(!this.customAllowRendering||this.customAllowRendering(e))if(this.isReady(e,_,t)){e._renderId=a.getRenderId();const r=o.shadowDepthWrapper,h=r?.getEffect(e,this,n.currentRenderPassId)??e._getDrawWrapper(),l=S.GetEffect(h);n.enableEffect(h),_||s._bind(e,l,o.fillMode),this.getTransformMatrix(),l.setFloat3("biasAndScaleSM",this.bias,this.normalBias,this.depthScale),this.getLight().getTypeID()===M.LIGHTTYPEID_DIRECTIONALLIGHT?l.setVector3("lightDataSM",this._cachedDirection):l.setVector3("lightDataSM",this._cachedPosition);const d=this._getCamera();if(l.setFloat2("depthValuesSM",this.getLight().getDepthMinZ(d),this.getLight().getDepthMinZ(d)+this.getLight().getDepthMaxZ(d)),t&&this.enableSoftTransparentShadow&&l.setFloat2("softTransparentShadowSM",i.visibility*o.alpha,this._opacityTexture?.getAlphaFromRGB?1:0),r)e._setMainDrawWrapperOverride(h),r.standalone?r.baseMaterial.bindForSubMesh(i.getWorldMatrix(),s,e):o.bindForSubMesh(i.getWorldMatrix(),s,e),e._setMainDrawWrapperOverride(null);else{if(this._opacityTexture&&(l.setTexture("diffuseSampler",this._opacityTexture),l.setMatrix("diffuseMatrix",this._opacityTexture.getTextureMatrix()||this._defaultTextureMatrix)),s.useBones&&s.computeBonesUsingShaders&&s.skeleton){const e=s.skeleton;if(e.isUsingTextureForMatrices){const t=e.getTransformMatrixTexture(s);if(!t)return;l.setTexture("boneSampler",t),l.setFloat("boneTextureWidth",4*(e.bones.length+1))}else l.setMatrices("mBones",e.getTransformMatrices(s))}E(s,l),s.morphTargetManager&&s.morphTargetManager.isUsingTextureForTargets&&s.morphTargetManager._bind(l);const t=e.getMesh().bakedVertexAnimationManager;t&&t.isEnabled&&t.bind(l,_),m(l,o,a)}this._useUBO||r||this._bindCustomEffectForRenderSubMeshForShadowMap(e,l,i),T(l,this._scene.getSceneUniformBuffer()),this._scene.getSceneUniformBuffer().bindUniformBuffer();const u=i.getWorldMatrix();_&&(i.getMeshUniformBuffer().bindToEffect(l,"Mesh"),i.transferToEffect(u)),this.forceBackFacesOnly&&n.setState(!0,0,!1,!0,o.cullBackFaces),this.onBeforeShadowMapRenderMeshObservable.notifyObservers(s),this.onBeforeShadowMapRenderObservable.notifyObservers(l),s._processRendering(i,e,l,o.fillMode,p,_,((e,t)=>{i===s||e?(i.getMeshUniformBuffer().bindToEffect(l,"Mesh"),i.transferToEffect(e?t:u)):(s.getMeshUniformBuffer().bindToEffect(l,"Mesh"),s.transferToEffect(t))})),this.forceBackFacesOnly&&n.setState(!0,0,!1,!1,o.cullBackFaces),this.onAfterShadowMapRenderObservable.notifyObservers(l),this.onAfterShadowMapRenderMeshObservable.notifyObservers(s)}else this._shadowMap&&this._shadowMap.resetRefreshCounter()}_applyFilterValues(){this._shadowMap&&(this.filter===R.FILTER_NONE||this.filter===R.FILTER_PCSS?this._shadowMap.updateSamplingMode(i.NEAREST_SAMPLINGMODE):this._shadowMap.updateSamplingMode(i.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,t,s,i){s.push("#define SM_LIGHTTYPE_"+this._light.getClassName().toUpperCase()),s.push("#define SM_FLOAT "+(this._textureType!==r.TEXTURETYPE_UNSIGNED_BYTE?"1":"0")),s.push("#define SM_ESM "+(this.useExponentialShadowMap||this.useBlurExponentialShadowMap?"1":"0")),s.push("#define SM_DEPTHTEXTURE "+(this.usePercentageCloserFiltering||this.useContactHardeningShadow?"1":"0"));const a=e.getMesh();return s.push("#define SM_NORMALBIAS "+(this.normalBias&&a.isVerticesDataPresent(w.NormalKind)?"1":"0")),s.push("#define SM_DIRECTIONINLIGHTDATA "+(this.getLight().getTypeID()===M.LIGHTTYPEID_DIRECTIONALLIGHT?"1":"0")),s.push("#define SM_USEDISTANCE "+(this._light.needCube()?"1":"0")),s.push("#define SM_SOFTTRANSPARENTSHADOW "+(this.enableSoftTransparentShadow&&i?"1":"0")),this._isReadyCustomDefines(s,e,t),s}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=[w.PositionKind],h=e.getMesh();let l=!1,d=!1,u=!1;const p=!1;this.normalBias&&h.isVerticesDataPresent(w.NormalKind)&&(o.push(w.NormalKind),a.push("#define NORMAL"),l=!0,h.nonUniformScaling&&a.push("#define NONUNIFORMSCALING"));const _=i.needAlphaTestingForMesh(h);if((_||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??R.DEFAULT_ALPHA_CUTOFF;a.push("#define ALPHATEXTURE"),_&&a.push(`#define ALPHATESTVALUE ${e}${e%1==0?".":""}`),h.isVerticesDataPresent(w.UVKind)&&(o.push(w.UVKind),a.push("#define UV1"),d=!0),h.isVerticesDataPresent(w.UV2Kind)&&1===this._opacityTexture.coordinatesIndex&&(o.push(w.UV2Kind),a.push("#define UV2"),u=!0)}const c=new L;if(h.useBones&&h.computeBonesUsingShaders&&h.skeleton){o.push(w.MatricesIndicesKind),o.push(w.MatricesWeightsKind),h.numBoneInfluencers>4&&(o.push(w.MatricesIndicesExtraKind),o.push(w.MatricesWeightsExtraKind));const e=h.skeleton;a.push("#define NUM_BONE_INFLUENCERS "+h.numBoneInfluencers),h.numBoneInfluencers>0&&c.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?x(h.morphTargetManager,a,o,h,!0,l,!1,d,u,p):0;if(P(i,this._scene,a),t&&(a.push("#define INSTANCES"),I(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","boneTextureWidth","softTransparentShadowSM","morphTargetTextureInfo","morphTargetTextureIndices","bakedVertexAnimationSettings","bakedVertexAnimationTextureSizeInverted","bakedVertexAnimationTime","bakedVertexAnimationTexture"],i=["diffuseSampler","boneSampler","morphTargets","bakedVertexAnimationTexture"],a=["Scene","Mesh"];if(B(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:c,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===R.QUALITY_LOW?e["SHADOWLOWQUALITY"+t]=!0:this._filteringQuality===R.QUALITY_MEDIUM&&(e["SHADOWMEDIUMQUALITY"+t]=!0)):this.usePercentageCloserFiltering?(e["SHADOWPCF"+t]=!0,this._filteringQuality===R.QUALITY_LOW?e["SHADOWLOWQUALITY"+t]=!0:this._filteringQuality===R.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;if(!this._scene.shadowsEnabled||!s.shadowEnabled)return;const i=this._getCamera(),r=this.getShadowMap();if(!r)return;s.needCube()||t.setMatrix("lightMatrix"+e,this.getTransformMatrix());const a=this.getShadowMapForRendering();this._filter===R.FILTER_PCF?(t.setDepthStencilTexture("shadowTexture"+e,a),s._uniformBuffer.updateFloat4("shadowsInfo",this.getDarkness(),r.getSize().width,1/r.getSize().width,this.frustumEdgeFalloff,e)):this._filter===R.FILTER_PCSS?(t.setDepthStencilTexture("shadowTexture"+e,a),t.setTexture("depthTexture"+e,a),s._uniformBuffer.updateFloat4("shadowsInfo",this.getDarkness(),1/r.getSize().width,this._contactHardeningLightSizeUVRatio*r.getSize().width,this.frustumEdgeFalloff,e)):(t.setTexture("shadowTexture"+e,a),s._uniformBuffer.updateFloat4("shadowsInfo",this.getDarkness(),this.blurScale/r.getSize().width,this.depthScale,this.frustumEdgeFalloff,e)),s._uniformBuffer.updateFloat2("depthValues",this.getLight().getDepthMinZ(i),this.getLight().getDepthMinZ(i)+this.getLight().getDepthMaxZ(i),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),u.NormalizeToRef(this._light.getShadowDirection(this._currentFaceIndex),this._lightDirection),1===Math.abs(u.Dot(this._lightDirection,u.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),p.LookAtLHToRef(t,t.add(this._lightDirection),u.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(){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()}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 R(e.mapSize,i,void 0,r),n=a.getShadowMap();for(let s=0;s<e.renderList.length;s++){const i=t.getMeshesById(e.renderList[s]);for(const e of i)n&&(n.renderList||(n.renderList=[]),n.renderList.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}}R.CLASSNAME="ShadowGenerator",R.ForceGLSL=!1,R.FILTER_NONE=0,R.FILTER_EXPONENTIALSHADOWMAP=1,R.FILTER_POISSONSAMPLING=2,R.FILTER_BLUREXPONENTIALSHADOWMAP=3,R.FILTER_CLOSEEXPONENTIALSHADOWMAP=4,R.FILTER_BLURCLOSEEXPONENTIALSHADOWMAP=5,R.FILTER_PCF=6,R.FILTER_PCSS=7,R.QUALITY_HIGH=0,R.QUALITY_MEDIUM=1,R.QUALITY_LOW=2,R.DEFAULT_ALPHA_CUTOFF=.5,R._SceneComponentInitialization=e=>{throw A("ShadowGeneratorSceneComponent")};export{R as ShadowGenerator};
//# sourceMappingURL=shadowGenerator-YelHvDzx.esm.min.js.map