Skip to content

Commit e7df696

Browse files
PassNode: Fix depthTexture creation when depthBuffer: false (#33239)
1 parent deffab6 commit e7df696

2 files changed

Lines changed: 40 additions & 21 deletions

File tree

src/nodes/display/PassNode.js

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -251,14 +251,22 @@ class PassNode extends TempNode {
251251
*/
252252
this._height = 1;
253253

254-
const depthTexture = new DepthTexture();
255-
depthTexture.isRenderTargetTexture = true;
256-
//depthTexture.type = FloatType;
257-
depthTexture.name = 'depth';
258-
259254
const renderTarget = new RenderTarget( this._width * this._pixelRatio, this._height * this._pixelRatio, { type: HalfFloatType, ...options, } );
260255
renderTarget.texture.name = 'output';
261-
renderTarget.depthTexture = depthTexture;
256+
257+
let depthTexture = null;
258+
259+
if ( this.scope === PassNode.DEPTH || options.depthBuffer !== false ) {
260+
261+
depthTexture = new DepthTexture();
262+
depthTexture.isRenderTargetTexture = true;
263+
//depthTexture.type = FloatType;
264+
depthTexture.name = 'depth';
265+
266+
renderTarget.depthTexture = depthTexture;
267+
268+
}
269+
262270

263271
/**
264272
* The pass's render target.
@@ -310,13 +318,18 @@ class PassNode extends TempNode {
310318
* A dictionary holding the internal result textures.
311319
*
312320
* @private
313-
* @type {Object<string, Texture>}
321+
* @type {{ output: Texture, depth?: DepthTexture }}
314322
*/
315323
this._textures = {
316-
output: renderTarget.texture,
317-
depth: depthTexture
324+
output: renderTarget.texture
318325
};
319326

327+
if ( depthTexture !== null ) {
328+
329+
this._textures.depth = depthTexture;
330+
331+
}
332+
320333
/**
321334
* A dictionary holding the internal texture nodes.
322335
*
@@ -757,7 +770,7 @@ class PassNode extends TempNode {
757770

758771
this.renderTarget.texture.type = renderer.getOutputBufferType();
759772

760-
if ( renderer.reversedDepthBuffer === true ) {
773+
if ( renderer.reversedDepthBuffer === true && this.renderTarget.depthTexture !== null ) {
761774

762775
this.renderTarget.depthTexture.type = FloatType;
763776

src/renderers/common/Textures.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,24 +78,30 @@ class Textures extends DataMap {
7878
const mipWidth = size.width >> activeMipmapLevel;
7979
const mipHeight = size.height >> activeMipmapLevel;
8080

81-
let depthTexture = renderTarget.depthTexture || depthTextureMips[ activeMipmapLevel ];
8281
const useDepthTexture = renderTarget.depthBuffer === true || renderTarget.stencilBuffer === true;
82+
let depthTexture = null;
8383

8484
let textureNeedsUpdate = false;
8585

86-
if ( depthTexture === undefined && useDepthTexture ) {
86+
if ( useDepthTexture ) {
8787

88-
depthTexture = new DepthTexture();
88+
depthTexture = renderTarget.depthTexture || depthTextureMips[ activeMipmapLevel ];
8989

90-
depthTexture.format = renderTarget.stencilBuffer ? DepthStencilFormat : DepthFormat;
91-
depthTexture.type = renderTarget.stencilBuffer ? UnsignedInt248Type : UnsignedIntType; // FloatType
92-
depthTexture.image.width = mipWidth;
93-
depthTexture.image.height = mipHeight;
94-
depthTexture.image.depth = size.depth;
95-
depthTexture.renderTarget = renderTarget;
96-
depthTexture.isArrayTexture = renderTarget.multiview === true && size.depth > 1;
90+
if ( depthTexture === undefined ) {
9791

98-
depthTextureMips[ activeMipmapLevel ] = depthTexture;
92+
depthTexture = new DepthTexture();
93+
94+
depthTexture.format = renderTarget.stencilBuffer ? DepthStencilFormat : DepthFormat;
95+
depthTexture.type = renderTarget.stencilBuffer ? UnsignedInt248Type : UnsignedIntType; // FloatType
96+
depthTexture.image.width = mipWidth;
97+
depthTexture.image.height = mipHeight;
98+
depthTexture.image.depth = size.depth;
99+
depthTexture.renderTarget = renderTarget;
100+
depthTexture.isArrayTexture = renderTarget.multiview === true && size.depth > 1;
101+
102+
depthTextureMips[ activeMipmapLevel ] = depthTexture;
103+
104+
}
99105

100106
}
101107

0 commit comments

Comments
 (0)