nodeImmutable
A performance optimization node used to declare a compile-time constant that never changes. It 'bakes' a value directly into the final shader code, eliminating unnecessary uniform variable overhead.
Core Advantages
Extreme performance optimization. It transforms a runtime variable (uniform) into a literal value (e.g., `3.14`) within the shader code, completely removing the GPU's overhead of fetching and reading a uniform at runtime, thus making related calculations as fast as possible.
Common Uses
Defining mathematical or physical constants, such as PI or a fixed Index of Refraction (IOR).
Setting fixed parameters for stylized shaders (like cel-shading), such as the number of color bands.
Hard-coding a fixed color or direction vector to avoid creating a uniform for it.
How to adjust
The value of this node is not adjustable after the material has been compiled. Any adjustment must be made in the JavaScript code before compilation, which will trigger a shader recompile. Attempting to modify its value at runtime will have no effect, in stark contrast to a uniform node which can be updated every frame.
Code Examples
1// 1. Define a fixed, unchangeable number of color bands
2const celBands = nodeImmutable(float(3.0));
3
4// 2. Use the immutable bands to quantize the light intensity
5const celShading = lightIntensity.mul(celBands).ceil().div(celBands);