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 → returns 0.0
  • x >= edge → returns 1.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:

ThresholdEffect
0.3Left side takes only 30%
0.7Left side takes 70%
0.5Equal 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.

GLSL Code Editor

Correct Code Preview

Current Code Preview