bool
Converts a numerical input (integer or float) into a boolean value (true/false). The rule is: 0 converts to false, and any non-zero value converts to true.
Core Advantages
Ensures type safety by guaranteeing that the input to conditional nodes (like IfNode) is a proper boolean, thus avoiding shader compilation errors. It clearly expresses the intent to use a numerical value as a 'logical switch', improving code readability.
Common Uses
Providing the condition for conditional nodes (IfNode)
Dynamically enabling or disabling an effect based on a uniform variable (0.0 or 1.0)
Generating high-contrast, binary masks from continuous procedural patterns (like noise or sine waves)
As a debugging tool to visualize whether a calculation result is zero
How to adjust
It acts as a 'digital circuit breaker' visually, with only two states: 'on' (true) and 'off' (false). Adjusting its input from 0 to any non-zero value (or vice-versa) causes an instantaneous, hard visual switch, such as a color snapping from blue to red with no smooth transition. It can turn a smooth function (like a sine wave) into a discontinuous, hard-edged pattern.
Code Examples
1// Convert a controllable value (e.g., a uniform) to a boolean condition
2const isSwitchedOn = myControlValue.bool();
3
4// If the condition is true, show red; otherwise, show blue
5const finalColor = If( isSwitchedOn, color('red'), color('blue') );