Skip to content

Commit

Permalink
NodeMaterial: Only call setupDepth() with active depth buffer. (#29799
Browse files Browse the repository at this point in the history
)

* NodeMaterial: Use early out in `setupDepth()`.

* Update NodeMaterial.js

* NodeMaterial: Refactor `setupDepth()`.

* NodeMaterial: Clean up.
  • Loading branch information
Mugen87 authored Nov 4, 2024
1 parent 3ef244c commit c3f685f
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/materials/nodes/NodeMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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 ) {

Expand All @@ -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 ) {
Expand Down

0 comments on commit c3f685f

Please sign in to comment.