@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) • 31.3 kB
JavaScript
import{c5 as e,a as t,ac as s,C as r,l as i,aP as n,q as a,s as o,be as g,aZ as h,ao as u,y as c,b1 as _,F as P,ba as f}from"./index-BPURObVq.esm.min.js";import{R as T,G as p}from"./geometryBufferRenderer.pure-BG473DMM.esm.min.js";class d extends e{_gatherImports(e,t){e?(this._webGPUReady=!0,t.push(import("./imageProcessing.fragment-B2iTyKTc.esm.min.js"))):t.push(import("./imageProcessing.fragment-CprfGHst.esm.min.js"))}get imageProcessingConfiguration(){return this._imageProcessingConfiguration}set imageProcessingConfiguration(e){e.applyByPostProcess=!0,this._attachImageProcessingConfiguration(e)}_attachImageProcessingConfiguration(e,r=!1){if(e!==this._imageProcessingConfiguration){if(this._imageProcessingConfiguration&&this._imageProcessingObserver&&this._imageProcessingConfiguration.onUpdateParameters.remove(this._imageProcessingObserver),e)this._imageProcessingConfiguration=e;else{let e=this.options.scene;if(!e){const s=this.options.engine;if(s&&s.scenes){const t=s.scenes;e=t[t.length-1]}else e=t.LastCreatedScene}this._imageProcessingConfiguration=e?e.imageProcessingConfiguration:new s}this._imageProcessingConfiguration&&(this._imageProcessingObserver=this._imageProcessingConfiguration.onUpdateParameters.add(()=>{this._updateParameters()})),r||this._updateParameters()}}get colorCurves(){return this.imageProcessingConfiguration.colorCurves}set colorCurves(e){this.imageProcessingConfiguration.colorCurves=e}get colorCurvesEnabled(){return this.imageProcessingConfiguration.colorCurvesEnabled}set colorCurvesEnabled(e){this.imageProcessingConfiguration.colorCurvesEnabled=e}get colorGradingTexture(){return this.imageProcessingConfiguration.colorGradingTexture}set colorGradingTexture(e){this.imageProcessingConfiguration.colorGradingTexture=e}get colorGradingEnabled(){return this.imageProcessingConfiguration.colorGradingEnabled}set colorGradingEnabled(e){this.imageProcessingConfiguration.colorGradingEnabled=e}get exposure(){return this.imageProcessingConfiguration.exposure}set exposure(e){this.imageProcessingConfiguration.exposure=e}get toneMappingEnabled(){return this._imageProcessingConfiguration.toneMappingEnabled}set toneMappingEnabled(e){this._imageProcessingConfiguration.toneMappingEnabled=e}get toneMappingType(){return this._imageProcessingConfiguration.toneMappingType}set toneMappingType(e){this._imageProcessingConfiguration.toneMappingType=e}get contrast(){return this.imageProcessingConfiguration.contrast}set contrast(e){this.imageProcessingConfiguration.contrast=e}get vignetteStretch(){return this.imageProcessingConfiguration.vignetteStretch}set vignetteStretch(e){this.imageProcessingConfiguration.vignetteStretch=e}get vignetteCentreX(){return this.imageProcessingConfiguration.vignetteCenterX}set vignetteCentreX(e){this.imageProcessingConfiguration.vignetteCenterX=e}get vignetteCentreY(){return this.imageProcessingConfiguration.vignetteCenterY}set vignetteCentreY(e){this.imageProcessingConfiguration.vignetteCenterY=e}get vignetteCenterY(){return this.imageProcessingConfiguration.vignetteCenterY}set vignetteCenterY(e){this.imageProcessingConfiguration.vignetteCenterY=e}get vignetteCenterX(){return this.imageProcessingConfiguration.vignetteCenterX}set vignetteCenterX(e){this.imageProcessingConfiguration.vignetteCenterX=e}get vignetteWeight(){return this.imageProcessingConfiguration.vignetteWeight}set vignetteWeight(e){this.imageProcessingConfiguration.vignetteWeight=e}get vignetteColor(){return this.imageProcessingConfiguration.vignetteColor}set vignetteColor(e){this.imageProcessingConfiguration.vignetteColor=e}get vignetteCameraFov(){return this.imageProcessingConfiguration.vignetteCameraFov}set vignetteCameraFov(e){this.imageProcessingConfiguration.vignetteCameraFov=e}get vignetteBlendMode(){return this.imageProcessingConfiguration.vignetteBlendMode}set vignetteBlendMode(e){this.imageProcessingConfiguration.vignetteBlendMode=e}get vignetteEnabled(){return this.imageProcessingConfiguration.vignetteEnabled}set vignetteEnabled(e){this.imageProcessingConfiguration.vignetteEnabled=e}get ditheringIntensity(){return this.imageProcessingConfiguration.ditheringIntensity}set ditheringIntensity(e){this.imageProcessingConfiguration.ditheringIntensity=e}get ditheringEnabled(){return this.imageProcessingConfiguration.ditheringEnabled}set ditheringEnabled(e){this.imageProcessingConfiguration.ditheringEnabled=e}get fromLinearSpace(){return this._fromLinearSpace}set fromLinearSpace(e){this._fromLinearSpace!==e&&(this._fromLinearSpace=e,this._updateParameters())}get outputTextureWidth(){return this.imageProcessingConfiguration.outputTextureWidth}set outputTextureWidth(e){this.imageProcessingConfiguration.outputTextureWidth=e}get outputTextureHeight(){return this.imageProcessingConfiguration.outputTextureHeight}set outputTextureHeight(e){this.imageProcessingConfiguration.outputTextureHeight=e}constructor(e,s=null,r){super({...r,name:e,engine:s||t.LastCreatedEngine,useShaderStore:!0,useAsPostProcess:!0,fragmentShader:d.FragmentUrl}),this._fromLinearSpace=!0,this._defines={IMAGEPROCESSING:!1,VIGNETTE:!1,VIGNETTEBLENDMODEMULTIPLY:!1,VIGNETTEBLENDMODEOPAQUE:!1,TONEMAPPING:0,CONTRAST:!1,COLORCURVES:!1,COLORGRADING:!1,COLORGRADING3D:!1,FROMLINEARSPACE:!1,SAMPLER3DGREENDEPTH:!1,SAMPLER3DBGRMAP:!1,DITHER:!1,IMAGEPROCESSINGPOSTPROCESS:!1,EXPOSURE:!1,SKIPFINALCOLORCLAMP:!1};const i=r?.imageProcessingConfiguration;i?(i.applyByPostProcess=!0,this._attachImageProcessingConfiguration(i,!0),this._updateParameters()):(this._attachImageProcessingConfiguration(null,!0),this.imageProcessingConfiguration.applyByPostProcess=!0)}_updateParameters(){this._defines.FROMLINEARSPACE=this._fromLinearSpace,this.imageProcessingConfiguration.prepareDefines(this._defines,!0);let e="";for(const t in this._defines){const s=this._defines[t];switch(typeof s){case"number":case"string":e+=`#define ${t} ${s};\n`;break;default:s&&(e+=`#define ${t};\n`)}}const t=["textureSampler"],r=["scale"];s&&(s.PrepareSamplers(t,this._defines),s.PrepareUniforms(r,this._defines)),this.updateEffect(e,r,t)}bind(e=!1){super.bind(e),this.imageProcessingConfiguration.bind(this.effect,this.overrideAspectRatio)}dispose(){super.dispose(),this._imageProcessingConfiguration&&this._imageProcessingObserver&&this._imageProcessingConfiguration.onUpdateParameters.remove(this._imageProcessingObserver),this._imageProcessingConfiguration&&(this.imageProcessingConfiguration.applyByPostProcess=!1)}}d.FragmentUrl="imageProcessing";let m=(()=>{var e;let t,s=n,g=[];return e=class extends s{get _imageProcessingConfiguration(){return this._effectWrapper.imageProcessingConfiguration}get imageProcessingConfiguration(){return this._effectWrapper.imageProcessingConfiguration}set imageProcessingConfiguration(e){this._effectWrapper.imageProcessingConfiguration=e}get isSupported(){const e=this.getEffect();return!e||e.isSupported}get colorCurves(){return this.imageProcessingConfiguration.colorCurves}set colorCurves(e){this.imageProcessingConfiguration.colorCurves=e}get colorCurvesEnabled(){return this.imageProcessingConfiguration.colorCurvesEnabled}set colorCurvesEnabled(e){this.imageProcessingConfiguration.colorCurvesEnabled=e}get colorGradingTexture(){return this.imageProcessingConfiguration.colorGradingTexture}set colorGradingTexture(e){this.imageProcessingConfiguration.colorGradingTexture=e}get colorGradingEnabled(){return this.imageProcessingConfiguration.colorGradingEnabled}set colorGradingEnabled(e){this.imageProcessingConfiguration.colorGradingEnabled=e}get exposure(){return this.imageProcessingConfiguration.exposure}set exposure(e){this.imageProcessingConfiguration.exposure=e}get toneMappingEnabled(){return this._imageProcessingConfiguration.toneMappingEnabled}set toneMappingEnabled(e){this._imageProcessingConfiguration.toneMappingEnabled=e}get toneMappingType(){return this._imageProcessingConfiguration.toneMappingType}set toneMappingType(e){this._imageProcessingConfiguration.toneMappingType=e}get contrast(){return this.imageProcessingConfiguration.contrast}set contrast(e){this.imageProcessingConfiguration.contrast=e}get vignetteStretch(){return this.imageProcessingConfiguration.vignetteStretch}set vignetteStretch(e){this.imageProcessingConfiguration.vignetteStretch=e}get vignetteCentreX(){return this.imageProcessingConfiguration.vignetteCenterX}set vignetteCentreX(e){this.imageProcessingConfiguration.vignetteCenterX=e}get vignetteCentreY(){return this.imageProcessingConfiguration.vignetteCenterY}set vignetteCentreY(e){this.imageProcessingConfiguration.vignetteCenterY=e}get vignetteCenterY(){return this.imageProcessingConfiguration.vignetteCenterY}set vignetteCenterY(e){this.imageProcessingConfiguration.vignetteCenterY=e}get vignetteCenterX(){return this.imageProcessingConfiguration.vignetteCenterX}set vignetteCenterX(e){this.imageProcessingConfiguration.vignetteCenterX=e}get vignetteWeight(){return this.imageProcessingConfiguration.vignetteWeight}set vignetteWeight(e){this.imageProcessingConfiguration.vignetteWeight=e}get vignetteColor(){return this.imageProcessingConfiguration.vignetteColor}set vignetteColor(e){this.imageProcessingConfiguration.vignetteColor=e}get vignetteCameraFov(){return this.imageProcessingConfiguration.vignetteCameraFov}set vignetteCameraFov(e){this.imageProcessingConfiguration.vignetteCameraFov=e}get vignetteBlendMode(){return this.imageProcessingConfiguration.vignetteBlendMode}set vignetteBlendMode(e){this.imageProcessingConfiguration.vignetteBlendMode=e}get vignetteEnabled(){return this.imageProcessingConfiguration.vignetteEnabled}set vignetteEnabled(e){this.imageProcessingConfiguration.vignetteEnabled=e}get ditheringIntensity(){return this.imageProcessingConfiguration.ditheringIntensity}set ditheringIntensity(e){this.imageProcessingConfiguration.ditheringIntensity=e}get ditheringEnabled(){return this.imageProcessingConfiguration.ditheringEnabled}set ditheringEnabled(e){this.imageProcessingConfiguration.ditheringEnabled=e}get fromLinearSpace(){return this._effectWrapper.fromLinearSpace}set fromLinearSpace(e){this._effectWrapper.fromLinearSpace=e}constructor(e,t,s=null,n,a,o,h=r.TEXTURETYPE_UNSIGNED_BYTE,u){const c={size:"number"==typeof t?t:void 0,camera:s,samplingMode:n,engine:a,reusable:o,textureType:h,imageProcessingConfiguration:u,scene:s?.getScene(),...t,blockCompilation:!0};super(e,d.FragmentUrl,{effectWrapper:"number"!=typeof t&&t.effectWrapper?void 0:new d(e,a,c),...c}),i(this,g),this.onApply=()=>{this._effectWrapper.overrideAspectRatio=this.aspectRatio}}getClassName(){return"ImageProcessingPostProcess"}_updateParameters(){this._effectWrapper._updateParameters()}dispose(e){super.dispose(e),this._imageProcessingConfiguration&&(this.imageProcessingConfiguration.applyByPostProcess=!1)}},(()=>{const r="function"==typeof Symbol&&Symbol.metadata?Object.create(s[Symbol.metadata]??null):void 0;t=[o()],a(e,null,t,{kind:"getter",name:"fromLinearSpace",static:!1,private:!1,access:{has:e=>"fromLinearSpace"in e,get:e=>e.fromLinearSpace},metadata:r},null,g),r&&Object.defineProperty(e,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:r})})(),e})();class l extends g{constructor(e,t,s,r,i,n){super(e,s,r,i,n),this._beforeCompositionPostProcesses=[],this._internalTextureDirty=!1,this.enabled=!1,this.renderTargetTexture=null,this.renderTargetTexture=t}_createCompositionEffect(){this.imageProcessingPostProcess=new m("prePassComposition",1,null,void 0,this._engine),this.imageProcessingPostProcess._updateParameters()}_checkSize(){const e=this._engine.getRenderWidth(!0),t=this._engine.getRenderHeight(!0),s=this.getRenderWidth(),r=this.getRenderHeight();s===e&&r===t||(this.resize({width:e,height:t}),this._internalTextureDirty=!0)}updateCount(e,t,s){super.updateCount(e,t,s),this._internalTextureDirty=!0}_resetPostProcessChain(){this._beforeCompositionPostProcesses.length=0}dispose(){const e=this._scene;if(super.dispose(),e&&e.prePassRenderer){const t=e.prePassRenderer.renderTargets.indexOf(this);-1!==t&&e.prePassRenderer.renderTargets.splice(t,1)}this.imageProcessingPostProcess&&this.imageProcessingPostProcess.dispose(),this.renderTargetTexture&&(this.renderTargetTexture._prePassRenderTarget=null),this._outputPostProcess&&(this._outputPostProcess.autoClear=!0,this._outputPostProcess.restoreDefaultInputTexture())}}class E{constructor(e){this.name=h.NAME_PREPASSRENDERER,this.scene=e}register(){this.scene._beforeCameraDrawStage.registerStep(h.STEP_BEFORECAMERADRAW_PREPASS,this,this._beforeCameraDraw),this.scene._afterCameraDrawStage.registerStep(h.STEP_AFTERCAMERADRAW_PREPASS,this,this._afterCameraDraw),this.scene._beforeRenderTargetDrawStage.registerStep(h.STEP_BEFORERENDERTARGETDRAW_PREPASS,this,this._beforeRenderTargetDraw),this.scene._afterRenderTargetDrawStage.registerStep(h.STEP_AFTERCAMERADRAW_PREPASS,this,this._afterRenderTargetDraw),this.scene._beforeClearStage.registerStep(h.STEP_BEFORECLEAR_PREPASS,this,this._beforeClearStage),this.scene._beforeRenderTargetClearStage.registerStep(h.STEP_BEFORERENDERTARGETCLEAR_PREPASS,this,this._beforeRenderTargetClearStage),this.scene._beforeRenderingMeshStage.registerStep(h.STEP_BEFORERENDERINGMESH_PREPASS,this,this._beforeRenderingMeshStage),this.scene._afterRenderingMeshStage.registerStep(h.STEP_AFTERRENDERINGMESH_PREPASS,this,this._afterRenderingMeshStage)}_beforeRenderTargetDraw(e,t,s){this.scene.prePassRenderer&&!e.noPrePassRenderer&&(this.scene.prePassRenderer._setRenderTarget(e._prePassRenderTarget),this.scene.prePassRenderer._beforeDraw(void 0,t,s))}_afterRenderTargetDraw(e,t,s){this.scene.prePassRenderer&&!e.noPrePassRenderer&&this.scene.prePassRenderer._afterDraw(t,s)}_beforeRenderTargetClearStage(e){this.scene.prePassRenderer&&!e.noPrePassRenderer&&(e._prePassRenderTarget||(e._prePassRenderTarget=this.scene.prePassRenderer._createRenderTarget(e.name+"_prePassRTT",e)),this.scene.prePassRenderer._setRenderTarget(e._prePassRenderTarget),this.scene.prePassRenderer._clear())}_beforeCameraDraw(e){this.scene.prePassRenderer&&(this.scene.prePassRenderer._setRenderTarget(null),this.scene.prePassRenderer._beforeDraw(e))}_afterCameraDraw(){this.scene.prePassRenderer&&this.scene.prePassRenderer._afterDraw()}_beforeClearStage(){this.scene.prePassRenderer&&(this.scene.prePassRenderer._setRenderTarget(null),this.scene.prePassRenderer._clear())}_beforeRenderingMeshStage(e,t,s,r){if(!r)return;const i=e.getScene();i.prePassRenderer&&i.prePassRenderer.bindAttachmentsForEffect(r,t)}_afterRenderingMeshStage(e){const t=e.getScene();t.prePassRenderer&&t.prePassRenderer.restoreAttachments()}rebuild(){}dispose(){this.scene.disablePrePassRenderer()}}let C=!1;function R(e){C||(C=!0,Object.defineProperty(u.prototype,"prePassRenderer",{get:function(){return this._prePassRenderer},set:function(e){e&&e.isSupported&&(this._prePassRenderer=e)},enumerable:!0,configurable:!0}),u.prototype.enablePrePassRenderer=function(){return this._prePassRenderer||(this._prePassRenderer=new e(this),this._prePassRenderer.isSupported||(this._prePassRenderer=null,c.Error("PrePassRenderer needs WebGL 2 support.\nMaybe you tried to use the following features that need the PrePassRenderer :\n + Subsurface Scattering"))),this._prePassRenderer},u.prototype.disablePrePassRenderer=function(){this._prePassRenderer&&(this._prePassRenderer.dispose(),this._prePassRenderer=null)},e._SceneComponentInitialization=e=>{let t=e._getComponent(h.NAME_PREPASSRENDERER);t||(t=new E(e),e._addComponent(t))})}class S{get generateNormalsInWorldSpace(){return this._generateNormalsInWorldSpace}set generateNormalsInWorldSpace(e){this._generateNormalsInWorldSpace!==e&&(this._generateNormalsInWorldSpace=e,this._markAllMaterialsAsPrePassDirty())}getIndex(e){return this._textureIndices[e]}get samples(){return this.defaultRT.samples}set samples(e){this.defaultRT.samples=e}get useSpecificClearForDepthTexture(){return this._useSpecificClearForDepthTexture}set useSpecificClearForDepthTexture(e){this._useSpecificClearForDepthTexture!==e&&(this._useSpecificClearForDepthTexture=e,this._isDirty=!0)}getRenderTarget(){return this._currentTarget}_setRenderTarget(e){e?this._currentTarget=e:(this._currentTarget=this.defaultRT,this._engine.currentRenderPassId=this._scene.activeCamera?.renderPassId??this._currentTarget.renderPassId)}get currentRTisSceneRT(){return this._currentTarget===this.defaultRT}_refreshGeometryBufferRendererLink(){if(this.doNotUseGeometryRendererFallback)this._geometryBuffer&&this._geometryBuffer._unlinkPrePassRenderer(),this._geometryBuffer=null,this._scene.disableGeometryBufferRenderer();else{if(this._geometryBuffer=this._scene.enableGeometryBufferRenderer(),!this._geometryBuffer)return void(this.doNotUseGeometryRendererFallback=!0);this._geometryBuffer._linkPrePassRenderer(this)}}get enabled(){return this._enabled}constructor(e){this.excludedSkinnedMesh=[],this.excludedMaterials=[],this.mrtCount=0,this._mrtTypes=[],this._mrtFormats=[],this._mrtLayout=[],this._mrtNames=[],this._textureIndices=[],this._generateNormalsInWorldSpace=!1,this._useSpecificClearForDepthTexture=!1,this._isDirty=!0,this._effectConfigurations=[],this.doNotUseGeometryRendererFallback=!0,this.renderTargets=[],this._clearColor=new _(0,0,0,0),this._clearDepthColor=new _(0,0,0,1),this._enabled=!1,this._geometryBufferRenderList=[],this._needsCompositionForThisPass=!1,this._postProcessesSourceForThisPass=[],this._postProcessChainForThisPass=[],this._postProcessesForUpdate=[],this.disableGammaTransform=!1,this._scene=e,this._engine=e.getEngine();let t=r.TEXTURETYPE_UNSIGNED_BYTE;this._engine._caps.textureFloat&&this._engine._caps.textureFloatLinearFiltering?t=r.TEXTURETYPE_FLOAT:this._engine._caps.textureHalfFloat&&this._engine._caps.textureHalfFloatLinearFiltering&&(t=r.TEXTURETYPE_HALF_FLOAT);for(let e=0;e<S.TextureFormats.length;++e){const s=S.TextureFormats[e].format;S.TextureFormats[e].type===r.TEXTURETYPE_FLOAT&&(S.TextureFormats[e].type=t,t!==r.TEXTURETYPE_FLOAT||s!==r.TEXTUREFORMAT_R&&s!==r.TEXTUREFORMAT_RG&&s!==r.TEXTUREFORMAT_RGBA||this._engine._caps.supportFloatTexturesResolve||(S.TextureFormats[e].type=r.TEXTURETYPE_HALF_FLOAT))}R(S),T(p),S._SceneComponentInitialization(this._scene),this.defaultRT=this._createRenderTarget("sceneprePassRT",null),this._currentTarget=this.defaultRT}_createRenderTarget(e,t){const s=new l(e,t,{width:this._engine.getRenderWidth(),height:this._engine.getRenderHeight()},0,this._scene,{generateMipMaps:!1,generateStencilBuffer:this._engine.isStencilEnable,defaultType:r.TEXTURETYPE_UNSIGNED_BYTE,types:[],drawOnlyOnFirstAttachmentByDefault:!0});return this.renderTargets.push(s),this._enabled&&this._update(),s}get isSupported(){return this._scene.getEngine().getCaps().drawBuffersExtension}bindAttachmentsForEffect(e,t){const s=t.getMaterial(),r=s&&s.isPrePassCapable,i=s&&-1!==this.excludedMaterials.indexOf(s);this.enabled&&this._currentTarget.enabled&&(e._multiTarget&&r&&!i?this._engine.bindAttachments(this._multiRenderAttachments):(this._engine._currentRenderTarget?this._engine.bindAttachments(this._defaultAttachments):this._engine.restoreSingleAttachment(),this._geometryBuffer&&this.currentRTisSceneRT&&!i&&this._geometryBuffer.renderList.push(t.getRenderingMesh())))}_reinitializeAttachments(){const e=[],t=[!1],s=[!1],i=[!0];for(let n=0;n<this.mrtCount;n++)e.push(!0),n>0&&(this._useSpecificClearForDepthTexture&&this._mrtLayout[n]===r.PREPASS_DEPTH_TEXTURE_TYPE?(t.push(!1),s.push(!0)):(t.push(!0),s.push(!1)),i.push(!1));this._multiRenderAttachments=this._engine.buildTextureLayout(e),this._clearAttachments=this._engine.buildTextureLayout(t),this._clearDepthAttachments=this._engine.buildTextureLayout(s),this._defaultAttachments=this._engine.buildTextureLayout(i)}_resetLayout(){for(let e=0;e<S.TextureFormats.length;e++)this._textureIndices[S.TextureFormats[e].purpose]=-1;this._textureIndices[r.PREPASS_COLOR_TEXTURE_TYPE]=0,this._mrtLayout=[r.PREPASS_COLOR_TEXTURE_TYPE],this._mrtTypes=[S.TextureFormats[r.PREPASS_COLOR_TEXTURE_TYPE].type],this._mrtFormats=[S.TextureFormats[r.PREPASS_COLOR_TEXTURE_TYPE].format],this._mrtNames=[S.TextureFormats[r.PREPASS_COLOR_TEXTURE_TYPE].name],this.mrtCount=1}_updateGeometryBufferLayout(){if(this._refreshGeometryBufferRendererLink(),this._geometryBuffer){this._geometryBuffer._resetLayout();const e=[];for(let t=0;t<this._mrtLayout.length;t++)e.push(!1);this._geometryBuffer._linkInternalTexture(this.defaultRT.getInternalTexture());const t=[{prePassConstant:r.PREPASS_DEPTH_TEXTURE_TYPE,geometryBufferConstant:p.DEPTH_TEXTURE_TYPE},{prePassConstant:r.PREPASS_NORMAL_TEXTURE_TYPE,geometryBufferConstant:p.NORMAL_TEXTURE_TYPE},{prePassConstant:r.PREPASS_POSITION_TEXTURE_TYPE,geometryBufferConstant:p.POSITION_TEXTURE_TYPE},{prePassConstant:r.PREPASS_REFLECTIVITY_TEXTURE_TYPE,geometryBufferConstant:p.REFLECTIVITY_TEXTURE_TYPE},{prePassConstant:r.PREPASS_VELOCITY_TEXTURE_TYPE,geometryBufferConstant:p.VELOCITY_TEXTURE_TYPE}];for(let s=0;s<t.length;s++){const r=this._mrtLayout.indexOf(t[s].prePassConstant);-1!==r&&(this._geometryBuffer._forceTextureType(t[s].geometryBufferConstant,r),e[r]=!0)}this._geometryBuffer._setAttachments(this._engine.buildTextureLayout(e))}}restoreAttachments(){this.enabled&&this._currentTarget.enabled&&this._defaultAttachments&&(this._engine._currentRenderTarget?this._engine.bindAttachments(this._defaultAttachments):this._engine.restoreSingleAttachment())}_beforeDraw(e,t,s){this._isDirty&&this._update(),this._enabled&&this._currentTarget.enabled&&(this._geometryBuffer&&(this._geometryBufferRenderList.length=0,this._geometryBuffer.renderList!==this._geometryBufferRenderList&&(this._geometryBuffer.renderList=this._geometryBufferRenderList)),this._setupOutputForThisPass(this._currentTarget,e))}_prepareFrame(e,t,s){e.renderTargetTexture?e.renderTargetTexture._prepareFrame(this._scene,t,s,e.renderTargetTexture.useCameraPostProcesses):this._postProcessesSourceForThisPass.length?this._scene.postProcessManager._prepareFrame():this._engine.restoreDefaultFramebuffer()}setCustomOutput(e){const t=this._postProcessesSourceForThisPass[0];return!!t&&(t.inputTexture=e.renderTarget,!0)}_renderPostProcesses(e,t){const s=this._postProcessesSourceForThisPass[0],r=s?s.inputTexture:e.renderTargetTexture?e.renderTargetTexture.renderTarget:null;let i=this._currentTarget._beforeCompositionPostProcesses;if(this._needsCompositionForThisPass){i=this._postProcessChainForThisPass,i.length=0;for(let e=0;e<this._currentTarget._beforeCompositionPostProcesses.length;e++)i.push(this._currentTarget._beforeCompositionPostProcesses[e]);i.push(this._currentTarget.imageProcessingPostProcess)}i.length&&(this._scene.postProcessManager._prepareFrame(this._currentTarget.renderTarget?.texture,i),this._scene.postProcessManager.directRender(i,r,!1,t))}_afterDraw(e,t){this._enabled&&this._currentTarget.enabled&&(this._prepareFrame(this._currentTarget,e,t),this._renderPostProcesses(this._currentTarget,e))}_clear(){this._isDirty&&this._update(),this._enabled&&this._currentTarget.enabled&&(this._bindFrameBuffer(),this._engine.bindAttachments(this._clearAttachments),this._engine.clear(this._clearColor,!0,!1,!1),this._useSpecificClearForDepthTexture&&(this._engine.bindAttachments(this._clearDepthAttachments),this._engine.clear(this._clearDepthColor,!0,!1,!1)),this._engine.bindAttachments(this._defaultAttachments))}_bindFrameBuffer(){if(this._enabled&&this._currentTarget.enabled){this._currentTarget._checkSize();const e=this._currentTarget.renderTarget;e&&this._engine.bindFramebuffer(e)}}_setEnabled(e){this._enabled=e}_setRenderTargetEnabled(e,t){e.enabled=t,t||this._unlinkInternalTexture(e)}addEffectConfiguration(e){for(let t=0;t<this._effectConfigurations.length;t++)if(this._effectConfigurations[t].name===e.name)return this._effectConfigurations[t];return this._effectConfigurations.push(e),e.clearColor&&this._clearColor.copyFrom(e.clearColor),e}getEffectConfiguration(e){for(let t=0;t<this._effectConfigurations.length;t++)if(this._effectConfigurations[t].name===e)return this._effectConfigurations[t];return null}_enable(){const e=this.mrtCount;for(let e=0;e<this._effectConfigurations.length;e++)this._effectConfigurations[e].enabled&&this._enableTextures(this._effectConfigurations[e].texturesRequired);for(let t=0;t<this.renderTargets.length;t++){this.mrtCount===e&&this.renderTargets[t].count===this.mrtCount||this.renderTargets[t].updateCount(this.mrtCount,{types:this._mrtTypes,formats:this._mrtFormats},this._mrtNames.concat("prePass_DepthBuffer")),this.renderTargets[t]._resetPostProcessChain();for(let e=0;e<this._effectConfigurations.length;e++)this._effectConfigurations[e].enabled&&(!this._effectConfigurations[e].postProcess&&this._effectConfigurations[e].createPostProcess&&this._effectConfigurations[e].createPostProcess(),this._effectConfigurations[e].postProcess&&this.renderTargets[t]._beforeCompositionPostProcesses.push(this._effectConfigurations[e].postProcess))}this._reinitializeAttachments(),this._setEnabled(!0),this._updateGeometryBufferLayout()}_disable(){this._setEnabled(!1);for(let e=0;e<this.renderTargets.length;e++)this._setRenderTargetEnabled(this.renderTargets[e],!1);this._resetLayout();for(let e=0;e<this._effectConfigurations.length;e++)this._effectConfigurations[e].enabled=!1}_getPostProcessesSource(e,t){if(t)return t._postProcesses;if(e.renderTargetTexture){if(e.renderTargetTexture.useCameraPostProcesses){const t=e.renderTargetTexture.activeCamera?e.renderTargetTexture.activeCamera:this._scene.activeCamera;return t?t._postProcesses:[]}return e.renderTargetTexture.postProcesses?e.renderTargetTexture.postProcesses:[]}return this._scene.activeCamera?this._scene.activeCamera._postProcesses:[]}_setupOutputForThisPass(e,t){const s=t&&this._scene.activeCameras&&!!this._scene.activeCameras.length&&0!==this._scene.activeCameras.indexOf(t),r=this._getPostProcessesSource(e,t);this._postProcessesSourceForThisPass.length=0;for(let e=0;e<r.length;e++){const t=r[e];t&&this._postProcessesSourceForThisPass.push(t)}this._scene.autoClear=!0;const i=this._hasImageProcessing(this._postProcessesSourceForThisPass);this._needsCompositionForThisPass=!i&&!this.disableGammaTransform&&this._needsImageProcessing()&&!s;const n=this._getFirstPostProcess(this._postProcessesSourceForThisPass),a=e._beforeCompositionPostProcesses&&e._beforeCompositionPostProcesses[0];let o=null;this._scene.imageProcessingConfiguration.applyByPostProcess=this._needsCompositionForThisPass||i,this._needsCompositionForThisPass&&!e.imageProcessingPostProcess&&e._createCompositionEffect(),a?o=a:this._needsCompositionForThisPass?o=e.imageProcessingPostProcess:n&&(o=n),this._bindFrameBuffer(),this._linkInternalTexture(e,o)}_linkInternalTexture(e,t){t&&(t.autoClear=!1,t.inputTexture=e.renderTarget),e._outputPostProcess!==t&&(e._outputPostProcess&&this._unlinkInternalTexture(e),e._outputPostProcess=t),e._internalTextureDirty&&(this._updateGeometryBufferLayout(),e._internalTextureDirty=!1)}_unlinkInternalTexture(e){e._outputPostProcess&&(e._outputPostProcess.autoClear=!0,e._outputPostProcess.restoreDefaultInputTexture(),e._outputPostProcess=null)}_needsImageProcessing(){for(let e=0;e<this._effectConfigurations.length;e++)if(this._effectConfigurations[e].enabled&&this._effectConfigurations[e].needsImageProcessing)return!0;return!1}_hasImageProcessing(e){let t=!1;if(e)for(let s=0;s<e.length;s++)if("ImageProcessingPostProcess"===e[s]?.getClassName()){t=!0;break}return t}_getFirstPostProcess(e){for(let t=0;t<e.length;t++)if(null!==e[t])return e[t];return null}markAsDirty(){this._isDirty=!0}_enableTextures(e){this._scene.needsPreviousWorldMatrices=!1;for(let t=0;t<e.length;t++){const s=e[t];-1===this._textureIndices[s]&&(this._textureIndices[s]=this._mrtLayout.length,this._mrtLayout.push(s),this._mrtTypes.push(S.TextureFormats[s].type),this._mrtFormats.push(S.TextureFormats[s].format),this._mrtNames.push(S.TextureFormats[s].name),this.mrtCount++),s!==r.PREPASS_VELOCITY_TEXTURE_TYPE&&s!==r.PREPASS_VELOCITY_LINEAR_TEXTURE_TYPE||(this._scene.needsPreviousWorldMatrices=!0)}}update(){this._isDirty&&this._update()}_update(){this._disable();let e,t=!1;this._scene.imageProcessingConfiguration.applyByPostProcess=!1,this._scene._depthPeelingRenderer&&this._scene.useOrderIndependentTransparency&&(this._scene._depthPeelingRenderer.setPrePassRenderer(this),t=!0);for(let e=0;e<this._scene.materials.length;e++)this._scene.materials[e].setPrePassRenderer(this)&&(t=!0);t&&this._setRenderTargetEnabled(this.defaultRT,!0);for(let s=0;s<this.renderTargets.length;s++){if(this.renderTargets[s].renderTargetTexture)e=this._getPostProcessesSource(this.renderTargets[s]);else{const t=this._scene.activeCameras&&this._scene.activeCameras.length>0?this._scene.activeCameras[0]:this._scene.activeCamera;if(!t)continue;e=t._postProcesses}if(!e)continue;const r=e;e=this._postProcessesForUpdate,e.length=0;for(let t=0;t<r.length;t++){const s=r[t];s&&e.push(s)}if(e){for(let r=0;r<e.length;r++)e[r].setPrePassRenderer(this)&&(this._setRenderTargetEnabled(this.renderTargets[s],!0),t=!0);this._hasImageProcessing(e)&&(this._scene.imageProcessingConfiguration.applyByPostProcess=!0)}}this._markAllMaterialsAsPrePassDirty(),this._isDirty=!1,t&&this._enable()}_markAllMaterialsAsPrePassDirty(){const e=this._scene.materials;for(let t=0;t<e.length;t++)e[t].markAsDirty(P.PrePassDirtyFlag)}dispose(){for(let e=this.renderTargets.length-1;e>=0;e--)this.renderTargets[e].dispose();for(let e=0;e<this._effectConfigurations.length;e++)this._effectConfigurations[e].dispose&&this._effectConfigurations[e].dispose()}}S._SceneComponentInitialization=e=>{throw f("PrePassRendererSceneComponent")},S.TextureFormats=[{purpose:r.PREPASS_IRRADIANCE_LEGACY_TEXTURE_TYPE,type:r.TEXTURETYPE_HALF_FLOAT,format:r.TEXTUREFORMAT_RGBA,name:"prePass_IrradianceLegacy"},{purpose:r.PREPASS_POSITION_TEXTURE_TYPE,type:r.TEXTURETYPE_HALF_FLOAT,format:r.TEXTUREFORMAT_RGBA,name:"prePass_Position"},{purpose:r.PREPASS_VELOCITY_TEXTURE_TYPE,type:r.TEXTURETYPE_UNSIGNED_BYTE,format:r.TEXTUREFORMAT_RGBA,name:"prePass_Velocity"},{purpose:r.PREPASS_REFLECTIVITY_TEXTURE_TYPE,type:r.TEXTURETYPE_UNSIGNED_BYTE,format:r.TEXTUREFORMAT_RGBA,name:"prePass_Reflectivity"},{purpose:r.PREPASS_COLOR_TEXTURE_TYPE,type:r.TEXTURETYPE_HALF_FLOAT,format:r.TEXTUREFORMAT_RGBA,name:"prePass_Color"},{purpose:r.PREPASS_DEPTH_TEXTURE_TYPE,type:r.TEXTURETYPE_FLOAT,format:r.TEXTUREFORMAT_R,name:"prePass_Depth"},{purpose:r.PREPASS_NORMAL_TEXTURE_TYPE,type:r.TEXTURETYPE_HALF_FLOAT,format:r.TEXTUREFORMAT_RGBA,name:"prePass_Normal"},{purpose:r.PREPASS_ALBEDO_SQRT_TEXTURE_TYPE,type:r.TEXTURETYPE_UNSIGNED_BYTE,format:r.TEXTUREFORMAT_RGBA,name:"prePass_Albedo"},{purpose:r.PREPASS_WORLD_NORMAL_TEXTURE_TYPE,type:r.TEXTURETYPE_UNSIGNED_BYTE,format:r.TEXTUREFORMAT_RGBA,name:"prePass_WorldNormal"},{purpose:r.PREPASS_LOCAL_POSITION_TEXTURE_TYPE,type:r.TEXTURETYPE_HALF_FLOAT,format:r.TEXTUREFORMAT_RGBA,name:"prePass_LocalPosition"},{purpose:r.PREPASS_SCREENSPACE_DEPTH_TEXTURE_TYPE,type:r.TEXTURETYPE_FLOAT,format:r.TEXTUREFORMAT_R,name:"prePass_ScreenDepth"},{purpose:r.PREPASS_VELOCITY_LINEAR_TEXTURE_TYPE,type:r.TEXTURETYPE_HALF_FLOAT,format:r.TEXTUREFORMAT_RGBA,name:"prePass_VelocityLinear"},{purpose:r.PREPASS_IRRADIANCE_TEXTURE_TYPE,type:r.TEXTURETYPE_HALF_FLOAT,format:r.TEXTUREFORMAT_RGBA,name:"prePass_Irradiance"}];export{S as P,R,E as a};
//# sourceMappingURL=prePassRenderer.pure-B6DM-kfL.esm.min.js.map