Skip to content

Commit

Permalink
Nodes: Fixes and improvements for reflector and gaussianBlur (#29619
Browse files Browse the repository at this point in the history
)

* GaussianBlurNode: preserves input UV

* fix sequential events of update before

* add multi-sampler support
  • Loading branch information
sunag authored Oct 11, 2024
1 parent 36bac08 commit 0e584a2
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 5 deletions.
1 change: 1 addition & 0 deletions examples/jsm/tsl/display/GaussianBlurNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions src/nodes/core/Node.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ class Node extends EventDispatcher {
}

builder.removeChain( this );
builder.addSequentialNode( this );

return result;

Expand Down
20 changes: 18 additions & 2 deletions src/nodes/core/NodeBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class NodeBuilder {
this.camera = null;

this.nodes = [];
this.sequentialNodes = [];
this.updateNodes = [];
this.updateBeforeNodes = [];
this.updateAfterNodes = [];
Expand Down Expand Up @@ -320,20 +321,35 @@ 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 ) {

this.updateNodes.push( node.getSelf() );

}

}

for ( const node of this.sequentialNodes ) {

const updateBeforeType = node.getUpdateBeforeType();
const updateAfterType = node.getUpdateAfterType();

if ( updateBeforeType !== NodeUpdateType.NONE ) {

this.updateBeforeNodes.push( node.getSelf() );
Expand Down
59 changes: 56 additions & 3 deletions src/nodes/utils/ReflectorNode.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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,
Expand All @@ -52,6 +104,8 @@ class ReflectorNode extends TextureNode {

//

this.textureNode = textureNode;

this.target = target;
this.resolution = resolution;
this.generateMipmaps = generateMipmaps;
Expand All @@ -62,7 +116,6 @@ class ReflectorNode extends TextureNode {
this.virtualCameras = new WeakMap();
this.renderTargets = new WeakMap();


}

_updateResolution( renderTarget, renderer ) {
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -209,7 +262,7 @@ class ReflectorNode extends TextureNode {

//

this.value = renderTarget.texture;
this.textureNode.value = renderTarget.texture;

material.visible = false;

Expand Down

0 comments on commit 0e584a2

Please sign in to comment.