Const
Defines a named, compile-time constant within the TSL node graph to improve code readability, efficiency, and maintainability.
Core Advantages
Greatly enhances shader readability and maintainability by naming the result of a node calculation and solidifying it as a compile-time constant, which also helps the compiler generate more efficient GLSL code.
Common Uses
Defining mathematical or physical constants (e.g., PI)
Caching the result of a complex but static calculation (e.g., a mixed solid color)
Defining core parameters for a procedural effect (e.g., noise scale)
Creating configuration "switches" or modes for the shader
How to adjust
Adjustment is done by modifying the node value passed to `Const` in the JavaScript code, which takes effect after the material is recompiled. For example, changing a constant used for a circular mask's radius from `Const(float(0.5))` to `Const(float(0.1))` will cause the rendered circle to shrink from half the size to 1/5th of its original size after recompilation.
Code Examples
1// Solidify a complex calculation result into a constant
2const baseColor = Const( mix( color('blue'), color('green'), 0.5 ), 'baseColor' );