Просмотр исходного кода

Nodes: Cache linear depth and viewZ of depth textures in PassNode (#28922)

* add arguments to getLinearDepthNode and getViewZ

* only assign to _viewZ and _linearDepth of renderTarget when name is 'depth'

* remove error check

* adjust functions to use cache system

* fix cache access typo

* restore comment
Christian Helgeson 1 год назад
Родитель
Сommit
f5eaae88a0
1 измененных файлов с 18 добавлено и 13 удалено
  1. 18 13
      src/nodes/display/PassNode.js

+ 18 - 13
src/nodes/display/PassNode.js

@@ -100,10 +100,10 @@ class PassNode extends TempNode {
 			depth: depthTexture
 			depth: depthTexture
 		};
 		};
 
 
-		this._nodes = {};
+		this._textureNodes = {};
+		this._linearDepthNodes = {};
+		this._viewZNodes = {};
 
 
-		this._linearDepthNode = null;
-		this._viewZNode = null;
 		this._cameraNear = uniform( 0 );
 		this._cameraNear = uniform( 0 );
 		this._cameraFar = uniform( 0 );
 		this._cameraFar = uniform( 0 );
 
 
@@ -157,11 +157,11 @@ class PassNode extends TempNode {
 
 
 	getTextureNode( name = 'output' ) {
 	getTextureNode( name = 'output' ) {
 
 
-		let textureNode = this._nodes[ name ];
+		let textureNode = this._textureNodes[ name ];
 
 
 		if ( textureNode === undefined ) {
 		if ( textureNode === undefined ) {
 
 
-			this._nodes[ name ] = textureNode = nodeObject( new PassMultipleTextureNode( this, name ) );
+			this._textureNodes[ name ] = textureNode = nodeObject( new PassMultipleTextureNode( this, name ) );
 
 
 		}
 		}
 
 
@@ -169,35 +169,40 @@ class PassNode extends TempNode {
 
 
 	}
 	}
 
 
-	getViewZNode() {
+	getViewZNode( name = 'depth' ) {
 
 
-		if ( this._viewZNode === null ) {
+		let viewZNode = this._viewZNodes[ name ];
+
+		if ( viewZNode === undefined ) {
 
 
 			const cameraNear = this._cameraNear;
 			const cameraNear = this._cameraNear;
 			const cameraFar = this._cameraFar;
 			const cameraFar = this._cameraFar;
 
 
-			this._viewZNode = perspectiveDepthToViewZ( this.getTextureNode( 'depth' ), cameraNear, cameraFar );
+			this._viewZNodes[ name ] = viewZNode = perspectiveDepthToViewZ( this.getTextureNode( name ), cameraNear, cameraFar );
 
 
 		}
 		}
 
 
-		return this._viewZNode;
+		return viewZNode;
 
 
 	}
 	}
 
 
-	getLinearDepthNode() {
+	getLinearDepthNode( name = 'depth' ) {
+
+		let linearDepthNode = this._linearDepthNodes[ name ];
 
 
-		if ( this._linearDepthNode === null ) {
+		if ( linearDepthNode === undefined ) {
 
 
 			const cameraNear = this._cameraNear;
 			const cameraNear = this._cameraNear;
 			const cameraFar = this._cameraFar;
 			const cameraFar = this._cameraFar;
+			const viewZNode = this.getViewZNode( name );
 
 
 			// TODO: just if ( builder.camera.isPerspectiveCamera )
 			// TODO: just if ( builder.camera.isPerspectiveCamera )
 
 
-			this._linearDepthNode = viewZToOrthographicDepth( this.getViewZNode(), cameraNear, cameraFar );
+			this._linearDepthNodes[ name ] = linearDepthNode = viewZToOrthographicDepth( viewZNode, cameraNear, cameraFar );
 
 
 		}
 		}
 
 
-		return this._linearDepthNode;
+		return linearDepthNode;
 
 
 	}
 	}
 
 

粤ICP备19079148号