Sfoglia il codice sorgente

Nodes: Fixes and improvements for `reflector` and `gaussianBlur` (#29619)

* GaussianBlurNode: preserves input UV

* fix sequential events of update before

* add multi-sampler support
sunag 1 anno fa
parent
commit
0e584a2057

+ 1 - 0
examples/jsm/tsl/display/GaussianBlurNode.js

@@ -60,6 +60,7 @@ class GaussianBlurNode extends TempNode {
 		this._verticalRT.texture.name = 'GaussianBlurNode.vertical';
 
 		this._textureNode = passTexture( this, this._verticalRT.texture );
+		this._textureNode.uvNode = textureNode.uvNode;
 
 		this.updateBeforeType = NodeUpdateType.FRAME;
 

+ 1 - 0
src/nodes/core/Node.js

@@ -378,6 +378,7 @@ class Node extends EventDispatcher {
 		}
 
 		builder.removeChain( this );
+		builder.addSequentialNode( this );
 
 		return result;
 

+ 18 - 2
src/nodes/core/NodeBuilder.js

@@ -82,6 +82,7 @@ class NodeBuilder {
 		this.camera = null;
 
 		this.nodes = [];
+		this.sequentialNodes = [];
 		this.updateNodes = [];
 		this.updateBeforeNodes = [];
 		this.updateAfterNodes = [];
@@ -320,13 +321,21 @@ class NodeBuilder {
 
 	}
 
+	addSequentialNode( node ) {
+
+		if ( this.sequentialNodes.includes( node ) === false ) {
+
+			this.sequentialNodes.push( node );
+
+		}
+
+	}
+
 	buildUpdateNodes() {
 
 		for ( const node of this.nodes ) {
 
 			const updateType = node.getUpdateType();
-			const updateBeforeType = node.getUpdateBeforeType();
-			const updateAfterType = node.getUpdateAfterType();
 
 			if ( updateType !== NodeUpdateType.NONE ) {
 
@@ -334,6 +343,13 @@ class NodeBuilder {
 
 			}
 
+		}
+
+		for ( const node of this.sequentialNodes ) {
+
+			const updateBeforeType = node.getUpdateBeforeType();
+			const updateAfterType = node.getUpdateAfterType();
+
 			if ( updateBeforeType !== NodeUpdateType.NONE ) {
 
 				this.updateBeforeNodes.push( node.getSelf() );

+ 56 - 3
src/nodes/utils/ReflectorNode.js

@@ -1,3 +1,4 @@
+import Node from '../core/Node.js';
 import TextureNode from '../accessors/TextureNode.js';
 import { nodeObject } from '../tsl/TSLBase.js';
 import { NodeUpdateType } from '../core/constants.js';
@@ -43,6 +44,57 @@ class ReflectorNode extends TextureNode {
 
 		super( _defaultRT.texture, _defaultUV );
 
+		this._reflectorBaseNode = new ReflectorBaseNode( this, parameters );
+
+		this.setUpdateMatrix( false );
+
+	}
+
+	get reflector() {
+
+		return this._reflectorBaseNode;
+
+	}
+
+	get target() {
+
+		return this._reflectorBaseNode.target;
+
+	}
+
+	setup( builder ) {
+
+		// ignore if used in post-processing
+		if ( ! builder.object.isQuadMesh ) this._reflectorBaseNode.build( builder );
+
+		return super.setup( builder );
+
+	}
+
+	clone() {
+
+		const texture = new this.constructor( this.reflectorNode );
+		texture._reflectorBaseNode = this._reflectorBaseNode;
+
+		return texture;
+
+	}
+
+}
+
+
+class ReflectorBaseNode extends Node {
+
+	static get type() {
+
+		return 'ReflectorBaseNode';
+
+	}
+
+	constructor( textureNode, parameters = {} ) {
+
+		super();
+
 		const {
 			target = new Object3D(),
 			resolution = 1,
@@ -52,6 +104,8 @@ class ReflectorNode extends TextureNode {
 
 		//
 
+		this.textureNode = textureNode;
+
 		this.target = target;
 		this.resolution = resolution;
 		this.generateMipmaps = generateMipmaps;
@@ -62,7 +116,6 @@ class ReflectorNode extends TextureNode {
 		this.virtualCameras = new WeakMap();
 		this.renderTargets = new WeakMap();
 
-
 	}
 
 	_updateResolution( renderTarget, renderer ) {
@@ -124,7 +177,7 @@ class ReflectorNode extends TextureNode {
 
 	updateBefore( frame ) {
 
-		if ( this.bounces === false && _inReflector ) return false;
+		if ( this.bounces === false && _inReflector ) return;
 
 		_inReflector = true;
 
@@ -209,7 +262,7 @@ class ReflectorNode extends TextureNode {
 
 		//
 
-		this.value = renderTarget.texture;
+		this.textureNode.value = renderTarget.texture;
 
 		material.visible = false;
 

粤ICP备19079148号