nodeObjectIntent
Wraps any JS value or existing node into a proxy with variable intent, hinting the compiler to materialize it as a local shader variable so it can be the LHS of in-place ops (addAssign/mulAssign) and avoid redundant re-evaluation.
Core Advantages
Promotes literals/expressions to reusable variables with one call, reducing inlined GLSL and duplicated work while preserving the proxy API and type inference. Raw JS values are auto-lifted to constant nodes (you can force a type via altType); shader function objects are wrapped as Fn nodes.
Common Uses
Build step-by-step intermediates as the left-hand side of addAssign/subAssign.
Wrap complex expressions once and reuse them to cut recomputation.
Quickly lift JS literals (0, true, [0,1,0]) to nodes and mark them as variable.
Cache staged results in vertex displacement/normal pipelines for clarity.
How to adjust
Use the second parameter altType to force the target type when wrapping raw values (e.g., 'float', 'vec2', 'vec3', 'color'). If you need a guaranteed materialized variable, call .toVar('name') at the end; if you only need a single-use expression, prefer nodeObject(...) without the Intent.
Code Examples
1
2// Accumulate an emissive mask using a variable-intended node
3const mask = nodeObjectIntent( float( 0 ) );
4mask.addAssign( noise( uv().mul( 6.0 ) ).mul( 0.6 ) );
5mask.addAssign( time.sin().mul( 0.4 ) );
6
7// Optionally force the type for literals
8const weight = nodeObjectIntent( 0, 'float' );
9
10material.emissiveNode = color( 0x00ffff ).mul( mask.saturate() );
11