Diagonal Gradient

17 / 30
Combine vUv.x and vUv.y to create a diagonal gradient and interpolate colors with mix.

This is the Module 2 capstone. Combine a diagonal factor, clamp, and mix for a colored diagonal gradient.


Review: three steps

  1. Build the factor: combine x and y into a single 0–1 value
  1. Clamp to range: make sure t stays within 0–1
  1. Map to color with mix:

Why clamp

(vUv.x + vUv.y) * 0.5 maxes out at 1.0 and mins at 0.0, so it won't actually overflow here. But in more complex situations factors can go out of range — clamp is a good habit.


Exercise

The exercise has t = 0.0 and three TODOs waiting. Complete them in order: build t → clamp → compute color.

Answer Breakdown

clamp(t, 0.0, 1.0) locks t in the 0–1 range no matter what.

mix(colorA, colorB, t) interpolates from deep blue (bottom-left, t=0) to orange (top-right, t=1).

Try t = vUv.x * vUv.y — multiplication gives a very different shape than addition.

GLSL Code Editor

Correct Code Preview

Current Code Preview