decrement
A function node that simulates the postfix decrement operator (a--). It returns the input variable's current value and then subtracts 1 from it, serving as a fundamental tool for iteration and state management.
Core Advantages
Abstracts a common, multi-step operation (get value, then subtract one) into a single, reusable function. This makes shader logic cleaner, more readable, and less error-prone, especially when implementing loops or stateful algorithms, providing a clear pattern for functions with side effects.
Common Uses
Managing counters in custom loop structures (e.g., while loops).
Acting as a step limiter and iteration counter in Ray Marching algorithms.
Creating countdown timers for procedural animations or state machines.
Counting passes in multi-pass rendering effects.
How to adjust
The node's behavior is fixed. Its visual effect is indirectly adjusted by changing the 'initial value' of the mutable node (usually a VarNode) passed to it. For example, in ray marching where color brightness depends on remaining steps, increasing the counter's initial value from 10 to 20 will make objects hit early appear brighter, as `decrement` will return a higher value in the initial iterations.
Code Examples
1// myCounter is a mutable node, e.g., VarNode(10)
2const previousValue = decrement( myCounter );
3
4// Now, previousValue holds 10, but myCounter's internal value has become 9.