File: NodeBuilder.md | Updated: 11/15/2025
Base class for builders which generate a shader program based on a 3D object and its node material definition.
Constructs a new node builder.
object | The 3D object.
---|---
renderer | The current renderer.
parser | A reference to a node parser.
The active stack nodes.
This array holds the node attributes of this builder created via AttributeNode.
Reference to the array of bind groups.
This dictionary holds the bindings for each shader stage.
This dictionary maintains the binding indices per bind group.
This array holds the node attributes of this builder created via BufferAttributeNode.
The current build stage.
The builder's cache.
The camera the 3D object is rendered with.
Default is null.
A chain of nodes. Used to check recursive calls in node-graph.
The current clipping context.
This dictionary holds the (native) node codes of this builder. The codes are maintained in an array for each shader stage.
The generated compute shader.
The builder's context.
Reference to the current function node.
Default is null.
A reference the current node which is the last node in the chain of nodes.
This dictionary holds the declarations for each shader stage.
A reference to the current environment node.
Default is null.
Current code flow. All code generated in this stack will be stored in .flow.
Nodes code from .flowNodes.
Nodes used in the primary flow of code generation.
The current TSL function(Fn) call node.
Default is null.
A reference to the current fog node.
Default is null.
The generated fragment shader.
The geometry of the 3D object.
Since the NodeBuilder#cache might be temporarily overwritten by other caches, this member retains the reference to the builder's own cache.
Default is this.cache.
A dictionary that assigns each node to a unique hash.
A reference to the current lights node.
Default is null.
The material of the 3D object.
A list of all nodes the builder is processing for this 3D object.
The 3D object.
A reference to a node material observer.
Default is null.
A reference to a node parser.
The current renderer.
The scene the 3D object belongs to.
Default is null.
A list of all sequential nodes.
The current shader stage.
The current stack. 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.
List of stack nodes. The current stack hierarchy is stored in an array.
This dictionary holds the output structs of the builder. The structs are maintained in an array for each shader stage.
Returns the current sub-build layer.
The current sub-build TSL function(Fn).
Default is null.
The sub-build layers.
Default is [].
A tab value. Used for shader string generation.
Default is '\t'.
This dictionary holds the types of the builder.
This dictionary holds the node uniforms of the builder. The uniforms are maintained in an array for each shader stage.
A list of all nodes which Node#updateAfter method should be executed.
A list of all nodes which Node#updateBefore method should be executed.
A list of all nodes which Node#update method should be executed.
This dictionary holds the node variables of this builder. The variables are maintained in an array for each shader stage. This dictionary is also used to count the number of variables according to their type (const, vars).
This array holds the node varyings of this builder.
The generated vertex shader.
Adds the given node to the internal node chain. This is used to check recursive calls in node-graph.
node | The node to add.
---|---
Adds context data to the builder's current context.
context | The context to add.
---|---
Returns: The previous context.
Adds the Node to a target flow so that it can generate code in the 'generate' process.
shaderStage | The shader stage.
---|---
node | The node to add.
Returns: The node.
Adds a code to the current code flow.
code | Shader code.
---|---
Returns: A reference to this node builder.
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.
node | The node to add.
---|---
nodeBlock | Node-based code-block. Usually 'ConditionalNode'.
Add tab in the code that will be generated so that other snippets respect the current tabulation. Typically used in codes with If,Else.
Returns: A reference to this node builder.
Includes a node in the current function node.
node | The node to include.
---|---
Add a inline-code to the current flow.
code | The code to add.
---|---
node | Optional Node, can help the system understand if the Node is part of a code-block. Default is null.
Returns: A reference to this node builder.
Add a inline-code to the current flow code-block.
node | The node to add.
---|---
code | The code to add.
nodeBlock | Current ConditionalNode
Adds a node to this builder.
node | The node to add.
---|---
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. This function should be called after 'setup()' in the 'build()' process to ensure that the child nodes are processed first.
node | The node to add.
---|---
Adds a stack node to the internal stack.
Returns: The added stack node.
Adds a sub-build layer to the node builder.
subBuild | The sub-build layer to add.
---|---
Central build method which controls the build for the given object.
Returns: A reference to this node builder.
Controls the code build of the shader stages.
Builds the given shader node.
shaderNode | The shader node.
---|---
Returns: The function code.
Returns the native shader operator name for a given generic name. It is a similar type of method like NodeBuilder#getMethod.
shaderNode | The shader node to build the function node with.
---|---
Returns: The build function node.
Checks the update types of nodes
For a given type this method changes the component type to the given value. E.g. vec4 should be changed to the new component type uint which results in uvec4.
type | The type.
---|---
newComponentType | The new component type.
Returns: The new type.
Factory method for creating an instance of CubeRenderTarget with the given dimensions and options.
size | The size of the cube render target.
---|---
options | The options of the cube render target.
Returns: The cube render target.
Factory method for creating an instance of RenderTarget with the given dimensions and options.
width | The width of the render target.
---|---
height | The height of the render target.
options | The options of the render target.
Returns: The render target.
Executes the node in a specific build stage.
This function can be used to arbitrarily execute the specified build stage outside of the standard build process. For instance, if a node's type depends on properties created by the 'setup' stage, then flowBuildStage(node, 'setup') can be used to execute the setup build stage and access its generated nodes before the standard build process begins.
node | The node to execute.
---|---
buildStage | The build stage to execute the node in.
output | Expected output type. For example 'vec3'. Default is null.
Returns: The result of the node build.
Generates a code flow based on a child Node.
node | The node to execute.
---|---
output | Expected output type. For example 'vec3'. Default is null.
Returns: The code flow.
Executes the node flow based on a root node to generate the final shader code.
node | The node to execute.
---|---
Returns: The code flow.
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.
shaderStage | The shader stage.
---|---
node | The node to execute.
output | Expected output type. For example 'vec3'. Default is null.
propertyName | The property name to assign the result. Default is null.
Returns: The code flow or node.build() result.
Generates a code flow based on a TSL function: Fn().
shaderNode | A function code will be generated based on the input.
---|---
Runs the node flow through all the steps of creation, 'setup', 'analyze', 'generate'.
node | The node to execute.
---|---
output | Expected output type. For example 'vec3'. Default is null.
Formats the given shader snippet from a given type into another one. E.g. this method might be used to convert a simple float string "1.0" into a vec3 representation: "vec3<f32>( 1.0 )".
snippet | The shader snippet.
---|---
fromType | The source type.
toType | The target type.
Returns: The updated shader string.
Generates the array shader string for the given type and value.
type | The type.
---|---
count | The count.
values | The default values. Default is null.
Returns: The generated value as a shader string.
Generates the array declaration string.
type | The type.
---|---
count | The count.
Returns: The generated value as a shader string.
Generates the shader string for the given type and value.
type | The type.
---|---
value | The value. Default is null.
Returns: The generated value as a shader string.
Generates the struct shader string.
type | The type.
---|---
membersLayout | The count.
values | The default values. Default is null.
Returns: The generated value as a shader string.
Generates a texture sample shader string for the given texture data.
texture | The texture.
---|---
textureProperty | The texture property name.
uvSnippet | Snippet defining the texture coordinates.
Returns: The generated shader string.
Generates a texture LOD shader string for the given texture data.
texture | The texture.
---|---
textureProperty | The texture property name.
uvSnippet | Snippet defining the texture coordinates.
depthSnippet | Snippet defining the 0-based texture array index to sample.
levelSnippet | Snippet defining the mip level.
Returns: The generated shader string.
Returns the active stack.
Returns: The active stack.
Returns a node attribute for the given name and type.
name | The attribute's name.
---|---
type | The attribute's type.
Returns: The node attribute.
Returns the attribute definitions as a shader string for the given shader stage.
shaderStage | The shader stage.
---|---
Returns: The attribute code section.
Returns an array holding all node attributes of this node builder.
Returns: The node attributes of this builder.
Returns the base stack.
Returns: The base stack.
Returns an array of node uniform groups for the given group name and shader stage.
groupName | The group name.
---|---
shaderStage | The shader stage.
Returns: The array of node uniform groups.
Returns the bind groups of the current renderer.
Returns: The cache.
Returns a list bindings of all shader stages separated by groups.
Returns: The list of bindings.
Returns an instance of NodeAttribute for the given buffer attribute node.
node | The buffer attribute node.
---|---
type | The node type.
Returns: The node attribute.
Returns the current build stage.
Returns: The current build stage.
Returns the builder's current cache.
Returns: The builder's current cache.
Returns a cache for the given node.
node | The node.
---|---
parent | Whether this node refers to a shared parent cache or not. Default is true.
Returns: The cache.
Returns the closest sub-build layer for the given data.
data | The data to get the closest sub-build layer from.
---|---
Returns: The closest sub-build name or null if none found.
Returns an instance of NodeCode for the given code node.
node | The code node.
---|---
type | The node type.
shaderStage | The shader stage. Default is this.shaderStage.
Returns: The node code.
Returns the native code definitions as a shader string for the given shader stage.
shaderStage | The shader stage.
---|---
Returns: The native code section.
Returns the component type for a given type.
type | The type.
---|---
Returns: The component type.
Returns the component type of a given texture.
texture | The texture.
---|---
Returns: The component type.
Returns the builder's current context.
Returns: The builder's current context.
The builder maintains (cached) data for each node during the building process. This method can be used to get these data for a specific shader stage and cache.
node | The node to get the data for.
---|---
shaderStage | The shader stage. Default is this.shaderStage.
cache | An optional cache. Default is null.
Returns: The node data.
Returns the drawIndex input variable as a native shader string. Only relevant for WebGL and its WEBGL_multi_draw extension.
Returns: The drawIndex shader string.
Returns the element type for a given type.
type | The type.
---|---
Returns: The element type.
Gets the current flow data based on a Node.
node | Node that the flow was started.
---|---
shaderStage | The shader stage.
Returns: The flow data.
Returns the fragCoord input variable as a native shader string.
Returns: The fragCoord shader string.
Returns the frontFacing input variable as a native shader string.
Returns: The frontFacing shader string.
Returns the native shader operator name for a given generic name. It is a similar type of method like NodeBuilder#getMethod.
op | The operator name to resolve.
---|---
Returns: The resolved operator name.
Returns the hash of this node builder.
Returns: The hash.
Contextually returns either the vertex stage instance index builtin or the linearized index of an compute invocation within a grid of workgroups.
Returns: The instanceIndex shader string.
Returns the integer type pendant for the given type.
type | The type.
---|---
Returns: The integer type.
Returns the native shader method name for a given generic name. E.g. the method name textureDimensions matches the WGSL name but must be resolved to textureSize in GLSL.
method | The method name to resolve.
---|---
Returns: The resolved method name.
Returns a node for the given hash, see NodeBuilder#setHashNode.
hash | The hash of the node.
---|---
Returns: The found node.
Returns the properties for the given node and shader stage.
Properties are typically used within a build stage to reference a node's child node or nodes manually assigned to the properties in a separate build stage. A typical usage pattern for defining nodes manually would be assigning dependency nodes to the current node's properties in the setup stage and building those properties in the generate stage.
node | The node to get the properties for.
---|---
shaderStage | The shader stage. Default is 'any'.
Returns: The node properties.
Returns a uniform representation which is later used for UBO generation and rendering.
uniformNode | The uniform node.
---|---
type | The requested type.
Returns: The uniform.
Returns the output struct name which is required by OutputStructNode.
Returns: The name of the output struct.
Returns an instance of StructType for the given output struct node.
node | The output struct node.
---|---
membersLayout | The output struct types.
Returns: The struct type attribute.
Returns for the given node and shader stage the property name for the shader.
node | The node.
---|---
shaderStage | The shader stage.
Returns: The property name.
Returns the current shader stage.
Returns: The current shader stage.
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.
Returns: The builder's current context without material.
Returns a signature with the engine's current revision.
Returns: The signature.
Returns an instance of StructType for the given output struct node.
node | The output struct node.
---|---
membersLayout | The output struct types.
name | The name of the struct. Default is null.
shaderStage | The shader stage. Default is this.shaderStage.
Returns: The struct type attribute.
Returns an instance of StructType for the given struct name and shader stage or null if not found.
name | The name of the struct.
---|---
shaderStage | The shader stage. Default is this.shaderStage.
Returns: The struct type or null if not found.
Returns the output node of a sub-build layer.
node | The node to get the output from.
---|---
Returns: The output node name.
Returns the sub-build property name for the given property and node.
property | The property name. Default is ''.
---|---
node | The node to get the sub-build from. Default is null.
Returns: The sub-build property name.
Returns the native snippet for a ternary operation. E.g. GLSL would output a ternary op as cond ? x : y whereas WGSL would output it as select(y, x, cond)
condSnippet | The condition determining which expression gets resolved.
---|---
ifSnippet | The expression to resolve to if the condition is true.
elseSnippet | The expression to resolve to if the condition is false.
Returns: The resolved method name.
It might be necessary to convert certain data types to different ones so this method can be used to hide the conversion.
type | The type.
---|---
Returns: The updated type.
Returns the type for a given typed array.
array | The typed array.
---|---
Returns: The type.
Returns the type for a given buffer attribute.
attribute | The buffer attribute.
---|---
Returns: The type.
Returns the data type for the given the length and component type.
length | The length.
---|---
componentType | The component type. Default is 'float'.
Returns: The type.
Returns the length for the given data type.
type | The data type.
---|---
Returns: The length.
Returns an instance of NodeUniform for the given uniform node.
node | The uniform node.
---|---
type | The uniform type.
shaderStage | The shader stage. Default is this.shaderStage.
name | The name of the uniform. Default is null.
Returns: The node uniform.
Returns the uniform definitions as a shader string for the given shader stage.
shaderStage | The shader stage.
---|---
Returns: The uniform code section.
Returns a single variable definition as a shader string for the given variable type and name.
type | The variable's type.
---|---
name | The variable's name.
count | The array length. Default is null.
Returns: The shader string.
Returns an instance of NodeVar for the given variable node.
node | The variable node.
---|---
name | The variable's name. Default is null.
type | The variable's type. Default is node.getNodeType( this ).
shaderStage | The shader stage. Default is this.shaderStage.
readOnly | Whether the variable is read-only or not. Default is false.
Returns: The node variable.
Returns the variable definitions as a shader string for the given shader stage.
shaderStage | The shader stage.
---|---
Returns: The variable code section.
Returns an instance of NodeVarying for the given varying node.
node | The varying node.
---|---
name | The varying's name. Default is null.
type | The varying's type. Default is node.getNodeType( this ).
interpolationType | The interpolation type of the varying. Default is null.
interpolationSampling | The interpolation sampling type of the varying. Default is null.
Returns: The node varying.
Returns the varying definitions as a shader string for the given shader stage.
shaderStage | The shader stage.
---|---
Returns: The varying code section.
Returns the vector type for a given matrix type.
type | The matrix type.
---|---
Returns: The vector type.
Returns the vector type for a given type.
type | The type.
---|---
Returns: The vector type.
Returns the vertexIndex input variable as a native shader string.
Returns: The instanceIndex shader string.
Whether the given attribute name is defined in the geometry or not.
name | The attribute name.
---|---
Returns: Whether the given attribute name is defined in the geometry.
Whether the given node is included in the internal array of nodes or not.
node | The node to test.
---|---
Returns: Whether the given node is included in the internal array of nodes or not.
Calling this method increases the usage count for the given node by one.
node | The node to increase the usage count for.
---|---
Returns: The updated usage count.
Whether the requested feature is available or not.
name | The requested feature.
---|---
Returns: Whether the requested feature is supported or not.
Returns whether a Node or its flow is deterministic, useful for use in const.
node | The varying node.
---|---
Returns: Returns true if deterministic.
Whether the given texture is filtered or not.
texture | The texture to check.
---|---
Returns: Whether the given texture is filtered or not.
Whether to flip texture data along its vertical axis or not. WebGL needs this method evaluate to true, WebGPU to false.
Returns: Whether to flip texture data along its vertical axis or not.
Returns the type is an integer type.
type | The type.
---|---
Returns: Whether the type is an integer type or not.
Whether the given type is a matrix type or not.
type | The type to check.
---|---
Returns: Whether the given type is a matrix type or not.
Whether the material is opaque or not.
Returns: Whether the material is opaque or not.
Whether the given type is a reference type or not.
type | The type to check.
---|---
Returns: Whether the given type is a reference type or not.
Whether the given type is a vector type or not.
type | The type to check.
---|---
Returns: Whether the given type is a vector type or not.
Checks if the given texture requires a manual conversion to the working color space.
texture | The texture to check.
---|---
Returns: Whether the given texture requires a conversion to working color space or not.
Registers a node declaration in the current shader stage.
node | The node to be registered.
---|---
Removes the active stack from the internal stack.
stack | The stack node to remove.
---|---
Removes the given node from the internal node chain.
node | The node to remove.
---|---
Removes a tab.
Returns: A reference to this node builder.
Removes the last stack node from the internal stack.
Returns: The removed stack node.
Removes the last sub-build layer from the node builder.
Returns: The removed sub-build layer.
Adds an active stack to the internal stack.
stack | The stack node to add.
---|---
Sets the current build stage.
buildStage | The build stage to set.
---|---
Sets builder's cache.
cache | The cache to set.
---|---
Sets builder's context.
context | The context to set.
---|---
The builder maintains each node in a hash-based dictionary. This method sets the given node (value) with the given hash (key) into this dictionary.
node | The node to add.
---|---
hash | The hash of the node.
Sets the current shader stage.
shaderStage | The shader stage to set.
---|---
Sorts the bind groups and updates NodeBuilder#bindingsIndexes.