string
The string node encapsulates a JavaScript string to be used as a compile-time 'identifier' or 'metadata' within the TSL node graph. It doesn't generate a runtime shader variable but is used to configure other nodes, such as specifying a vertex attribute by name.
Core Advantages
Allows developers to use intuitive, readable names (e.g., 'uv', 'color') to reference shader resources and configure node behavior, which significantly improves code readability and maintainability.
Common Uses
Specify the name of a vertex attribute to read, used with the `attribute()` node.
Define the data type of elements in a storage buffer, such as 'vec3' or 'float'.
Act as a selector in complex nodes to retrieve a specific output, like the 'specular' component from a lighting model.
How to adjust
Adjusting its string value causes a 'switching' or 'breaking' change in shader behavior, not a smooth visual transition. For example, changing 'uv' to 'uv2' switches to a different set of texture coordinates, while providing a non-existent attribute name will cause a compilation error and rendering failure.
Code Examples
1// Use string('noiseStrength') to get a vertex attribute by name
2const noiseValueNode = attribute(string('noiseStrength'));
3// and use it as a color
4material.colorNode = vec3(noiseValueNode);