Noise · lesson 4 of 6 · Intermediate · about 5 min

Value noise (smooth randomness)

You will build: Write vnoise() and display it at scale 8x6 as grey.

The picture produced by the shader in the lesson "Value noise (smooth randomness)"
The target picture. In the lesson you write the shader that draws it, and a match bar shows how close you are.

You blended two random values along a line. Now do it on a flat sheet: value noise is random numbers at the corners of a grid, blended smoothly in between. Five steps, all of which you have already seen:

  1. i = floor(p) is the cell (whole numbers), f = frac(p) is the position inside it (0 to 1 in x and y).
  2. Soften f: f = f * f * (3.0 - 2.0 * f).
  3. Get a random number at each of the cell's four corners: a bottom-left, b bottom-right, c top-left, d top-right (hash(i), hash(i + float2(1, 0)), and so on).
  4. Blend the bottom pair across: lerp(a, b, f.x). Blend the top pair across: lerp(c, d, f.x).
  5. Blend those two results upward: lerp(bottom, top, f.y).

Move the sliders and watch the numbers: blend across twice, then blend up once. That is the whole algorithm. Then wrap it in a function called vnoise so you can reuse it. (Tip: the Outline button writes this plan into your editor as comments.)

The numbers you need

Everything the picture depends on is given, so the challenge is the code, not guessing.

Scale
vnoise(uv * float2(8.0, 6.0))

Try it in your own language

The lesson is written once and shown in every language. Pick yours: Unity (Built-in), Unity (URP), Unreal, Shadertoy / WebGL, OpenGL (LWJGL, raylib), three.js, GameMaker, LÖVE (Lua), Godot, Apple (iOS, macOS), WebGPU / Bevy.

Start coding