Shader Learn

12 From picture to recipe

Cosine palettes: colour in one line

0.5 + 0.5 · cos(2π(f·t + phase)): three cosine waves with different phases for R, G and B turn one 0–1 number into a colour ramp.

0.23
01
01
01
ExerciseTune values0%

Find this warm colour ramp

Runs once per pixelDrag numbers, or edit the code

JS sidegl.uniform2f(uResolution, …, …)

A palette maps a number t to a colour: each channel is a cosine wave with its own phase. The phases set the order of the hues; the frequency sets how many times the colours cycle as t goes from 0 to 1. t can come from x, a distance, an angle or noise.

Try it

  • Set all three phases to 0: it turns grey
  • Set the frequency to 3: the ramp cycles three times
  • In the lower half t is the distance from the centre: change it to the angle atan(p.y, p.x)