select
Implements fundamental 'if-then-else' conditional logic within a shader, allowing for a selective output between two different input values or node networks based on a boolean condition.
Core Advantages
It enables dynamic per-pixel or per-vertex decisions on the GPU, allowing the construction of complex conditional logic in a declarative, visual node-based way while maintaining a clear and understandable material structure.
Common Uses
Creating hard-edged masks
Generating procedural geometric patterns (e.g., checkerboards)
Implementing conditional vertex displacement
How to adjust
Control by adjusting its three input nodes: changing the `condNode` (condition node) alters the boundary of the effect's active area; swapping the `ifNode` and `elseNode` inverts the display regions of the two results; replacing the `ifNode` or `elseNode` from a simple value (like a color) to a complex node chain (like animated noise) can achieve localized dynamic effects.
Code Examples
1// Condition: Is the pixel's world Y-coordinate greater than 0?
2const condition = positionWorld.y.greaterThan( 0 );
3
4// If the condition is true, output red; otherwise, output blue
5const finalColor = select(
6 condition, // --> condNode
7 color( 0xff0000 ), // --> ifNode
8 color( 0x0000ff ) // --> elseNode
9);