Sfoglia il codice sorgente

PassNode: Fix depthTexture creation when `depthBuffer: false` (#33239)

thelazylama 1 mese fa
parent
commit
e7df696957
2 ha cambiato i file con 40 aggiunte e 21 eliminazioni
  1. 23 10
      src/nodes/display/PassNode.js
  2. 17 11
      src/renderers/common/Textures.js

+ 23 - 10
src/nodes/display/PassNode.js

@@ -251,14 +251,22 @@ class PassNode extends TempNode {
 		 */
 		this._height = 1;
 
-		const depthTexture = new DepthTexture();
-		depthTexture.isRenderTargetTexture = true;
-		//depthTexture.type = FloatType;
-		depthTexture.name = 'depth';
-
 		const renderTarget = new RenderTarget( this._width * this._pixelRatio, this._height * this._pixelRatio, { type: HalfFloatType, ...options, } );
 		renderTarget.texture.name = 'output';
-		renderTarget.depthTexture = depthTexture;
+
+		let depthTexture = null;
+
+		if ( this.scope === PassNode.DEPTH || options.depthBuffer !== false ) {
+
+			depthTexture = new DepthTexture();
+			depthTexture.isRenderTargetTexture = true;
+			//depthTexture.type = FloatType;
+			depthTexture.name = 'depth';
+
+			renderTarget.depthTexture = depthTexture;
+
+		}
+
 
 		/**
 		 * The pass's render target.
@@ -310,13 +318,18 @@ class PassNode extends TempNode {
 		 * A dictionary holding the internal result textures.
 		 *
 		 * @private
-		 * @type {Object<string, Texture>}
+		 * @type {{ output: Texture, depth?: DepthTexture }}
 		 */
 		this._textures = {
-			output: renderTarget.texture,
-			depth: depthTexture
+			output: renderTarget.texture
 		};
 
+		if ( depthTexture !== null ) {
+
+			this._textures.depth = depthTexture;
+
+		}
+
 		/**
 		 * A dictionary holding the internal texture nodes.
 		 *
@@ -757,7 +770,7 @@ class PassNode extends TempNode {
 
 		this.renderTarget.texture.type = renderer.getOutputBufferType();
 
-		if ( renderer.reversedDepthBuffer === true ) {
+		if ( renderer.reversedDepthBuffer === true && this.renderTarget.depthTexture !== null ) {
 
 			this.renderTarget.depthTexture.type = FloatType;
 

+ 17 - 11
src/renderers/common/Textures.js

@@ -78,24 +78,30 @@ class Textures extends DataMap {
 		const mipWidth = size.width >> activeMipmapLevel;
 		const mipHeight = size.height >> activeMipmapLevel;
 
-		let depthTexture = renderTarget.depthTexture || depthTextureMips[ activeMipmapLevel ];
 		const useDepthTexture = renderTarget.depthBuffer === true || renderTarget.stencilBuffer === true;
+		let depthTexture = null;
 
 		let textureNeedsUpdate = false;
 
-		if ( depthTexture === undefined && useDepthTexture ) {
+		if ( useDepthTexture ) {
 
-			depthTexture = new DepthTexture();
+			depthTexture = renderTarget.depthTexture || depthTextureMips[ activeMipmapLevel ];
 
-			depthTexture.format = renderTarget.stencilBuffer ? DepthStencilFormat : DepthFormat;
-			depthTexture.type = renderTarget.stencilBuffer ? UnsignedInt248Type : UnsignedIntType; // FloatType
-			depthTexture.image.width = mipWidth;
-			depthTexture.image.height = mipHeight;
-			depthTexture.image.depth = size.depth;
-			depthTexture.renderTarget = renderTarget;
-			depthTexture.isArrayTexture = renderTarget.multiview === true && size.depth > 1;
+			if ( depthTexture === undefined ) {
 
-			depthTextureMips[ activeMipmapLevel ] = depthTexture;
+				depthTexture = new DepthTexture();
+
+				depthTexture.format = renderTarget.stencilBuffer ? DepthStencilFormat : DepthFormat;
+				depthTexture.type = renderTarget.stencilBuffer ? UnsignedInt248Type : UnsignedIntType; // FloatType
+				depthTexture.image.width = mipWidth;
+				depthTexture.image.height = mipHeight;
+				depthTexture.image.depth = size.depth;
+				depthTexture.renderTarget = renderTarget;
+				depthTexture.isArrayTexture = renderTarget.multiview === true && size.depth > 1;
+
+				depthTextureMips[ activeMipmapLevel ] = depthTexture;
+
+			}
 
 		}
 

粤ICP备19079148号