Smooth Edges

29 / 30
Learn to create smooth edge transition effects using the smoothstep function, contrasting with the hard edges of the step function.

step creates hard edges, but many effects need soft transitions. smoothstep interpolates smoothly between two thresholds.


What is smoothstep

smoothstep(edge0, edge1, x) transitions smoothly from 0 to 1 between edge0 and edge1:

  • x <= edge0 → returns 0.0
  • x >= edge1 → returns 1.0
  • in between → smooth transition
  • d < 0.2: mask = 1.0 (inside circle, white)
  • d > 0.3: mask = 0.0 (outside circle, black)
  • 0.2 < d < 0.3: soft edge

step vs smoothstep

step snaps at the boundary; smoothstep eases from edge0 to edge1. Transition width = edge1 - edge0 — narrower means harder edge.


Exercise

The exercise has mask = 0.0 (solid black). Use smoothstep(0.2, 0.3, d) to create a soft-edged circle mask.

Answer Breakdown

smoothstep(0.2, 0.3, d) starts rising at d = 0.2 and reaches 1.0 at d = 0.3. The 1.0 - inverts it: white at center, black outside.

Transition range is 0.3 - 0.2 = 0.1. Change 0.3 to 0.25 for a sharper edge; change it to 0.5 for a wider blur.

GLSL Code Editor

Correct Code Preview

Current Code Preview