mx_modulo
MaterialX‑compatible modulo/remainder helper; a thin wrapper around TSL mod(in1, in2). Returns in1 modulo in2 element‑wise; the divisor defaults to float(1) when omitted.
Core Advantages
Predictable wrapping aligned with MaterialX semantics; safe default; works on scalars and vectors (element‑wise) so it can be applied directly to UVs or color channels.
Common Uses
UV wrapping, tiling masks, and band/stripe patterns
Mapping continuous time to a [0,1) looping phase for animations
Bucket/grid indexing with floor/div (segmenting space or time)
Building periodic waveforms (saw/triangle) from a normalized phase
How to adjust
Change in2 to set the period (use positive, non‑zero values). For vector inputs you can set per‑component periods (e.g., vec2 for U/V). To get a normalized phase use mx_modulo(x, p).div(p). Results follow GLSL mod semantics (a − b*floor(a/b)); if you need a non‑negative phase, wrap the divisor with abs(in2).
Code Examples
1// Split the U coordinate into 10 segments and take a [0,1) phase inside each
2const phase = mx_modulo( uv().x.mul( 10.0 ), 1.0 );
3
4// White in the second half of each segment, black in the first: repeating stripes
5const stripe = step( 0.5, phase );
6material.colorNode = vec3( stripe );
7
8// Looping timer: wrap time to a [0,1) cycle (use as an animation driver)
9const loop01 = mx_modulo( time, 1.0 );