Start typing to search packages!
noise
By @nightcycle
Roblox
Mirrored from WallyNoise
Seeded noise maps for Luau: white, value, Perlin, simplex, cellular, edge and Voronoi, each in 2D and 3D.
Plain Luau with no dependencies. It runs the same in Roblox and in any other Luau runtime, and a seed gives the same values on every machine.
[dependencies]
Noise = "nightcycle/noise@2.0.0"
Usage
local Noise = require(ReplicatedStorage.Packages.Noise)
local noise = Noise.new(12345) -- leave the seed out for a fresh one
local flat = noise:Perlin(x, y) -- 2D
local volume = noise:Perlin(x, y, z) -- 3D
Every map takes (x, y) or (x, y, z) and returns a number from 0 to 1. One unit is one lattice cell, so scale your
coordinates to choose how coarse the pattern is: noise:Perlin(x / 16, y / 16) puts a feature roughly every 16 studs.
Passing z selects the 3D map even when it is 0. The 2D maps are their own, faster paths, not a slice of the 3D ones.
| [image: random] | noise:Random(x, y, z?) | White noise. Every distinct coordinate gets an unrelated value in [0, 1). |
| [image: value] | noise:Value(x, y, z?) | Random values on the lattice corners, blended smoothly, in [0, 1). The cheapest smooth map, and the blobbiest: its highs and lows can only sit on corners. |
| [image: perlin] | noise:Perlin(x, y, z?) | Smooth gradient noise in [0, 1], centred on 0.5. A seeded take on math.noise. |
| [image: simplex] | noise:Simplex(x, y, z?) | Gradient noise on a lattice of triangles, in [0, 1], centred on 0.5. It has no favoured directions, where Perlin leans toward the axes and diagonals, and it uses far more of its range. |
| [image: cellular] | noise:Cellular(x, y, z?) | Worley noise: the distance to the nearest feature point. 0 on a point, capped at 1. |
| [image: edge] | noise:Edge(x, y, z?) | How much further the second nearest feature point is than the nearest, in [0, 1]. 0 along the border between two cells: cracks, veins, mortar, or a mask for blending across a border. |
| [image: voronoi] | noise:Voronoi(x, y, z?) | The value in [0, 1) of the nearest feature point's cell, giving flat regions with hard edges. |
Cellular, Edge and Voronoi share their feature points, so for one seed the Voronoi borders run along the Cellular ridges and the Edge zeroes.
Coordinates have to stay within about two billion cells of the origin (±2^31).
The nearest point
noise:Nearest(x, y, z?) returns the feature point nearest a sample: the centre of the Voronoi cell the sample is in.
Use it to find which region a position belongs to and where that region's centre is.
local centreX, centreY = noise:Nearest(x, y)
local biome = noise:Voronoi(centreX, centreY) -- the same value as noise:Voronoi(x, y)
It always returns three numbers, with 0 for z in 2D. Take the two you need before passing them on: handing all three to a map selects its 3D form.
Slopes
ValueDerivative, PerlinDerivative and SimplexDerivative return the same value as the plain map, followed by how
fast it is changing along x, y and z (0 for z in 2D). That is one sample where measuring the slope by hand takes three
or four, and it is exact.
local height, slopeX, slopeZ = noise:PerlinDerivative(x / 64, z / 64)
-- the slope is per cell, and a cell is 64 studs here
local normal = Vector3.new(-slopeX * HEIGHT / 64, 1, -slopeZ * HEIGHT / 64).Unit
Slopes are what terrain normals, slope-based texturing and flow fields are built from.
Options
Noise.new takes options as a second argument. They are fixed for the life of the object; make another object, with
the same seed if you like, for another combination.
local tiles = Noise.new(12345, { Metric = "Manhattan", PeriodX = 16, PeriodY = 16 })
Metric is how Cellular, Edge, Voronoi and Nearest measure the distance to a feature point. The points do not
move, so objects that share a seed still line up.
"Euclidean" (default) | "Manhattan" | "Chebyshev" |
|---|---|---|
| [image: voronoi, euclidean] | [image: voronoi, manhattan] | [image: voronoi, chebyshev] |
| Straight-line distance. | The distances along each axis added together, so the points equally far from somewhere form a diamond. | The largest distance along any one axis, so the points equally far from somewhere form a square. |
Manhattan and Chebyshev both give borders made of straight runs along the axes and diagonals, which suits city blocks, circuit boards and crystals.
PeriodX, PeriodY, PeriodZ make every map repeat after that many cells along an axis, for textures that tile,
worlds that wrap around, and animation that loops. Each is a whole number from 1 to 2^31, and an axis left out never
repeats.
- Inside its first period a map matches the same map without a period, except in the cells that reach across the seam. Simplex is the exception: its usual lattice cannot repeat, so with a period it is laid out on a different one and gives different values. In 2D that lattice is also stretched slightly to fit the periods.
- Random has no lattice, so it wraps the coordinate itself. It repeats exactly where a coordinate and the same coordinate one period on are both exact, which holds for whole numbers and binary fractions like 0.25 but not for a step like 0.1.
An object made without options pays nothing for them. With them, a period costs the lattice maps a fifth to two fifths of their speed, and either option costs the point maps about half; the figures are in the benchmark below.
In a hot loop
Calling through a local skips the method lookup. Under lune that made Perlin about a fifth faster:
local perlin = noise.Perlin
for x = 1, 1024 do
heights[x] = perlin(noise, x / 16, 0)
end
Benchmark
Measured on 2026-11-22 in a Roblox Studio 0.748 server playtest on a Ryzen 9 9950X. Each figure is the median of 51 runs of 4,096 samples.
Speed is given two ways: millions of samples a second, and the time to fill a 256 x 256 map (65,536 samples). For scale, a frame at 60 frames a second is 16.7 ms.
| Map | 2D million / s | 2D map | 3D million / s | 3D map |
|---|---|---|---|---|
| Random | 52.3 | 1.3 ms | 35.7 | 1.8 ms |
| Value | 54.8 | 1.2 ms | 41.3 | 1.6 ms |
| Perlin | 44.8 | 1.5 ms | 28.7 | 2.3 ms |
| Simplex | 37.0 | 1.8 ms | 22.0 | 3.0 ms |
| Cellular | 17.8 | 3.7 ms | 7.3 | 9.0 ms |
| Edge | 11.8 | 5.6 ms | 4.7 | 14.0 ms |
| Voronoi | 17.0 | 3.9 ms | 6.9 | 9.5 ms |
| Nearest | 16.7 | 3.9 ms | 6.8 | 9.7 ms |
| ValueDerivative | 45.5 | 1.4 ms | 33.0 | 2.0 ms |
| PerlinDerivative | 35.4 | 1.9 ms | 22.1 | 3.0 ms |
| SimplexDerivative | 31.9 | 2.1 ms | 17.9 | 3.7 ms |
The samples are called through a local, as in the loop above.
When the built-ins will do
The same loop, in the same session, over what the engine already provides:
| Built-in | million / s | map |
|---|---|---|
math.noise(x, y) | 45.4 | 1.4 ms |
math.noise(x, y, z) | 45.9 | 1.4 ms |
random:NextNumber(), one generator drawn from repeatedly | 39.7 | 1.7 ms |
Random.new(seed):NextNumber(), a generator per sample | 19.3 | 3.4 ms |
math.noise is the engine's Perlin noise. In 2D noise:Perlin keeps pace with it; in 3D math.noise is about
1.6 times as fast. Use it when all of these are fine:
- You want Perlin, and nothing else on this page.
- The pattern can be the same for everyone. It takes no seed, so the only way to vary it is to offset the coordinates.
- A range of roughly -1 to 1, not 0 to 1.
- A pattern that repeats every 256 units.
Random produces a sequence: each number depends on how many were drawn before it. Use it for things that happen
in an order, such as loot rolls, shuffles and spawn timing, and for its other methods (NextInteger, NextUnitVector,
Shuffle). Speed is not a reason to pick it: noise:Random is faster than NextNumber in 2D and close behind it in
3D.
Use noise:Random when a value has to depend on where it is rather than on when it was asked for: it can be sampled
in any order, from any thread, and gives the same answer. Seeding a Random from the coordinates gets the same
effect at well under half the speed, creating a generator for every sample.
With options
A period of 16 cells on every axis:
| Map | 2D million / s | 2D map | 3D million / s | 3D map |
|---|---|---|---|---|
| Random | 38.4 | 1.7 ms | 27.9 | 2.3 ms |
| Value | 40.7 | 1.6 ms | 25.8 | 2.5 ms |
| Perlin | 31.2 | 2.1 ms | 18.1 | 3.6 ms |
| Simplex | 29.0 | 2.3 ms | 16.4 | 4.0 ms |
| Cellular | 8.5 | 7.7 ms | 3.9 | 17.0 ms |
| Edge | 7.1 | 9.3 ms | 3.1 | 21.1 ms |
| Voronoi | 8.1 | 8.1 ms | 3.8 | 17.3 ms |
| Nearest | 8.2 | 8.0 ms | 3.8 | 17.2 ms |
| ValueDerivative | 33.3 | 2.0 ms | 20.1 | 3.3 ms |
| PerlinDerivative | 24.8 | 2.6 ms | 15.1 | 4.3 ms |
| SimplexDerivative | 23.6 | 2.8 ms | 13.3 | 4.9 ms |
The Manhattan metric, with no period:
| Map | 2D million / s | 2D map | 3D million / s | 3D map |
|---|---|---|---|---|
| Cellular | 7.8 | 8.4 ms | 3.2 | 20.2 ms |
| Edge | 6.9 | 9.5 ms | 2.8 | 23.8 ms |
| Voronoi | 6.9 | 9.5 ms | 1.7 | 37.5 ms |
| Nearest | 7.0 | 9.3 ms | 1.7 | 38.1 ms |
The point maps have one hand-tuned search for the plain case and share a general one for everything else, which costs them between a third and three fifths of their speed. Voronoi and Nearest lose the most, three quarters, in 3D with Manhattan: there the nearest point is more often outside the neighbouring cells and the search has to widen.
Against 1.0
1.0 run through the same cases as 2.0, in one session earlier the same day on the same machine. The 2.0 column differs a little from the table above because it comes from that session.
| Map | 2.0 million / s | 1.0 million / s | Speedup |
|---|---|---|---|
| Random 2D | 51.8 | 4.8 | 10.8x |
| Random 3D | 35.5 | 2.9 | 12.0x |
| Perlin 2D | 41.7 | 8.4 | 5.0x |
| Perlin 3D | 26.7 | 8.0 | 3.3x |
| Cellular 2D | 17.0 | 4.7 | 3.6x |
| Cellular 3D | 6.6 | 2.6 | 2.5x |
| Voronoi 2D | 15.9 | 4.8 | 3.3x |
| Voronoi 3D | 6.4 | 3.2 | 2.0x |
1.0 cached the feature points of every cell it touched and never let them go. Those numbers are with that cache warm, which is its best case; 2.0 keeps no state at all, so its memory use does not grow.
Running it yourself
| Where | How |
|---|---|
| Outside Roblox | lune run scripts/bench |
| Studio command bar, while the place is running | print(require(game.ReplicatedStorage.noise.bench.Studio).Run()) |
| boatbomber's Benchmarker plugin | open bench/Noise.bench |
All three time the cases in bench/Cases.luau. The two that run in Roblox add the Random class
from bench/BuiltIns.luau, which plain Luau does not have. The Studio runner times everything
twice, once with os.clock and once with MicroProfiler scopes read back through
LibMP, and leaves the Noise/... scopes in the MicroProfiler for a closer look. On
the machine above lune lands within about ten percent of Studio.
Debug visuals
Each map has a UI Labs story that renders it live from a set of controls: seed, cells across the image, resolution, a 3D toggle with a Z slider to scrub through the volume, an overlay, the metric and a period. Under the map sit a histogram of its values and a readout of the minimum, maximum, mean and sampling speed. A value outside [0, 1] is painted red or blue, so a map that breaks its range is obvious at a glance.
The overlay draws the lattice in blue, plus whatever the map is built from: feature points as orange dots, gradients as green arrows. On a 3D slice a feature point fades as it moves away from the slice.
| Perlin | Cellular | Voronoi |
|---|---|---|
| [image: perlin with its gradients] | [image: cellular with its feature points] | [image: voronoi with its feature points] |
Build the development place with lune run scripts/build, open noise.rbxl, and the stories appear in UI Labs under
the Noise storybook. All shows every map side by side.
The same renderer runs outside Roblox: lune run scripts/render writes the images in media/.
Adding a map
- Write
src/Maps/<Name>.luau, returning aTypes.Map: a name and two samplers, each afunction(self, x, y, z?).Sampleis the map as an object without options uses it, reading the seed fromself._Seed32.Configuredis the map for an object with options: it also wraps its hashing atself._WrapX,_WrapYand_WrapZ, and a point map measures withself._Metric(the search insrc/Search.luaudoes both). AddDerivativeandConfiguredDerivativeif the map has a slope. ExposePointorGradientif it has feature points or gradients, and the overlay will draw them. - List it in src/Maps/init.luau.
- Give the classes their methods for it in src/init.luau.
- Add
stories/<Name>.story.luau(two lines; copy an existing one).
The benchmarks, the renderer, the All story and the range, determinism and period tests read the map list, so the
new map is covered by each of them without further changes. The build fails if a map has no story.
Maps hash lattice cells with the functions in src/Hash.luau, but keep their own copy of the mixing step rather than calling it: a function call per cell costs more than the hash does. The tests check the copies against the reference. For the same reason the plain, configured and derivative forms of a map are written out separately rather than sharing a core.
Development
Tools are managed with Rokit.
rokit install
lune run scripts/setup # dev packages, sourcemap, type definitions
lune run scripts/check # tests, formatting, strict analysis
lune run scripts/build # build/noise.rbxm, the Wally archive, and noise.rbxl
src/ is the library and the only thing that ships. Stories, benchmarks and tests live beside it and are left out of
both the Wally package and the release model; the build checks that.
To release, set the version in wally.toml, commit, and push a matching tag (v2.0.0). The release workflow
re-runs the checks, publishes to Wally and attaches the model and archive to a GitHub release.
Changes from 1.x
- A seed produces different values than it did in 1.x. Anything that stored a seed to regenerate a map will get a new map.
- Every map now stays within [0, 1]. Cellular returns the plain distance capped at 1; in 1.x the 2D form was rescaled and could go negative, and the 3D form was uncapped.
- The 2D maps are no longer the
z = 0slice of the 3D ones. - The library no longer depends on any packages or on Roblox datatypes.
- New maps: Value, Simplex and Edge. New queries:
Nearest, and derivatives for Value, Perlin and Simplex. New options: a distance metric for the point maps, and a period for every map.
Package Details
Install command (Click to copy)
Version
2.0.0
License
Apache-2.0
Safe for commercial use
Modified files must carry a notice of changes. If the package ships a NOTICE file, its attributions must be preserved.
Automated license review — not legal advice.
