decrementBefore
A function node that simulates the prefix decrement operator (--a). It first subtracts 1 from the input variable and then returns the new, updated value.
Core Advantages
Abstracts and encapsulates a fundamental operation (a = a - 1), greatly enhancing code readability and reusability. The intent of `decrementBefore(counter)` is far clearer than a manually constructed subtraction node network, simplifying the graph and reducing errors.
Common Uses
Serving as an iteration controller in loop structures like ray marching.
Playing sprite or frame-based animations in reverse by decrementing the frame index.
Simulating the modification of game states in a shader, such as reducing health or ammo counts.
As a debugging tool, to step down a value upon an event to observe its changes.
How to adjust
The node's behavior is fixed. Its visual effect is indirectly adjusted by changing the initial value of the mutable node (e.g., a VarNode) passed to it and how its output is used. For instance, in a stepped fade-out effect, repeatedly applying `decrementBefore` to a uniform variable controlling brightness will cause the object's brightness to jump down in discrete, non-continuous 'steps' rather than fading smoothly.
Code Examples
1// myCounter is a mutable node, e.g., VarNode(10)
2const newValue = decrementBefore( myCounter );
3
4// At this point, both newValue and myCounter's internal value are now 9.