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.
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:
i = floor(p)is the cell (whole numbers),f = frac(p)is the position inside it (0 to 1 in x and y).- Soften f:
f = f * f * (3.0 - 2.0 * f). - Get a random number at each of the cell's four corners:
abottom-left,bbottom-right,ctop-left,dtop-right (hash(i),hash(i + float2(1, 0)), and so on). - Blend the bottom pair across:
lerp(a, b, f.x). Blend the top pair across:lerp(c, d, f.x). - 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