NodeAccess
Manages variable mutability (read-only vs. read-write) in shaders, clarifying data intent to enable safer code and advanced algorithms.
Core Advantages
Acting like `const` and `let` in TSL, it enhances code robustness by preventing accidental modification of inputs, provides optimization hints to the compiler, and is the cornerstone for implementing iterative algorithms like loops with accumulators.
Common Uses
READ_ONLY: For all input data, such as Uniforms, Attributes, and texture sampling results.
READ_WRITE: For creating modifiable state variables or accumulators, especially within loops (LoopNode).
WRITE_ONLY: For specifying write-only output targets, like the final fragment color or vertex position.
How to adjust
This node is a constant and cannot be adjusted. However, choosing the `READ_WRITE` access is the 'key' to unlocking certain effects. For instance, without it, you can only blend a few noise layers to get a flat 'mist'. By using a `READ_WRITE` variable to iteratively accumulate in a loop, you can create a 'cloud layer' effect with rich detail and depth.
Code Examples
1let totalNoise = float(0.0); // Create a read-write accumulator
2
3Loop({ end: 5 }, () => {
4 // Repeatedly read, modify, and write back to the variable in a loop
5 totalNoise.addAssign( noise( uv().mul(freq) ) );
6});