GLSL Learning

GLSL shader example

Voronoi (Cellular Noise)

Animated Voronoi cells in GLSL: scatter one random point per grid cell and color each pixel by its distance to the nearest point.

Live example

Edit the code and the preview updates as you type.

How it works

Voronoi noise splits the screen into cells, like soap bubbles, cracked mud or giraffe skin. It works in three steps:

  1. Split space into a grid, and give every grid cell one feature point at a random position inside it (random2(cell)).
  2. For each pixel, find the feature point closest to it.
  3. Use that distance as the color: dark right at a point, brighter farther away.

A pixel's nearest point might belong to a neighboring cell, so the double loop checks the current cell and its 8 neighbors. Points never leave their own cell, so checking further is never needed.

0.5 + 0.5 * sin(u_time + 6.2831 * point) moves each point around inside its cell. Every point has a different random phase, so they drift independently and the cell walls keep reshaping.

Try changing it

ChangeResult
* 5.0 to * 12.0Many small cells
sin(u_time + ...) to sin(6.2831 * point)Frozen cells
Delete the color += lineNo white dots at the feature points
minDist in mix(...) to step(0.3, minDist)Flat colored blobs around each point

Built-in functions used

Learn it step by step