@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) • 29.1 kB
JavaScript
import{aZ as e,ao as t,C as s,b1 as i,bd as r,a7 as n,as as a,a0 as l,b6 as o,b8 as u,b7 as h,be as T,m as c,M as d,b5 as _,F as p,am as E,aq as f,ba as g}from"./index-BPURObVq.esm.min.js";class m{constructor(t){this.name=e.NAME_GEOMETRYBUFFERRENDERER,this.scene=t}register(){this.scene._gatherRenderTargetsStage.registerStep(e.STEP_GATHERRENDERTARGETS_GEOMETRYBUFFERRENDERER,this,this._gatherRenderTargets)}rebuild(){}dispose(){}_gatherRenderTargets(e){this.scene._geometryBufferRenderer&&e.push(this.scene._geometryBufferRenderer.getGBuffer())}}let x=!1;function R(i){x||(x=!0,Object.defineProperty(t.prototype,"geometryBufferRenderer",{get:function(){return this._geometryBufferRenderer},set:function(e){e&&e.isSupported&&(this._geometryBufferRenderer=e)},enumerable:!0,configurable:!0}),t.prototype.enableGeometryBufferRenderer=function(e=1,t=s.TEXTUREFORMAT_DEPTH16,r){return this._geometryBufferRenderer||(this._geometryBufferRenderer=new i(this,e,t,r),this._geometryBufferRenderer.isSupported||(this._geometryBufferRenderer=null)),this._geometryBufferRenderer},t.prototype.disableGeometryBufferRenderer=function(){this._geometryBufferRenderer&&(this._geometryBufferRenderer.dispose(),this._geometryBufferRenderer=null)},i._SceneComponentInitialization=t=>{let s=t._getComponent(e.NAME_GEOMETRYBUFFERRENDERER);s||(s=new m(t),t._addComponent(s))})}const I=["diffuseSampler","bumpSampler","reflectivitySampler","albedoSampler","morphTargets","boneSampler","transmissionWeightSampler","subsurfaceWeightSampler","iblShadowSampler"],M=["world","mBones","viewProjection","diffuseMatrix","view","previousWorld","previousViewProjection","mPreviousBones","bumpMatrix","reflectivityMatrix","albedoMatrix","reflectivityColor","albedoColor","reflectionMatrix","vTransmissionWeight","vSubsurfaceWeight","vEyePosition","vTransmissionScatterAnisotropy","vSubsurfaceScatterAnisotropy","shadowTextureSize","metallic","glossiness","vTangentSpaceParams","vBumpInfos","morphTargetInfluences","morphTargetCount","morphTargetTextureInfo","morphTargetTextureIndices","boneTextureInfo"];class b{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._enableIrradiance=!1,this._attachmentsFromPrePass=[]}_forceTextureType(e,t){e===b.POSITION_TEXTURE_TYPE?(this._positionIndex=t,this._enablePosition=!0):e===b.VELOCITY_TEXTURE_TYPE?(this._velocityIndex=t,this._enableVelocity=!0):e===b.VELOCITY_LINEAR_TEXTURE_TYPE?(this._velocityLinearIndex=t,this._enableVelocityLinear=!0):e===b.REFLECTIVITY_TEXTURE_TYPE?(this._reflectivityIndex=t,this._enableReflectivity=!0):e===b.DEPTH_TEXTURE_TYPE?(this._depthIndex=t,this._enableDepth=!0):e===b.NORMAL_TEXTURE_TYPE?(this._normalIndex=t,this._enableNormal=!0):e===b.SCREENSPACE_DEPTH_TEXTURE_TYPE?(this._screenspaceDepthIndex=t,this._enableScreenspaceDepth=!0):e===b.IRRADIANCE_TEXTURE_TYPE&&(this._irradianceIndex=t,this._enableIrradiance=!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 b.POSITION_TEXTURE_TYPE:return this._positionIndex;case b.VELOCITY_TEXTURE_TYPE:return this._velocityIndex;case b.VELOCITY_LINEAR_TEXTURE_TYPE:return this._velocityLinearIndex;case b.REFLECTIVITY_TEXTURE_TYPE:return this._reflectivityIndex;case b.DEPTH_TEXTURE_TYPE:return this._depthIndex;case b.NORMAL_TEXTURE_TYPE:return this._normalIndex;case b.SCREENSPACE_DEPTH_TEXTURE_TYPE:return this._screenspaceDepthIndex;case b.IRRADIANCE_TEXTURE_TYPE:return this._irradianceIndex;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 enableIrradiance(){return this._enableIrradiance}set enableIrradiance(e){this._enableIrradiance=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,t=1,r=s.TEXTUREFORMAT_DEPTH16,n){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._enableIrradiance=!1,this._clearColor=new i(0,0,0,0),this._clearDepthColor=new i(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._irradianceIndex=-1,this._linkedWithPrePass=!1,this.generateIrradianceWithScatterMask=!1,this.useSpecificClearForDepthTexture=!1,this._shaderLanguage=0,this._shadersLoaded=!1,this._scene=e,this._ratioOrDimensions=t,this._useUbo=e.getEngine().supportsUniformBuffers,this._depthFormat=r,this._textureTypesAndFormats=n||{},this._initShaderSourceAsync(),R(b),b._SceneComponentInitialization(this._scene),this._createRenderTargets()}async _initShaderSourceAsync(){this._scene.getEngine().isWebGPU&&!b.ForceGLSL?(this._shaderLanguage=1,await Promise.all([import("./geometry.vertex-lGW8SxEw.esm.min.js"),import("./geometry.fragment-B_haV1OI.esm.min.js")])):await Promise.all([import("./geometry.vertex-B7Ds1Cdm.esm.min.js"),import("./geometry.fragment-JwfBOssm.esm.min.js")]),this._shadersLoaded=!0}isReady(e,t){if(!this._shadersLoaded)return!1;const s=e.getMaterial();if(s&&s.disableDepthWrite)return!1;if(r(e.getMesh().getClassName()))return!1;const i=[],T=[n.PositionKind],c=e.getMesh();c.isVerticesDataPresent(n.NormalKind)&&(i.push("#define HAS_NORMAL_ATTRIBUTE"),T.push(n.NormalKind));let d=!1,_=!1;if(s){let e=!1;if(s.needAlphaTestingForMesh(c)&&s.getAlphaTestTexture()&&(i.push("#define ALPHATEST"),i.push(`#define ALPHATEST_UV${s.getAlphaTestTexture().coordinatesIndex+1}`),e=!0),(s.bumpTexture||s.normalTexture||s.geometryNormalTexture)&&a.BumpTextureEnabled){const t=s.bumpTexture||s.normalTexture||s.geometryNormalTexture;i.push("#define BUMP"),i.push(`#define BUMP_UV${t.coordinatesIndex+1}`),e=!0}if(this._enableReflectivity){let t=!1;if("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"));else if("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");else if("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"));else if("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");else if("OpenPBRMaterial"===s.getClassName()){const t=s;i.push("#define METALLIC"),i.push("#define ROUGHNESS"),t._useRoughnessFromMetallicTextureGreen&&t.baseMetalnessTexture?(i.push("#define ORMTEXTURE"),i.push(`#define REFLECTIVITY_UV${t.baseMetalnessTexture.coordinatesIndex+1}`),e=!0):t.baseMetalnessTexture?(i.push("#define METALLIC_TEXTURE"),i.push(`#define METALLIC_UV${t.baseMetalnessTexture.coordinatesIndex+1}`),e=!0):t.specularRoughnessTexture&&(i.push("#define ROUGHNESS_TEXTURE"),i.push(`#define ROUGHNESS_UV${t.specularRoughnessTexture.coordinatesIndex+1}`),e=!0),t.baseColorTexture&&(i.push("#define ALBEDOTEXTURE"),i.push(`#define ALBEDO_UV${t.baseColorTexture.coordinatesIndex+1}`),t.baseColorTexture.gammaSpace&&i.push("#define GAMMAALBEDO"),e=!0),t.baseColor&&i.push("#define ALBEDOCOLOR")}}if(this._enableIrradiance&&this.generateIrradianceWithScatterMask&&(i.push("#define IRRADIANCE_SCATTER_MASK"),"OpenPBRMaterial"===s.getClassName())){const t=s;t.subsurfaceWeight>0&&t.subsurfaceWeightTexture&&(i.push("#define SUBSURFACE_WEIGHT"),i.push(`#define SUBSURFACEWEIGHT_UV${t.subsurfaceWeightTexture.coordinatesIndex+1}`),e=!0),t.transmissionWeight>0&&t.transmissionWeightTexture&&(i.push("#define TRANSMISSION_WEIGHT"),i.push(`#define TRANSMISSIONWEIGHT_UV${t.transmissionWeightTexture.coordinatesIndex+1}`),e=!0)}e&&(i.push("#define NEED_UV"),c.isVerticesDataPresent(n.UVKind)&&(T.push(n.UVKind),i.push("#define UV1"),d=!0),c.isVerticesDataPresent(n.UV2Kind)&&(T.push(n.UV2Kind),i.push("#define UV2"),_=!0))}if(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(c)&&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(c)&&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._enableIrradiance&&-1!==this._irradianceIndex){i.push("#define IRRADIANCE_INDEX "+this._irradianceIndex),i.push("#define IRRADIANCE");const e=this._scene;if(e.environmentTexture){const t={};let r=!1,n=0;"OpenPBRMaterial"!==s.getClassName()&&"StandardMaterial"!==s.getClassName()&&"PBRMetallicRoughnessMaterial"!==s.getClassName()&&"PBRSpecularGlossinessMaterial"!==s.getClassName()&&"PBRMaterial"!==s.getClassName()||(r=!!s.realtimeFiltering,n=s.realtimeFilteringQuality||0),l(e,e.environmentTexture,t,r,n,!0);for(const e in t)t[e]&&i.push("#define "+e);t.USEIRRADIANCEMAP||i.push("#define SPHERICAL_HARMONICS");const a=e.postProcessRenderPipelineManager.supportedPipelines.find(e=>"IBLShadowsRenderPipeline"===e.getClassName());if(a){const e=a;e._getAccumulatedTexture()&&(i.push("#define IBL_SHADOW_TEXTURE"),e.coloredShadows&&i.push("#define COLORED_IBL_SHADOWS"))}}}this.generateNormalsInWorldSpace&&i.push("#define NORMAL_WORLDSPACE"),this._normalsAreUnsigned&&i.push("#define ENCODE_NORMAL"),c.useBones&&c.computeBonesUsingShaders&&c.skeleton?(T.push(n.MatricesIndicesKind),T.push(n.MatricesWeightsKind),c.numBoneInfluencers>4&&(T.push(n.MatricesIndicesExtraKind),T.push(n.MatricesWeightsExtraKind)),i.push("#define NUM_BONE_INFLUENCERS "+c.numBoneInfluencers),i.push("#define BONETEXTURE "+c.skeleton.isUsingTextureForMatrices),i.push("#define BonesPerMesh "+(c.skeleton.bones.length+1))):(i.push("#define NUM_BONE_INFLUENCERS 0"),i.push("#define BONETEXTURE false"),i.push("#define BonesPerMesh 0"));const p=c.morphTargetManager?o(c.morphTargetManager,i,T,c,!0,!0,!1,d,_,!1):0;t&&(i.push("#define INSTANCES"),u(T,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),h(s,this._scene,i);const E=this._scene.getEngine(),f=e._getDrawWrapper(void 0,!0),g=f.defines,m=i.join("\n");return g!==m&&f.setEffect(E.createEffect("geometry",{attributes:T,uniformsNames:M,samplers:I,defines:m,onCompiled:null,fallbacks:null,onError:null,uniformBuffersNames:["Scene"],indexParameters:{buffersCount:this._multiRenderTarget.textures.length-1,maxSimultaneousMorphTargets:p},shaderLanguage:this.shaderLanguage},E),m),f.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._multiRenderTarget?.renderTarget&&this.scene.getEngine()._currentRenderTarget===this._multiRenderTarget.renderTarget&&this.scene.getEngine().unBindFramebuffer(this._multiRenderTarget?.renderTarget),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[b.DEPTH_TEXTURE_TYPE])),this._enableNormal&&(this._normalIndex=s,s++,e.push("gBuffer_Normal"),t.push(this._textureTypesAndFormats[b.NORMAL_TEXTURE_TYPE])),this._enablePosition&&(this._positionIndex=s,s++,e.push("gBuffer_Position"),t.push(this._textureTypesAndFormats[b.POSITION_TEXTURE_TYPE])),this._enableVelocity&&(this._velocityIndex=s,s++,e.push("gBuffer_Velocity"),t.push(this._textureTypesAndFormats[b.VELOCITY_TEXTURE_TYPE])),this._enableVelocityLinear&&(this._velocityLinearIndex=s,s++,e.push("gBuffer_VelocityLinear"),t.push(this._textureTypesAndFormats[b.VELOCITY_LINEAR_TEXTURE_TYPE])),this._enableReflectivity&&(this._reflectivityIndex=s,s++,e.push("gBuffer_Reflectivity"),t.push(this._textureTypesAndFormats[b.REFLECTIVITY_TEXTURE_TYPE])),this._enableScreenspaceDepth&&(this._screenspaceDepthIndex=s,s++,e.push("gBuffer_ScreenspaceDepth"),t.push(this._textureTypesAndFormats[b.SCREENSPACE_DEPTH_TEXTURE_TYPE])),this._enableIrradiance&&(this._irradianceIndex=s,s++,e.push("gBuffer_Irradiance"),t.push(this._textureTypesAndFormats[b.IRRADIANCE_TEXTURE_TYPE])),[s,e,t]}_createRenderTargets(){const e=this._scene.getEngine(),[t,i,r]=this._assignRenderTargetIndices();let n=s.TEXTURETYPE_UNSIGNED_BYTE;e._caps.textureFloat&&e._caps.textureFloatLinearFiltering?n=s.TEXTURETYPE_FLOAT:e._caps.textureHalfFloat&&e._caps.textureHalfFloatLinearFiltering&&(n=s.TEXTURETYPE_HALF_FLOAT);const l=void 0!==this._ratioOrDimensions.width?this._ratioOrDimensions:{width:e.getRenderWidth()*this._ratioOrDimensions,height:e.getRenderHeight()*this._ratioOrDimensions},o=[],u=[],h=[];for(const e of r)e?(o.push(e.textureType),u.push(e.textureFormat),h.push(e.samplingMode??s.TEXTURE_BILINEAR_SAMPLINGMODE)):(o.push(n),u.push(s.TEXTUREFORMAT_RGBA),h.push(s.TEXTURE_BILINEAR_SAMPLINGMODE));if(this._normalsAreUnsigned=o[b.NORMAL_TEXTURE_TYPE]===s.TEXTURETYPE_UNSIGNED_INT_2_10_10_10_REV||o[b.NORMAL_TEXTURE_TYPE]===s.TEXTURETYPE_UNSIGNED_INT_10F_11F_11F_REV,this._multiRenderTarget=new T("gBuffer",l,t,this._scene,{generateMipMaps:!1,generateDepthTexture:!0,types:o,formats:u,samplingModes:h,depthTextureFormat:this._depthFormat},i.concat("gBuffer_DepthBuffer")),!this.isSupported)return;this._multiRenderTarget.wrapU=c.CLAMP_ADDRESSMODE,this._multiRenderTarget.wrapV=c.CLAMP_ADDRESSMODE,this._multiRenderTarget.refreshRate=1,this._multiRenderTarget.renderParticles=!1,this._multiRenderTarget.renderList=null;const g=[!0],m=[!1],x=[!0];for(let e=1;e<t;++e)g.push(!0),x.push(!1),m.push(!0);const R=e.buildTextureLayout(g),I=e.buildTextureLayout(m),M=e.buildTextureLayout(x);this._multiRenderTarget.onClearObservable.add(e=>{e.bindAttachments(this.useSpecificClearForDepthTexture?I:R),e.clear(this._clearColor,!0,!0,!0),this.useSpecificClearForDepthTexture&&(e.bindAttachments(M),e.clear(this._clearDepthColor,!0,!0,!0)),e.bindAttachments(R)}),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 S=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:d.Identity(),viewProjection:i.getTransformMatrix()},t.skeleton)){const e=t.skeleton.getTransformMatrices(t);this._previousBonesTransformationMatrices[t.uniqueId]=this._copyBonesTransformationMatrices(e,new Float32Array(e.length))}const l=t._getInstancesRenderList(e._id,!!e.getReplacementMesh());if(l.mustReturn)return;const o=r.getCaps().instancedArrays&&(null!==l.visibleInstances[e._id]||t.hasThinInstances),u=s.getWorldMatrix();if(this.isReady(e,o)){const h=e._getDrawWrapper();if(!h)return;const T=h.effect;let c;r.enableEffect(h),o||t._bind(e,T,n.fillMode),this._useUbo?(_(T,this._scene.getSceneUniformBuffer()),this._scene.finalizeSceneUbo()):(T.setMatrix("viewProjection",i.getTransformMatrix()),T.setMatrix("view",i.getViewMatrix()),this._scene.bindEyePosition(T,"vEyePosition"));if(t._instanceDataStorage.isFrozen||!n.backFaceCulling&&null===n.sideOrientation)c=t._effectiveSideOrientation;else{const e=s._getWorldMatrixDeterminant();c=n._getEffectiveOrientation(t),e<0&&(c=c===p.ClockWiseSideOrientation?p.CounterClockWiseSideOrientation:p.ClockWiseSideOrientation)}if(n._preBind(h,c),n.needAlphaTestingForMesh(s)){const e=n.getAlphaTestTexture();e&&(T.setTexture("diffuseSampler",e),T.setMatrix("diffuseMatrix",e.getTextureMatrix()))}if((n.bumpTexture||n.normalTexture||n.geometryNormalTexture)&&i.getEngine().getCaps().standardDerivatives&&a.BumpTextureEnabled){const e=n.bumpTexture||n.normalTexture||n.geometryNormalTexture;T.setFloat3("vBumpInfos",e.coordinatesIndex,1/e.level,n.parallaxScaleBias),T.setMatrix("bumpMatrix",e.getTextureMatrix()),T.setTexture("bumpSampler",e),T.setFloat2("vTangentSpaceParams",n.invertNormalMapX?-1:1,n.invertNormalMapY?-1:1)}if(this._enableReflectivity)if("PBRMetallicRoughnessMaterial"===n.getClassName())null!==n.metallicRoughnessTexture&&(T.setTexture("reflectivitySampler",n.metallicRoughnessTexture),T.setMatrix("reflectivityMatrix",n.metallicRoughnessTexture.getTextureMatrix())),null!==n.metallic&&T.setFloat("metallic",n.metallic),null!==n.roughness&&T.setFloat("glossiness",1-n.roughness),null!==n.baseTexture&&(T.setTexture("albedoSampler",n.baseTexture),T.setMatrix("albedoMatrix",n.baseTexture.getTextureMatrix())),null!==n.baseColor&&T.setColor3("albedoColor",n.baseColor);else if("PBRSpecularGlossinessMaterial"===n.getClassName())null!==n.specularGlossinessTexture?(T.setTexture("reflectivitySampler",n.specularGlossinessTexture),T.setMatrix("reflectivityMatrix",n.specularGlossinessTexture.getTextureMatrix())):null!==n.specularColor&&T.setColor3("reflectivityColor",n.specularColor),null!==n.glossiness&&T.setFloat("glossiness",n.glossiness);else if("PBRMaterial"===n.getClassName())null!==n.metallicTexture&&(T.setTexture("reflectivitySampler",n.metallicTexture),T.setMatrix("reflectivityMatrix",n.metallicTexture.getTextureMatrix())),null!==n.metallic&&T.setFloat("metallic",n.metallic),null!==n.roughness&&T.setFloat("glossiness",1-n.roughness),null!==n.roughness||null!==n.metallic||null!==n.metallicTexture?(null!==n.albedoTexture&&(T.setTexture("albedoSampler",n.albedoTexture),T.setMatrix("albedoMatrix",n.albedoTexture.getTextureMatrix())),null!==n.albedoColor&&T.setColor3("albedoColor",n.albedoColor)):(null!==n.reflectivityTexture?(T.setTexture("reflectivitySampler",n.reflectivityTexture),T.setMatrix("reflectivityMatrix",n.reflectivityTexture.getTextureMatrix())):null!==n.reflectivityColor&&T.setColor3("reflectivityColor",n.reflectivityColor),null!==n.microSurface&&T.setFloat("glossiness",n.microSurface));else if("StandardMaterial"===n.getClassName())null!==n.specularTexture&&(T.setTexture("reflectivitySampler",n.specularTexture),T.setMatrix("reflectivityMatrix",n.specularTexture.getTextureMatrix())),null!==n.specularColor&&T.setColor3("reflectivityColor",n.specularColor);else if("OpenPBRMaterial"===n.getClassName()){const e=n;e._useRoughnessFromMetallicTextureGreen&&e.baseMetalnessTexture?(T.setTexture("reflectivitySampler",e.baseMetalnessTexture),T.setMatrix("reflectivityMatrix",e.baseMetalnessTexture.getTextureMatrix())):e.baseMetalnessTexture?(T.setTexture("metallicSampler",e.baseMetalnessTexture),T.setMatrix("metallicMatrix",e.baseMetalnessTexture.getTextureMatrix())):e.specularRoughnessTexture&&(T.setTexture("roughnessSampler",e.specularRoughnessTexture),T.setMatrix("roughnessMatrix",e.specularRoughnessTexture.getTextureMatrix())),T.setFloat("metallic",e.baseMetalness),T.setFloat("glossiness",1-e.specularRoughness),null!==e.baseColorTexture&&(T.setTexture("albedoSampler",e.baseColorTexture),T.setMatrix("albedoMatrix",e.baseColorTexture.getTextureMatrix())),null!==e.baseColor&&T.setColor3("albedoColor",e.baseColor)}if(this._enableIrradiance&&i.environmentTexture){const e=i.environmentTexture,t=i.postProcessRenderPipelineManager.supportedPipelines.find(e=>"IBLShadowsRenderPipeline"===e.getClassName());if(t){const e=t._getAccumulatedTexture();e&&(T.setTexture("iblShadowSampler",e),T.setFloat2("shadowTextureSize",e.getSize().width,e.getSize().height))}if(T.setMatrix("reflectionMatrix",e.getReflectionTextureMatrix()),T.setFloat2("vReflectionInfos",e.level*i.iblIntensity,0),T.setTexture("reflectionSampler",e),e.irradianceTexture&&(T.setTexture("irradianceSampler",e.irradianceTexture),e.irradianceTexture._dominantDirection&&T.setVector3("vReflectionDominantDirection",e.irradianceTexture._dominantDirection)),e.sphericalPolynomial){const t=e.sphericalPolynomial;if(t.preScaledHarmonics){const e=t.preScaledHarmonics;T.setVector3("vSphericalL00",e.l00),T.setVector3("vSphericalL1_1",e.l1_1),T.setVector3("vSphericalL10",e.l10),T.setVector3("vSphericalL11",e.l11),T.setVector3("vSphericalL2_2",e.l2_2),T.setVector3("vSphericalL2_1",e.l2_1),T.setVector3("vSphericalL20",e.l20),T.setVector3("vSphericalL21",e.l21),T.setVector3("vSphericalL22",e.l22)}else T.setFloat3("vSphericalX",t.x.x,t.x.y,t.x.z),T.setFloat3("vSphericalY",t.y.x,t.y.y,t.y.z),T.setFloat3("vSphericalZ",t.z.x,t.z.y,t.z.z),T.setFloat3("vSphericalXX_ZZ",t.xx.x-t.zz.x,t.xx.y-t.zz.y,t.xx.z-t.zz.z),T.setFloat3("vSphericalYY_ZZ",t.yy.x-t.zz.x,t.yy.y-t.zz.y,t.yy.z-t.zz.z),T.setFloat3("vSphericalZZ",t.zz.x,t.zz.y,t.zz.z),T.setFloat3("vSphericalXY",t.xy.x,t.xy.y,t.xy.z),T.setFloat3("vSphericalYZ",t.yz.x,t.yz.y,t.yz.z),T.setFloat3("vSphericalZX",t.zx.x,t.zx.y,t.zx.z)}if(this.generateIrradianceWithScatterMask&&"OpenPBRMaterial"===n.getClassName()){const e=n;T.setFloat("vSubsurfaceWeight",e.subsurfaceWeight),e.subsurfaceWeightTexture&&(T.setTexture("subsurfaceWeightSampler",e.subsurfaceWeightTexture),T.setMatrix("subsurfaceWeightMatrix",e.subsurfaceWeightTexture.getTextureMatrix())),T.setFloat("vTransmissionWeight",e.transmissionWeight),e.transmissionWeightTexture&&(T.setTexture("transmissionWeightSampler",e.transmissionWeightTexture),T.setMatrix("transmissionWeightMatrix",e.transmissionWeightTexture.getTextureMatrix())),T.setFloat("vTransmissionScatterAnisotropy",e.transmissionScatterAnisotropy),T.setFloat("vSubsurfaceScatterAnisotropy",e.subsurfaceScatterAnisotropy)}}if(E(T,n,this._scene),t.useBones&&t.computeBonesUsingShaders&&t.skeleton){const e=t.skeleton;if(e.isUsingTextureForMatrices&&T.getUniformIndex("boneTextureInfo")>-1){const s=e.getTransformMatrixTexture(t);T.setTexture("boneSampler",s),T.setFloat2("boneTextureInfo",e._textureWidth,e._textureHeight)}else T.setMatrices("mBones",t.skeleton.getTransformMatrices(t));(this._enableVelocity||this._enableVelocityLinear)&&T.setMatrices("mPreviousBones",this._previousBonesTransformationMatrices[t.uniqueId])}f(t,T),t.morphTargetManager&&t.morphTargetManager.isUsingTextureForTargets&&t.morphTargetManager._bind(T),(this._enableVelocity||this._enableVelocityLinear)&&(T.setMatrix("previousWorld",this._previousTransformationMatrices[s.uniqueId].world),T.setMatrix("previousViewProjection",this._previousTransformationMatrices[s.uniqueId].viewProjection)),o&&t.hasThinInstances&&T.setMatrix("world",u),t._processRendering(s,e,T,n.fillMode,l,o,(e,t)=>{e||T.setMatrix("world",t)})}(this._enableVelocity||this._enableVelocityLinear)&&(this._previousTransformationMatrices[s.uniqueId].world=u.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(),n=i.getRenderingMesh();if(!r)continue;const a=n._getInstancesRenderList(i._id,!!i.getReplacementMesh()),l=e.getCaps().instancedArrays&&(null!==a.visibleInstances[i._id]||n.hasThinInstances);if(!this.isReady(i,l))return!1}return!0},this._multiRenderTarget.customRenderFunction=(t,s,i,r)=>{let n;if(this._linkedWithPrePass){if(!this._prePassRenderer.enabled)return;this._scene.getEngine().bindAttachments(this._attachmentsFromPrePass)}if(r.length){for(e.setColorWrite(!1),n=0;n<r.length;n++)S(r.data[n]);e.setColorWrite(!0)}for(n=0;n<t.length;n++)S(t.data[n]);for(e.setDepthWrite(!1),n=0;n<s.length;n++)S(s.data[n]);if(this.renderTransparentMeshes)for(n=0;n<i.length;n++)S(i.data[n]);e.setDepthWrite(!0)}}_copyBonesTransformationMatrices(e,t){for(let s=0;s<e.length;s++)t[s]=e[s];return t}}b.ForceGLSL=!1,b.DEPTH_TEXTURE_TYPE=0,b.NORMAL_TEXTURE_TYPE=1,b.POSITION_TEXTURE_TYPE=2,b.VELOCITY_TEXTURE_TYPE=3,b.REFLECTIVITY_TEXTURE_TYPE=4,b.SCREENSPACE_DEPTH_TEXTURE_TYPE=5,b.VELOCITY_LINEAR_TEXTURE_TYPE=6,b.IRRADIANCE_TEXTURE_TYPE=7,b._SceneComponentInitialization=e=>{throw g("GeometryBufferRendererSceneComponent")};export{b as G,R,m as a};
//# sourceMappingURL=geometryBufferRenderer.pure-BG473DMM.esm.min.js.map