Step Function Mask
25 / 30
Construct a mask with clear boundaries using the step() function, mastering binary processing in GLSL.
The mix factor is usually a continuous 0–1 value producing smooth gradients. The step function forces the factor to only 0 or 1, producing a hard edge.
What is step
step(edge, x) returns only two values:
x < edge→ returns0.0x >= edge→ returns1.0
Left half (vUv.x < 0.5) gets 0, right half (vUv.x >= 0.5) gets 1. No transition — the edge is hard.
Using mask to pick a color
Pass mask to mix to switch hard between two colors:
Try changing it
Change the threshold from 0.5 to move the cut line:
| Threshold | Effect |
|---|---|
| 0.3 | Left side takes only 30% |
| 0.7 | Left side takes 70% |
| 0.5 | Equal halves (default) |
Exercise
The exercise has mask = 0.0 (solid leftColor). Use step(0.5, vUv.x) to compute mask so the left and right halves show different colors.
Answer Breakdown
step(0.5, vUv.x) jumps from 0 to 1 at vUv.x = 0.5, creating a vertical cut.
mix(leftColor, rightColor, mask) switches colors at that cut: 0 → leftColor, 1 → rightColor.
Try step(0.5, vUv.y) — the cut line becomes horizontal.