If
Implements conditional logic (if...else branching) in shaders, allowing different computations or values based on specific criteria.
Core Advantages
Provides a declarative, highly readable way to implement control flow, compiling directly to efficient, native GLSL if...else statements. This allows the GPU to use dynamic branching for optimization, skipping unnecessary calculations, which is more performant and powerful than emulating conditions with math functions.
Common Uses
Mixing different materials or textures based on a mask map.
Controlling flow within loops (e.g., ray marching) by using Break or Continue based on a hit condition.
Acting as a feature toggle to enable or disable expensive visual effects (like volumetric fog) based on a uniform.
Creating geometric effects like dissolve or cutouts by conditionally discarding pixels.
How to adjust
Adjusting the logic of an If node produces the most direct visual changes. Modifying the `conditional` input (e.g., changing a comparison threshold) alters the boundary of where an effect is applied, like moving the snowline on a mountain. Changing the nodes connected to the `then` or `else` branches completely replaces the visual content for that condition, for instance, swapping a moss color with a rock texture.
Code Examples
1const condition = normal.dot( up ).greaterThan( 0.7 );
2const finalColor = If( condition, color('white') ).else( color('green') );