From c3f685f49d7a747397d44b8f9fedd4fcec792fa7 Mon Sep 17 00:00:00 2001 From: Michael Herzog Date: Mon, 4 Nov 2024 15:52:36 +0100 Subject: [PATCH] NodeMaterial: Only call `setupDepth()` with active depth buffer. (#29799) * NodeMaterial: Use early out in `setupDepth()`. * Update NodeMaterial.js * NodeMaterial: Refactor `setupDepth()`. * NodeMaterial: Clean up. --- src/materials/nodes/NodeMaterial.js | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/materials/nodes/NodeMaterial.js b/src/materials/nodes/NodeMaterial.js index 96efbf7345896d..5179d5864f1c85 100644 --- a/src/materials/nodes/NodeMaterial.js +++ b/src/materials/nodes/NodeMaterial.js @@ -99,6 +99,9 @@ class NodeMaterial extends Material { builder.context.setupNormal = () => this.setupNormal( builder ); + const renderer = builder.renderer; + const renderTarget = renderer.getRenderTarget(); + // < VERTEX STAGE > builder.addStack(); @@ -121,7 +124,21 @@ class NodeMaterial extends Material { const clippingNode = this.setupClipping( builder ); - if ( this.depthWrite === true ) this.setupDepth( builder ); + if ( this.depthWrite === true ) { + + // only write depth if depth buffer is configured + + if ( renderTarget !== null ) { + + if ( renderTarget.depthBuffer === true ) this.setupDepth( builder ); + + } else { + + if ( renderer.depth === true ) this.setupDepth( builder ); + + } + + } if ( this.fragmentNode === null ) { @@ -148,11 +165,9 @@ class NodeMaterial extends Material { // MRT - const renderTarget = builder.renderer.getRenderTarget(); - if ( renderTarget !== null ) { - const mrt = builder.renderer.getMRT(); + const mrt = renderer.getMRT(); const materialMRT = this.mrtNode; if ( mrt !== null ) {