mx_ifgreater
Compares value1 and value2 and selects between in1 and in2. In this implementation, if value1 > value2 it returns in2, otherwise in1 (because the comparison drives the mix factor). Works for scalars and component-wise vectors.
Core Advantages
Single-node compare-and-select without explicit If branching. Easy to inline and vectorize.
Common Uses
Threshold-based switch between two colors or material paths
Mask-driven selection using height/normal/lighting values
Noise/texture conditioned hard binary blending
Lightweight control-flow in vertex/fragment stages
How to adjust
1) Change value1/value2 or the threshold source to move the boundary; 2) Swap in1 and in2 to invert selection; 3) For the usual “true selects in1” semantics, call mx_ifgreater(value1, value2, in2, in1) or rewrite as value2.greaterThan(value1).mix(in1, in2); 4) Ensure in1 and in2 share the same type; 5) For soft transitions, feed a smooth factor (e.g., smoothstep) into mix instead.
Code Examples
1// Switch colors by height threshold (note: true selects in2)
2const threshold = uniform( 0.0 );
3const result = mx_ifgreater(
4 positionWorld.y,
5 threshold,
6 color( '#1e90ff' ), // below threshold
7 color( '#ff6347' ) // above threshold (selected)
8);
9
10material.colorNode = result;