Computer Science · Lesson 16
Perlin Noise: Randomness That Looks Natural
Minecraft does not store every hill in its worlds. It stores a single number, the seed, and calculates the land as you walk into it. The tool behind this is Perlin noise, a kind of randomness that changes smoothly the way real terrain, clouds, and wood grain do. In this lesson you will build it one piece at a time, then use it to generate your own worlds.
Why Plain Randomness Looks Wrong
Ask a computer for random heights with Math.random() and every value is chosen on its own, with no connection to its neighbor. That is white noise. It looks like TV static, and nothing in nature looks like that. A mountain that is 900 m tall at one step is not 12 m tall one step later.
Nature is random but smooth: points that are close together have similar values. The graph below draws the same kind of landscape three ways. Press Roll again a few times and compare them.
- White noise: a new random number at every step. Jagged and unusable as land.
- Value noise: random heights only at whole numbers, with the gaps filled in smoothly. Better, but the peaks all land on the grid.
- Perlin noise: random slopes at whole numbers. Hills and valleys fall between grid points, so the pattern looks less regular.
Build Perlin Noise in One Dimension
Ken Perlin's idea was to place a random gradient (a slope) at every whole number on the line, called the lattice. At a point x between two lattice points, the algorithm does three things:
- Follow each neighbor's slope. The left point's slope g₀ gives a height of g₀ · t, where t is how far you are past it (0 to 1). The right point's slope g₁ gives g₁ · (t − 1).
- Ease the blend. Pass t through a fade curve so the blend starts and ends gently.
- Blend. Mix the two heights using the faded t. This mixing is called interpolation. Near the left point you get mostly the left slope's line, and near the right point mostly the right one's.
Try it: hover or drag across the graph to inspect a point. Drag a purple slope handle up or down to change that gradient. Then switch the fade curve to Linear and look for sharp corners at the grid lines.
Why the fade curve matters
A linear blend changes direction suddenly at each grid line, and the eye picks up those creases, especially once the noise is lit and shaded. Perlin's 1985 version used smoothstep, 3t² − 2t³. In 2002 he changed it to 6t⁵ − 15t⁴ + 10t³, which also smooths out the curvature, so lighting on noise terrain no longer shows faint grid lines.
Into Two Dimensions: A Grid of Arrows
In 2D, each corner of a square grid gets a random arrow, a gradient vector. For any pixel inside a square, the algorithm:
- Finds the four corners of the square the pixel is in.
- Draws an offset arrow from each corner to the pixel.
- Takes the dot product of each corner's gradient with its offset. The result is positive if the gradient points toward the pixel and negative if it points away.
- Fades and blends the four numbers: first along x, then along y.
Move over the image (or tap it) to pick a pixel. The four corner values appear next to the corners, green for positive (lighter) and red for negative (darker).
Octaves: Mountains, Hills, and Pebbles
A single layer of noise gives gentle rolling hills and no small detail. Real landscapes have big shapes (mountain ranges), medium ones (ridges), and small ones (boulders). So we add several layers, called octaves. Each octave is the same noise, sampled at a higher frequency (zoomed out, so bumps come closer together) and with a smaller amplitude (shorter bumps).
World Builder Lab
This lab puts all the pieces together. Every pixel's color comes from one number, its fBm height, and the style decides how that number becomes a color. Use the Controls panel to change the style, octaves, persistence, and seed. Drag on the map to pan.
Beyond Terrain: One Function, Many Materials
Artists reuse the same noise function for many materials. The only change is the small formula that turns the noise number into a color. Click any tile to enlarge it. Every image below was generated in your browser a moment ago.
Warping space with noise
The Warped tile uses domain warping: before sampling the noise, it moves the sample point by another noise value, noise(p + noise(p)). The result looks like swirling paint or gas giant clouds.
The Whole Algorithm in 15 Lines
Here is the 1D version from Part 2 written in JavaScript. The 2D and 3D versions follow the same pattern with more corners.
// one random slope per whole number, fixed by the seed const slopes = makeSlopes(seed); // e.g. [0.7, -0.4, 0.9, ...] function fade(t) { return t*t*t*(t*(t*6 - 15) + 10); } function lerp(a, b, t) { return a + (b - a) * t; } function noise(x) { const i = Math.floor(x); // left lattice point const t = x - i; // how far past it (0..1) const left = slopes[i] * t; // follow left slope const right = slopes[i + 1] * (t - 1); // follow right slope return lerp(left, right, fade(t)); } function fbm(x, octaves) { let sum = 0, amp = 1, freq = 1; for (let o = 0; o < octaves; o++) { sum += amp * noise(x * freq); amp *= 0.5; freq *= 2; // persistence, lacunarity } return sum; }
slopes[3] = 1 and slopes[4] = -1, what is noise(3.5)? (Hint: fade(0.5) = 0.5.) Check your answer in the practice set below. An Oscar for a Math Function
Ken Perlin worked on the computer graphics for Disney's Tron (1982) at a company called MAGI. He disliked how "machine-like" the film's clean, perfect surfaces looked. Real materials have random variation in them. Over the next few years he wrote a noise function that artists could use to add that variation to any surface.
- 1982Tron is released. Perlin sets out to make CG surfaces look less perfect.
- 1983He develops the first version of his noise function.
- 1985He publishes it in "An Image Synthesizer" at SIGGRAPH, the main computer graphics conference.
- 1997The Academy of Motion Picture Arts and Sciences gives him a Technical Achievement Award for Perlin noise.
- 2001–2002He publishes simplex noise, which is faster in higher dimensions, and "improved noise" with the quintic fade curve you tested in Part 2.
Perlin chose not to patent his original noise, so anyone could use it. That is one reason it spread into every major 3D program and game engine.
Where You Have Already Seen It
Design Challenges
Use the World Builder Lab. Record the seed and every setting so someone else can recreate your result exactly.
Make a map that is at least 60% water with five or more separate islands. (Hint: the Water readout and the sea level slider.)
Find settings for rolling farmland and settings for jagged alpine peaks on the same seed. Which two sliders made the biggest difference?
Pick a seed and describe your world in three sentences without naming the seed. Can a partner find the seed from a list of five?
Sketch a material not in the gallery (lava, camouflage, a leopard's spots). Describe the rule that turns the noise number into a color.
Check Yourself
Answer, then press Check. A hint appears if you are not quite there.
Easy1. In Perlin noise, neighboring points have completely unrelated values. True or false?
Easy2. Value noise stores a random height at each lattice point. What does Perlin noise store there instead?
Easy3. What is the value of 1D Perlin noise at exactly x = 7, no matter what the slopes are?
Medium4. What does adding more octaves do?
Medium5. With persistence 0.5, octave 1 has amplitude 1.0. What is the largest possible combined amplitude of 3 octaves?
Medium6. From Part 7: slopes[3] = 1 and slopes[4] = −1. What is noise(3.5)? (fade(0.5) = 0.5)
Medium7. Two players type the same seed and the same settings on different computers. What do they get?
Challenge8. What goes wrong if you blend the corner values with a plain linear blend instead of a fade curve?
Signal Garden combines smooth noise, sine waves, color theory, live controls, PNG export, tutorials, and creative challenges.