mx_ifequal
mx_ifequal
Branchless conditional selector: returns in2 when value1 equals value2, otherwise returns in1 (note the inverted picking order).
Core Advantages
Avoids dynamic branching by using the equality mask to drive mix; works with scalars, vectors, and colors; handy for MaterialX-style conditionals.
Common Uses
Switching between two colors or parameter sets per instance/index.
Picking between two roughness/metalness/emissive values conditionally.
Per‑camera (e.g., stereo eye) or custom ID–based selection.
How to adjust
Change the compared operands (value1/value2) to alter the condition; remember: equal→in2, not equal→in1. For vector inputs, selection is component-wise. If you prefer “equal→in1”, swap in1/in2, or use value1.equal(value2).cond( in1, in2 ).
Code Examples
1// Use green when cameraIndex == 1, otherwise red (equal → choose in2)
2const col = mx_ifequal( cameraIndex, 1u, color( 0xff4444 ), color( 0x44ff44 ) );
3material.colorNode = col;