Forest Logo
search
package_2

noise

By @nightcycle

Roblox

Mirrored from Wally

Noise

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.

[image: perlin with a period of half the image]
  • 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.

Map2D million / s2D map3D million / s3D map
Random52.31.3 ms35.71.8 ms
Value54.81.2 ms41.31.6 ms
Perlin44.81.5 ms28.72.3 ms
Simplex37.01.8 ms22.03.0 ms
Cellular17.83.7 ms7.39.0 ms
Edge11.85.6 ms4.714.0 ms
Voronoi17.03.9 ms6.99.5 ms
Nearest16.73.9 ms6.89.7 ms
ValueDerivative45.51.4 ms33.02.0 ms
PerlinDerivative35.41.9 ms22.13.0 ms
SimplexDerivative31.92.1 ms17.93.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-inmillion / smap
math.noise(x, y)45.41.4 ms
math.noise(x, y, z)45.91.4 ms
random:NextNumber(), one generator drawn from repeatedly39.71.7 ms
Random.new(seed):NextNumber(), a generator per sample19.33.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:

Map2D million / s2D map3D million / s3D map
Random38.41.7 ms27.92.3 ms
Value40.71.6 ms25.82.5 ms
Perlin31.22.1 ms18.13.6 ms
Simplex29.02.3 ms16.44.0 ms
Cellular8.57.7 ms3.917.0 ms
Edge7.19.3 ms3.121.1 ms
Voronoi8.18.1 ms3.817.3 ms
Nearest8.28.0 ms3.817.2 ms
ValueDerivative33.32.0 ms20.13.3 ms
PerlinDerivative24.82.6 ms15.14.3 ms
SimplexDerivative23.62.8 ms13.34.9 ms

The Manhattan metric, with no period:

Map2D million / s2D map3D million / s3D map
Cellular7.88.4 ms3.220.2 ms
Edge6.99.5 ms2.823.8 ms
Voronoi6.99.5 ms1.737.5 ms
Nearest7.09.3 ms1.738.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.

Map2.0 million / s1.0 million / sSpeedup
Random 2D51.84.810.8x
Random 3D35.52.912.0x
Perlin 2D41.78.45.0x
Perlin 3D26.78.03.3x
Cellular 2D17.04.73.6x
Cellular 3D6.62.62.5x
Voronoi 2D15.94.83.3x
Voronoi 3D6.43.22.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

WhereHow
Outside Robloxlune run scripts/bench
Studio command bar, while the place is runningprint(require(game.ReplicatedStorage.noise.bench.Studio).Run())
boatbomber's Benchmarker pluginopen 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.

PerlinCellularVoronoi
[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

  1. Write src/Maps/<Name>.luau, returning a Types.Map: a name and two samplers, each a function(self, x, y, z?). Sample is the map as an object without options uses it, reading the seed from self._Seed32. Configured is the map for an object with options: it also wraps its hashing at self._WrapX, _WrapY and _WrapZ, and a point map measures with self._Metric (the search in src/Search.luau does both). Add Derivative and ConfiguredDerivative if the map has a slope. Expose Point or Gradient if it has feature points or gradients, and the overlay will draw them.
  2. List it in src/Maps/init.luau.
  3. Give the classes their methods for it in src/init.luau.
  4. 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 = 0 slice 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

check_circle

Safe for commercial use

infoModified 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.