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

NodeBuilder: More docs. #30038

Merged
merged 2 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 56 additions & 51 deletions src/nodes/core/NodeBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,14 @@ class NodeBuilder {
this.computeShader = null;

/**
* TODO
* Nodes used in the primary flow of code generation.
*
* @type {Object}
* @type {Object<String,Array<Node>>}
*/
this.flowNodes = { vertex: [], fragment: [], compute: [] };

/**
* TODO
* Nodes code from `.flowNodes`.
*
* @type {Object<String,String>}
*/
Expand Down Expand Up @@ -322,34 +322,33 @@ class NodeBuilder {
this.vars = {};

/**
* TODO
* Current code flow.
* All code generated in this stack will be stored in `.flow`.
*
* @type {{code: String}}
*/
this.flow = { code: '' };

/**
* A chain of nodes.
*
* TODO: Explains purpose of this property.
* Used to check recursive calls in node-graph.
*
* @type {Array<Node>}
*/
this.chaining = [];

/**
* The current stack.
*
* TODO: Explains purpose of this property.
* This reflects the current process in the code block hierarchy,
* it is useful to know if the current process is inside a conditional for example.
*
* @type {StackNode}
*/
this.stack = stack();

/**
* List of stack nodes.
*
* TODO: Explains purpose of this property.
* The current stack hierarchy is stored in an array.
*
* @type {Array<StackNode>}
*/
Expand Down Expand Up @@ -580,9 +579,7 @@ class NodeBuilder {
}

/**
* Returns a list bindings.
*
* TODO: Add more details.
* Returns a list bindings of all shader stages separated by groups.
*
* @return {Array<BindGroup>} The list of bindings.
*/
Expand Down Expand Up @@ -679,7 +676,8 @@ class NodeBuilder {
}

/**
* TODO: Describe the difference to `addNode()`.
* It is used to add Nodes that will be used as FRAME and RENDER events,
* and need to follow a certain sequence in the calls to work correctly.
*
* @param {Node} node - The node to add.
*/
Expand Down Expand Up @@ -758,8 +756,7 @@ class NodeBuilder {

/**
* Adds the given node to the internal node chain.
*
* TODO: Describe the difference to `addNode()`.
* This is used to check recursive calls in node-graph.
*
* @param {Node} node - The node to add.
*/
Expand Down Expand Up @@ -822,11 +819,11 @@ class NodeBuilder {
}

/**
* TODO
* Adds the Node to a target flow so that it can generate code in the 'generate' process.
*
* @param {('vertex'|'fragment'|'compute')} shaderStage - The shader stage.
* @param {Node} node - The node.
* @return {Node} The node
* @param {Node} node - The node to add.
* @return {Node} The node.
*/
addFlow( shaderStage, node ) {

Expand Down Expand Up @@ -859,9 +856,10 @@ class NodeBuilder {
}

/**
* TODO
* Gets a context used in shader construction that can be shared across different materials.
* This is necessary since the renderer cache can reuse shaders generated in one material and use them in another.
*
* @return {Object} TODO.
* @return {Object} The builder's current context without material.
*/
getSharedContext() {

Expand Down Expand Up @@ -1686,10 +1684,13 @@ class NodeBuilder {
}

/**
* TODO
* Adds a code flow based on the code-block hierarchy.

* This is used so that code-blocks like If,Else create their variables locally if the Node
* is only used inside one of these conditionals in the current shader stage.
*
* @param {Node} node - TODO.
* @param {Node} nodeBlock - TODO.
* @param {Node} node - The node to add.
* @param {Node} nodeBlock - Node-based code-block. Usually 'ConditionalNode'.
*/
addFlowCodeHierarchy( node, nodeBlock ) {

Expand Down Expand Up @@ -1724,11 +1725,11 @@ class NodeBuilder {
}

/**
* TODO
* Add a inline-code to the current flow code-block.
*
* @param {Node} node - TODO.
* @param {String} code - TODO.
* @param {Node} nodeBlock - TODO.
* @param {Node} node - The node to add.
* @param {String} code - The code to add.
* @param {Node} nodeBlock - Current ConditionalNode
*/
addLineFlowCodeBlock( node, code, nodeBlock ) {

Expand All @@ -1742,10 +1743,10 @@ class NodeBuilder {
}

/**
* TODO
* Add a inline-code to the current flow.
*
* @param {String} code - TODO.
* @param {Node?} [node= null] - TODO.
* @param {String} code - The code to add.
* @param {Node?} [node= null] - Optional Node, can help the system understand if the Node is part of a code-block.
* @return {NodeBuilder} A reference to this node builder.
*/
addLineFlowCode( code, node = null ) {
Expand Down Expand Up @@ -1773,9 +1774,9 @@ class NodeBuilder {
}

/**
* TODO
* Adds a code to the current code flow.
*
* @param {String} code - TODO.
* @param {String} code - Shader code.
* @return {NodeBuilder} A reference to this node builder.
*/
addFlowCode( code ) {
Expand All @@ -1787,7 +1788,8 @@ class NodeBuilder {
}

/**
* TODO
* Add tab in the code that will be generated so that other snippets respect the current tabulation.
* Typically used in codes with If,Else.
*
* @return {NodeBuilder} A reference to this node builder.
*/
Expand All @@ -1800,7 +1802,7 @@ class NodeBuilder {
}

/**
* TODO
* Removes a tab.
*
* @return {NodeBuilder} A reference to this node builder.
*/
Expand All @@ -1813,9 +1815,9 @@ class NodeBuilder {
}

/**
* TODO
* Gets the current flow data based on a Node.
*
* @param {Node} node - TODO.
* @param {Node} node - Node that the flow was started.
* @param {('vertex'|'fragment'|'compute'|'any')} shaderStage - The shader stage.
* @return {Object}
*/
Expand All @@ -1826,9 +1828,9 @@ class NodeBuilder {
}

/**
* TODO
* Executes the node flow based on a root node to generate the final shader code.
*
* @param {Node} node - TODO.
* @param {Node} node - The node to execute.
* @return {Object}
*/
flowNode( node ) {
Expand Down Expand Up @@ -1867,9 +1869,9 @@ class NodeBuilder {
}

/**
* TODO
* Generates a code flow based on a TSL function: Fn().
*
* @param {ShaderNodeInternal} node - TODO.
* @param {ShaderNodeInternal} node - A function code will be generated based on the input.
* @return {Object}
*/
flowShaderNode( shaderNode ) {
Expand Down Expand Up @@ -1911,10 +1913,10 @@ class NodeBuilder {
}

/**
* TODO
* Runs the node flow through all the steps of creation, 'setup', 'analyze', 'generate'.
*
* @param {Node} node - TODO.
* @param {String?} output - TODO.
* @param {Node} node - The node to execute.
* @param {String?} output - Expected output type. For example 'vec3'.
* @return {Object}
*/
flowStagesNode( node, output = null ) {
Expand Down Expand Up @@ -1970,10 +1972,10 @@ class NodeBuilder {
}

/**
* TODO
* Generates a code flow based on a child Node.
*
* @param {Node} node - TODO.
* @param {String?} output - TODO.
* @param {Node} node - The node to execute.
* @param {String?} output - Expected output type. For example 'vec3'.
* @return {Object}
*/
flowChildNode( node, output = null ) {
Expand All @@ -1995,12 +1997,15 @@ class NodeBuilder {
}

/**
* TODO
* Executes a flow of code in a different stage.
*
* Some nodes like `varying()` have the ability to compute code in vertex-stage and
* return the value in fragment-stage even if it is being executed in an input fragment.
*
* @param {('vertex'|'fragment'|'compute'|'any')} shaderStage - The shader stage.
* @param {Node} node - TODO.
* @param {String?} output - TODO.
* @param {String?} propertyName - TODO.
* @param {Node} node - The node to execute.
* @param {String?} output - Expected output type. For example 'vec3'.
* @param {String?} propertyName - The property name to assign the result.
* @return {Object}
*/
flowNodeFromShaderStage( shaderStage, node, output = null, propertyName = null ) {
Expand Down
5 changes: 3 additions & 2 deletions src/nodes/core/StackNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { select } from '../math/ConditionalNode.js';
import { ShaderNode, nodeProxy, getCurrentStack, setCurrentStack } from '../tsl/TSLBase.js';

/**
* TODO
* Stack is a helper for Nodes that need to produce stack-based code instead of continuous flow.
* They are usually needed in cases like `If`, `Else`.
*
* @augments Node
* @augments StackNode
Mugen87 marked this conversation as resolved.
Show resolved Hide resolved
*/
class StackNode extends Node {

Expand Down
Loading