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 ) {