VarIntent
Explicitly declares the intent to create a variable. Similar to Var, but it forces a local variable to be created in the generated shader, even if the optimizer would inline it. Effective only inside the TSL execution stack of Fn(); if called outside the stack (no current stack), it returns the input node unchanged.
Core Advantages
Reliably produces a named temporary, fixes evaluation order, avoids redundant computation, and improves readability and debuggability; makes it easy to locate the value in generated GLSL/WGSL.
Common Uses
Need to inspect or name an intermediate value and prevent it from being inlined
Reuse an expensive computation inside a function body and ensure it is evaluated only once
Explicitly keep an intermediate variable for debugging or performance profiling
How to adjust
VarIntent’s output depends on its input node. To change the result, modify the input node tree. If you no longer need to force variable creation, use Var or the original expression directly. Note: When called outside Fn(), it will not create a variable and will return the input node as-is.
Code Examples
1// Effective only within Fn() scope
2const shader = Fn(() => {
3 // Complex computation; force a local variable
4 const heavy = VarIntent(noise(uv().mul(8.0)));
5 // Reuse as color and elsewhere
6 return color(heavy, heavy, one().sub(heavy));
7});