diff --git a/packages/dev/core/src/FrameGraph/Tasks/Rendering/geometryRendererTask.ts b/packages/dev/core/src/FrameGraph/Tasks/Rendering/geometryRendererTask.ts index 0c8ccadf846..108b582fa26 100644 --- a/packages/dev/core/src/FrameGraph/Tasks/Rendering/geometryRendererTask.ts +++ b/packages/dev/core/src/FrameGraph/Tasks/Rendering/geometryRendererTask.ts @@ -247,6 +247,7 @@ export class FrameGraphGeometryRendererTask extends FrameGraphTask { this._renderer.renderParticles = false; this._renderer.enableBoundingBoxRendering = false; this._renderer.enableOutlineRendering = false; + this._renderer.disableDepthPrePass = true; this._renderer.customIsReadyFunction = (mesh: AbstractMesh, refreshRate: number, preWarm?: boolean) => { if (this.dontRenderWhenMaterialDepthWriteIsDisabled && mesh.material && mesh.material.disableDepthWrite) { diff --git a/packages/dev/core/src/Rendering/objectRenderer.ts b/packages/dev/core/src/Rendering/objectRenderer.ts index 6e794b0e518..b83d0e47689 100644 --- a/packages/dev/core/src/Rendering/objectRenderer.ts +++ b/packages/dev/core/src/Rendering/objectRenderer.ts @@ -173,6 +173,19 @@ export class ObjectRenderer { */ public dontSetTransformationMatrix = false; + private _disableDepthPrePass = false; + /** + * Specifies to disable depth pre-pass if true (default: false) + */ + public get disableDepthPrePass() { + return this._disableDepthPrePass; + } + + public set disableDepthPrePass(value: boolean) { + this._disableDepthPrePass = value; + this._renderingManager.disableDepthPrePass = value; + } + /** * Override the mesh isReady function with your own one. */ diff --git a/packages/dev/core/src/Rendering/renderingGroup.ts b/packages/dev/core/src/Rendering/renderingGroup.ts index 98aa1c9b567..3c54d85774c 100644 --- a/packages/dev/core/src/Rendering/renderingGroup.ts +++ b/packages/dev/core/src/Rendering/renderingGroup.ts @@ -43,6 +43,8 @@ export class RenderingGroup { public onBeforeTransparentRendering: () => void; + public disableDepthPrePass = false; + /** * Set the opaque sort comparison function. * If null the sub meshes will be render in the order they were created @@ -201,7 +203,7 @@ export class RenderingGroup { * @param subMeshes The submeshes to render */ private _renderOpaqueSorted(subMeshes: SmartArray): void { - RenderingGroup._RenderSorted(subMeshes, this._opaqueSortCompareFn, this._scene.activeCamera, false); + RenderingGroup._RenderSorted(subMeshes, this._opaqueSortCompareFn, this._scene.activeCamera, false, this.disableDepthPrePass); } /** @@ -209,7 +211,7 @@ export class RenderingGroup { * @param subMeshes The submeshes to render */ private _renderAlphaTestSorted(subMeshes: SmartArray): void { - RenderingGroup._RenderSorted(subMeshes, this._alphaTestSortCompareFn, this._scene.activeCamera, false); + RenderingGroup._RenderSorted(subMeshes, this._alphaTestSortCompareFn, this._scene.activeCamera, false, this.disableDepthPrePass); } /** @@ -217,7 +219,7 @@ export class RenderingGroup { * @param subMeshes The submeshes to render */ private _renderTransparentSorted(subMeshes: SmartArray): void { - RenderingGroup._RenderSorted(subMeshes, this._transparentSortCompareFn, this._scene.activeCamera, true); + RenderingGroup._RenderSorted(subMeshes, this._transparentSortCompareFn, this._scene.activeCamera, true, this.disableDepthPrePass); } /** @@ -226,12 +228,14 @@ export class RenderingGroup { * @param sortCompareFn The comparison function use to sort * @param camera The camera position use to preprocess the submeshes to help sorting * @param transparent Specifies to activate blending if true + * @param disableDepthPrePass Specifies to disable depth pre-pass if true (default: false) */ private static _RenderSorted( subMeshes: SmartArray, sortCompareFn: Nullable<(a: SubMesh, b: SubMesh) => number>, camera: Nullable, - transparent: boolean + transparent: boolean, + disableDepthPrePass?: boolean ): void { let subIndex = 0; let subMesh: SubMesh; @@ -262,7 +266,7 @@ export class RenderingGroup { if (transparent) { const material = subMesh.getMaterial(); - if (material && material.needDepthPrePass) { + if (material && material.needDepthPrePass && !disableDepthPrePass) { const engine = material.getScene().getEngine(); engine.setColorWrite(false); engine.setAlphaMode(Constants.ALPHA_DISABLE); @@ -413,13 +417,13 @@ export class RenderingGroup { this._transparentSubMeshes.push(subMesh); } else if (material.needAlphaTestingForMesh(mesh)) { // Alpha test - if (material.needDepthPrePass) { + if (material.needDepthPrePass && !this.disableDepthPrePass) { this._depthOnlySubMeshes.push(subMesh); } this._alphaTestSubMeshes.push(subMesh); } else { - if (material.needDepthPrePass) { + if (material.needDepthPrePass && !this.disableDepthPrePass) { this._depthOnlySubMeshes.push(subMesh); } diff --git a/packages/dev/core/src/Rendering/renderingManager.ts b/packages/dev/core/src/Rendering/renderingManager.ts index 824f5ce7410..794bd3a2056 100644 --- a/packages/dev/core/src/Rendering/renderingManager.ts +++ b/packages/dev/core/src/Rendering/renderingManager.ts @@ -80,6 +80,21 @@ export class RenderingManager { */ public _useSceneAutoClearSetup = false; + private _disableDepthPrePass = false; + /** + * Specifies to disable depth pre-pass if true (default: false) + */ + public get disableDepthPrePass() { + return this._disableDepthPrePass; + } + + public set disableDepthPrePass(value: boolean) { + this._disableDepthPrePass = value; + for (const group of this._renderingGroups) { + group.disableDepthPrePass = value; + } + } + private _scene: Scene; private _renderingGroups = new Array(); private _depthStencilBufferAlreadyCleaned: boolean; @@ -301,6 +316,7 @@ export class RenderingManager { this._customAlphaTestSortCompareFn[renderingGroupId], this._customTransparentSortCompareFn[renderingGroupId] ); + this._renderingGroups[renderingGroupId].disableDepthPrePass = this._disableDepthPrePass; } }