Skip to content

Commit c3f685f

Browse files
authored
NodeMaterial: Only call setupDepth() with active depth buffer. (#29799)
* NodeMaterial: Use early out in `setupDepth()`. * Update NodeMaterial.js * NodeMaterial: Refactor `setupDepth()`. * NodeMaterial: Clean up.
1 parent 3ef244c commit c3f685f

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

src/materials/nodes/NodeMaterial.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ class NodeMaterial extends Material {
9999

100100
builder.context.setupNormal = () => this.setupNormal( builder );
101101

102+
const renderer = builder.renderer;
103+
const renderTarget = renderer.getRenderTarget();
104+
102105
// < VERTEX STAGE >
103106

104107
builder.addStack();
@@ -121,7 +124,21 @@ class NodeMaterial extends Material {
121124

122125
const clippingNode = this.setupClipping( builder );
123126

124-
if ( this.depthWrite === true ) this.setupDepth( builder );
127+
if ( this.depthWrite === true ) {
128+
129+
// only write depth if depth buffer is configured
130+
131+
if ( renderTarget !== null ) {
132+
133+
if ( renderTarget.depthBuffer === true ) this.setupDepth( builder );
134+
135+
} else {
136+
137+
if ( renderer.depth === true ) this.setupDepth( builder );
138+
139+
}
140+
141+
}
125142

126143
if ( this.fragmentNode === null ) {
127144

@@ -148,11 +165,9 @@ class NodeMaterial extends Material {
148165

149166
// MRT
150167

151-
const renderTarget = builder.renderer.getRenderTarget();
152-
153168
if ( renderTarget !== null ) {
154169

155-
const mrt = builder.renderer.getMRT();
170+
const mrt = renderer.getMRT();
156171
const materialMRT = this.mrtNode;
157172

158173
if ( mrt !== null ) {

0 commit comments

Comments
 (0)