stepElement
stepElement
Alias of GLSL step with swapped parameter order (x, edge): returns 1 when x ≥ edge, otherwise 0.
Core Advantages
Places the source value first and the threshold second—more intuitive and consistent with many node/function signatures, reducing mistakes from writing step(edge, x) in the wrong order.
Common Uses
Create binary masks / hard edges (e.g., UI masks, thresholded stripes).
Threshold-based clipping or alpha testing (works with discard or materialAlphaTest).
Quantize continuous signals (noise, grayscale) into on/off gates for branching.
How to adjust
Change the second parameter (edge) to move the cutoff; invert with oneMinus(); pair with smoothstep for anti-aliased transitions. Equivalent to step(edge, x).
Code Examples
1
2// Compare uv.x against a threshold: black on the left, white on the right
3const mask = stepElement( uv().x, float( 0.5 ) );
4material.colorNode = mix( color( 0x000000 ), color( 0xffffff ), mask );
5