Inheritance: NodeBuilder →
A node builder targeting WGSL.
This module generates WGSL shader code from node materials and also generates the respective bindings and vertex buffer definitions. These data are later used by the renderer to create render and compute pipelines for render objects.
Constructs a new WGSL node builder renderer.
object
The 3D object.
renderer
The renderer.
A dictionary that holds for each shader stage a Map of builtins.
A dictionary that holds for each shader stage a Set of directives.
A map for managing scope arrays. Only relevant for when using WorkgroupInfoNode in context of compute shaders.
A dictionary that holds for each shader stage ('vertex', 'fragment', 'compute') another dictionary which manages UBOs per group ('render','frame','object').
A dictionary that holds the assigned binding indices for each uniform group. This ensures the same binding index is used across all shader stages.
Controls the code build of the shader stages.
Overrides: NodeBuilder#buildCode
Builds the given shader node.
shaderNode
The shader node.
Overrides: NodeBuilder#buildFunctionCode
Returns: The WGSL function code.
Enables the 'clip_distances' directive.
Enables the given directive for the given shader stage.
name
The directive name.
shaderStage
The shader stage to enable the directive for.
Default is this.shaderStage.
Enables the 'dual_source_blending' directive.
Enables hardware clipping.
planeCount
The clipping plane count.
Enables the 'f16' directive.
Enables the 'subgroups' directive.
Enables the 'subgroups-f16' directive.
Generates the array declaration string.
type
The type.
count
The count.
Overrides: NodeBuilder#generateArrayDeclaration
Returns: The generated value as a shader string.
Generates the WGSL snippet for a manual filtered texture.
texture
The texture.
textureProperty
The name of the texture uniform in the shader.
uvSnippet
A WGSL snippet that represents texture coordinates used for sampling.
offsetSnippet
A WGSL snippet that represents the offset that will be applied to the unnormalized texture coordinate before sampling the texture.
levelSnippet
A WGSL snippet that represents the mip level, with level 0 containing a full size version of the texture.
Default is '0u'.
Returns: The WGSL snippet.
Generates the WGSL snippet for sampling/loading the given texture.
texture
The texture.
textureProperty
The name of the texture uniform in the shader.
uvSnippet
A WGSL snippet that represents texture coordinates used for sampling.
depthSnippet
A WGSL snippet that represents 0-based texture array index to sample.
offsetSnippet
A WGSL snippet that represents the offset that will be applied to the unnormalized texture coordinate before sampling the texture.
shaderStage
The shader stage this code snippet is generated for.
Default is this.shaderStage.
Overrides: NodeBuilder#generateTexture
Returns: The WGSL snippet.
Generates the WGSL snippet when sampling textures with a bias to the mip level.
texture
The texture.
textureProperty
The name of the texture uniform in the shader.
uvSnippet
A WGSL snippet that represents texture coordinates used for sampling.
biasSnippet
A WGSL snippet that represents the bias to apply to the mip level before sampling.
depthSnippet
A WGSL snippet that represents 0-based texture array index to sample.
offsetSnippet
A WGSL snippet that represents the offset that will be applied to the unnormalized texture coordinate before sampling the texture.
shaderStage
The shader stage this code snippet is generated for.
Default is this.shaderStage.
Returns: The WGSL snippet.
Generates the WGSL snippet for sampling a depth texture and comparing the sampled depth values against a reference value.
texture
The texture.
textureProperty
The name of the texture uniform in the shader.
uvSnippet
A WGSL snippet that represents texture coordinates used for sampling.
compareSnippet
A WGSL snippet that represents the reference value.
depthSnippet
A WGSL snippet that represents 0-based texture array index to sample.
offsetSnippet
A WGSL snippet that represents the offset that will be applied to the unnormalized texture coordinate before sampling the texture.
shaderStage
The shader stage this code snippet is generated for.
Default is this.shaderStage.
Returns: The WGSL snippet.
Generates a WGSL variable that holds the texture dimension of the given texture. It also returns information about the number of layers (elements) of an arrayed texture as well as the cube face count of cube textures.
texture
The texture to generate the function for.
textureProperty
The name of the video texture uniform in the shader.
levelSnippet
A WGSL snippet that represents the mip level, with level 0 containing a full size version of the texture.
Returns: The name of the dimension variable.
Generates the WGSL snippet for sampling/loading the given texture using explicit gradients.
texture
The texture.
textureProperty
The name of the texture uniform in the shader.
uvSnippet
A WGSL snippet that represents texture coordinates used for sampling.
gradSnippet
An array holding both gradient WGSL snippets.
depthSnippet
A WGSL snippet that represents 0-based texture array index to sample.
offsetSnippet
A WGSL snippet that represents the offset that will be applied to the unnormalized texture coordinate before sampling the texture.
shaderStage
The shader stage this code snippet is generated for.
Default is this.shaderStage.
Returns: The WGSL snippet.
Generates the WGSL snippet when sampling textures with explicit mip level.
texture
The texture.
textureProperty
The name of the texture uniform in the shader.
uvSnippet
A WGSL snippet that represents texture coordinates used for sampling.
levelSnippet
A WGSL snippet that represents the mip level, with level 0 containing a full size version of the texture.
depthSnippet
A WGSL snippet that represents 0-based texture array index to sample.
offsetSnippet
A WGSL snippet that represents the offset that will be applied to the unnormalized texture coordinate before sampling the texture.
shaderStage
The shader stage this code snippet is generated for.
Default is this.shaderStage.
Returns: The WGSL snippet.
Generates the WGSL snippet that reads a single texel from a texture without sampling or filtering.
texture
The texture.
textureProperty
The name of the texture uniform in the shader.
uvIndexSnippet
A WGSL snippet that represents texture coordinates used for sampling.
levelSnippet
A WGSL snippet that represents the mip level, with level 0 containing a full size version of the texture.
depthSnippet
A WGSL snippet that represents 0-based texture array index to sample.
offsetSnippet
A WGSL snippet that represents the offset that will be applied to the unnormalized texture coordinate before sampling the texture.
Returns: The WGSL snippet.
Generates the WGSL snippet for a texture lookup with explicit level-of-detail. Since it's a lookup, no sampling or filtering is applied.
texture
The texture.
textureProperty
The name of the texture uniform in the shader.
uvSnippet
A WGSL snippet that represents texture coordinates used for sampling.
depthSnippet
A WGSL snippet that represents 0-based texture array index to sample.
offsetSnippet
A WGSL snippet that represents the offset that will be applied to the unnormalized texture coordinate before sampling the texture.
levelSnippet
A WGSL snippet that represents the mip level, with level 0 containing a full size version of the texture.
Default is '0u'.
Overrides: NodeBuilder#generateTextureLod
Returns: The WGSL snippet.
Generates the WGSL snippet that writes a single texel to a texture.
texture
The texture.
textureProperty
The name of the texture uniform in the shader.
uvIndexSnippet
A WGSL snippet that represents texture coordinates used for sampling.
depthSnippet
A WGSL snippet that represents 0-based texture array index to sample.
valueSnippet
A WGSL snippet that represent the new texel value.
Returns: The WGSL snippet.
Generates a wrap function used in context of textures.
texture
The texture to generate the function for.
Returns: The name of the generated function.
Returns the shader attributes of the given shader stage as a WGSL string.
shaderStage
The shader stage.
Overrides: NodeBuilder#getAttributes
Returns: The WGSL snippet that defines the shader attributes.
Returns the bitcast method name for a given input and outputType.
type
The output type to bitcast to.
Returns: The resolved WGSL bitcast invocation.
This method should be used whenever builtins are required in nodes. The internal builtins data structure will make sure builtins are defined in the WGSL source.
name
The builtin name.
property
The property name.
type
The node data type.
shaderStage
The shader stage this code snippet is generated for.
Default is this.shaderStage.
Returns: The property name.
Returns the builtins of the given shader stage as a WGSL string.
shaderStage
The shader stage.
Returns: A WGSL snippet that represents the builtins of the given stage.
Returns the clip distances builtin.
Returns: The clip distances builtin.
Returns the directives of the given shader stage as a WGSL string.
shaderStage
The shader stage.
Returns: A WGSL snippet that enables the directives of the given stage.
Overwritten as a NOP since this method is intended for the WebGL 2 backend.
Overrides: NodeBuilder#getDrawIndex
Returns: Null.
Returns the float packing method name for a given numeric encoding.
encoding
The numeric encoding that describes how the float values are mapped to the integer range.
Returns: The resolve WGSL float packing method name.
Returns the float unpacking method name for a given numeric encoding.
encoding
The numeric encoding that describes how the integer values are mapped to the float range.
Returns: The resolve WGSL float unpacking method name.
Returns the frag coord builtin.
Overrides: NodeBuilder#getFragCoord
Returns: The frag coord builtin.
Returns the frag depth builtin.
Returns: The frag depth builtin.
Returns the front facing builtin.
Overrides: NodeBuilder#getFrontFacing
Returns: The front facing builtin.
Returns the native shader operator name for a given generic name.
op
The operator name to resolve.
Overrides: NodeBuilder#getFunctionOperator
Returns: The resolved operator name.
Contextually returns either the vertex stage instance index builtin or the linearized index of an compute invocation within a grid of workgroups.
Overrides: NodeBuilder#getInstanceIndex
Returns: The instance index.
Returns a builtin representing the index of a compute invocation within the scope of a workgroup load.
Returns: The invocation local index.
Returns a builtin representing the index of a compute invocation within the scope of a subgroup.
Returns: The invocation subgroup index.
Returns the native shader method name for a given generic name.
method
The method name to resolve.
output
An optional output.
Default is null.
Overrides: NodeBuilder#getMethod
Returns: The resolved WGSL method name.
Returns the node access for the given node and shader stage.
node
The storage node.
shaderStage
The shader stage.
Returns: The node access.
Returns the output struct name.
Overrides: NodeBuilder#getOutputStructName
Returns: The name of the output struct.
Returns a WGSL snippet that represents the property name of the given node.
node
The node.
shaderStage
The shader stage this code snippet is generated for.
Default is this.shaderStage.
Overrides: NodeBuilder#getPropertyName
Returns: The property name.
This method should be used when a new scoped buffer is used in context of compute shaders. It adds the array to the internal data structure which is later used to generate the respective WGSL.
name
The array name.
scope
The scope.
bufferType
The buffer type.
bufferCount
The buffer count.
Returns: The array name.
Returns the scoped arrays of the given shader stage as a WGSL string.
shaderStage
The shader stage.
Returns: The WGSL snippet that defines the scoped arrays. Returns undefined when used in the vertex or fragment stage.
Returns A WGSL snippet representing the storage access.
node
The storage node.
shaderStage
The shader stage.
Returns: The WGSL snippet representing the storage access.
Returns the members of the given struct type node as a WGSL string.
struct
The struct type node.
Returns: The WGSL snippet that defines the struct members.
Returns the structs of the given shader stage as a WGSL string.
shaderStage
The shader stage.
Returns: The WGSL snippet that defines the structs.
Returns a builtin representing the index of a compute invocation's subgroup within its workgroup.
Returns: The subgroup index.
Returns a builtin representing the size of a subgroup within the current shader.
Returns: The subgroup size.
Returns the native snippet for a ternary operation.
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.
Overrides: NodeBuilder#getTernary
Returns: The resolved method name.
Returns the WGSL type of the given node data type.
type
The node data type.
Overrides: NodeBuilder#getType
Returns: The WGSL type.
Returns the maximum uniform buffer size limit.
Overrides: NodeBuilder#getUniformBufferLimit
Returns: The maximum uniform buffer size in bytes.
This method is one of the more important ones since it's responsible for generating a matching binding instance for the given uniform node.
These bindings are later used in the renderer to create bind groups and layouts.
node
The uniform node.
type
The node data type.
shaderStage
The shader stage.
name
An optional uniform name.
Default is null.
Overrides: NodeBuilder#getUniformFromNode
Returns: The node uniform object.
Returns the uniforms of the given shader stage as a WGSL string.
shaderStage
The shader stage.
Overrides: NodeBuilder#getUniforms
Returns: The WGSL snippet that defines the uniforms.
Returns a WGSL string representing a variable.
type
The variable's type.
name
The variable's name.
count
The array length.
Default is null.
Overrides: NodeBuilder#getVar
Returns: The WGSL snippet that defines a variable.
Returns the variables of the given shader stage as a WGSL string.
shaderStage
The shader stage.
Overrides: NodeBuilder#getVars
Returns: The WGSL snippet that defines the variables.
Returns the varyings of the given shader stage as a WGSL string.
shaderStage
The shader stage.
Overrides: NodeBuilder#getVaryings
Returns: The WGSL snippet that defines the varyings.
Returns the vertex index builtin.
Overrides: NodeBuilder#getVertexIndex
Returns: The vertex index.
Returns true if the given builtin is defined in the given shader stage.
name
The builtin name.
shaderStage
The shader stage this code snippet is generated for.
Default is this.shaderStage.
Returns: Whether the given builtin is defined in the given shader stage or not.
Whether the requested feature is available or not.
name
The requested feature.
Overrides: NodeBuilder#isAvailable
Returns: Whether the requested feature is supported or not.
Whether to flip texture data along its vertical axis or not.
Overrides: NodeBuilder#isFlipY
Returns: Returns always false in context of WGSL.
Returns true if the sampled values of the given texture should be compared against a reference value.
texture
The texture.
Returns: Whether the sampled values of the given texture should be compared against a reference value or not.
Returns true if the given texture is unfilterable.
texture
The texture.
Returns: Whether the given texture is unfilterable or not.