Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TSL: Introduce Node.updateAfter #28552

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
introduce updateNode
  • Loading branch information
RenaudRohlinger committed Jun 4, 2024
commit d50ffffcc0c51ce145e52b2d9fdbd6226f11ba67
13 changes: 13 additions & 0 deletions examples/jsm/nodes/core/Node.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Node extends EventDispatcher {

this.updateType = NodeUpdateType.NONE;
this.updateBeforeType = NodeUpdateType.NONE;
this.updateAfterType = NodeUpdateType.NONE;

this.uuid = MathUtils.generateUUID();

Expand Down Expand Up @@ -165,6 +166,12 @@ class Node extends EventDispatcher {

}

getUpdateAfterType() {

return this.updateAfterType;

}

getElementType( builder ) {

const type = this.getNodeType( builder );
Expand Down Expand Up @@ -273,6 +280,12 @@ class Node extends EventDispatcher {

}

updateAfter( /*frame*/ ) {

console.warn( 'Abstract function.' );

}

update( /*frame*/ ) {

console.warn( 'Abstract function.' );
Expand Down
8 changes: 8 additions & 0 deletions examples/jsm/nodes/core/NodeBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class NodeBuilder {
this.nodes = [];
this.updateNodes = [];
this.updateBeforeNodes = [];
this.updateAfterNodes = [];
this.hashNodes = {};

this.lightsNode = null;
Expand Down Expand Up @@ -215,6 +216,7 @@ class NodeBuilder {

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

if ( updateType !== NodeUpdateType.NONE ) {

Expand All @@ -228,6 +230,12 @@ class NodeBuilder {

}

if ( updateAfterType !== NodeUpdateType.NONE ) {

this.updateAfterNodes.push( node );

}

}

}
Expand Down
42 changes: 42 additions & 0 deletions examples/jsm/nodes/core/NodeFrame.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class NodeFrame {

this.updateMap = new WeakMap();
this.updateBeforeMap = new WeakMap();
this.updateAfterMap = new WeakMap();

this.renderer = null;
this.material = null;
Expand Down Expand Up @@ -83,6 +84,47 @@ class NodeFrame {

}

updateAfterNode( node ) {

const updateType = node.getUpdateAfterType();
const reference = node.updateReference( this );

if ( updateType === NodeUpdateType.FRAME ) {

const { frameMap } = this._getMaps( this.updateAfterMap, reference );

if ( frameMap.get( reference ) !== this.frameId ) {

if ( node.updateAfter( this ) !== false ) {

frameMap.set( reference, this.frameId );

}

}

} else if ( updateType === NodeUpdateType.RENDER ) {

const { renderMap } = this._getMaps( this.updateAfterMap, reference );

if ( renderMap.get( reference ) !== this.renderId ) {

if ( node.updateAfter( this ) !== false ) {

renderMap.set( reference, this.renderId );

}

}

} else if ( updateType === NodeUpdateType.OBJECT ) {

node.updateAfter( this );

}

}

updateNode( node ) {

const updateType = node.getUpdateType();
Expand Down
6 changes: 6 additions & 0 deletions examples/jsm/renderers/common/Renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,8 @@ class Renderer {

this.backend.draw( renderObject, this.info );

this._nodes.updateAfter( renderObject );

}

}
Expand Down Expand Up @@ -1527,6 +1529,8 @@ class Renderer {

}

this._nodes.updateAfter( renderObject );

}

_createObjectPipeline( object, material, scene, camera, lightsNode, passId ) {
Expand All @@ -1545,6 +1549,8 @@ class Renderer {

this._pipelines.getForRender( renderObject, this._compilationPromises );

this._nodes.updateAfter( renderObject );

}

get compute() {
Expand Down
3 changes: 2 additions & 1 deletion examples/jsm/renderers/common/nodes/NodeBuilderState.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class NodeBuilderState {

constructor( vertexShader, fragmentShader, computeShader, nodeAttributes, bindings, updateNodes, updateBeforeNodes, transforms = [] ) {
constructor( vertexShader, fragmentShader, computeShader, nodeAttributes, bindings, updateNodes, updateBeforeNodes, updateAfterNodes, transforms = [] ) {

this.vertexShader = vertexShader;
this.fragmentShader = fragmentShader;
Expand All @@ -12,6 +12,7 @@ class NodeBuilderState {

this.updateNodes = updateNodes;
this.updateBeforeNodes = updateBeforeNodes;
this.updateAfterNodes = updateAfterNodes;

this.usedTimes = 0;

Expand Down
14 changes: 14 additions & 0 deletions examples/jsm/renderers/common/nodes/Nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ class Nodes extends DataMap {
nodeBuilder.getBindings(),
nodeBuilder.updateNodes,
nodeBuilder.updateBeforeNodes,
nodeBuilder.updateAfterNodes,
nodeBuilder.transforms
);

Expand Down Expand Up @@ -427,6 +428,19 @@ class Nodes extends DataMap {

}

updateAfter( renderObject ) {

const nodeFrame = this.getNodeFrameForRender( renderObject );
const nodeBuilder = renderObject.getNodeBuilderState();

for ( const node of nodeBuilder.updateAfterNodes ) {

nodeFrame.updateAfterNode( node );

}

}

updateForCompute( computeNode ) {

const nodeFrame = this.getNodeFrame();
Expand Down