Noise
Perlin/Simplex noise → GPUTexture
Quick Start
Loading...
Source
Loading...
Documentation
Noise
GPU-accelerated Perlin and Simplex noise generator. Writes animated 2D noise to a caller-provided GPUTexture via a compute shader — no render pass required.
Usage
import { createNoise } from './noise';
const noise = createNoise(device);
const texture = device.createTexture({
size: [512, 512],
format: 'rgba8unorm',
usage: GPUTextureUsage.STORAGE_BINDING | GPUTextureUsage.TEXTURE_BINDING
});
// Per frame
noise.update(texture, { time: elapsed, scale: 2.0 });
// texture is now filled — bind it in your pipeline
// Clean up when done
noise.destroy();
API
createNoise(device)
Returns a Noise instance. No options — dimensions come from the target texture.
noise.update(target, options?)
Dispatches the compute shader to write noise into the target texture.
target—GPUTextureto write into (must haveSTORAGE_BINDINGusage, formatrgba8unorm)
| Option | Type | Default | Description |
|---|---|---|---|
time |
number |
0 |
Animation time (drives UV scrolling) |
scale |
number |
2.0 |
Noise frequency scale |
offset |
[number, number] |
[0, 0] |
UV offset |
octaves |
number |
6 |
FBM octave count |
persistence |
number |
0.5 |
Amplitude multiplier per octave |
lacunarity |
number |
2.0 |
Frequency multiplier per octave |
type |
'perlin' | 'simplex' |
'simplex' |
Noise algorithm |
domainWarp |
boolean |
false |
Enable domain warping |
warpStrength |
number |
1.0 |
Domain warp intensity |
noise.destroy()
Releases the uniform buffer. Does not destroy the target texture (you own it).
Algorithm
Perlin noise uses gradient-based interpolation on a regular grid with quintic smoothing (6t^5 - 15t^4 + 10t^3), producing smooth, continuous noise without visible grid artifacts.
Simplex noise evaluates on a simplex (triangular) grid instead, which has less directional bias and scales better to higher dimensions. It uses the same hash-based gradient approach but fewer lookups per evaluation.
FBM (Fractal Brownian Motion) layers multiple octaves of the base noise at increasing frequency and decreasing amplitude. More octaves add fine detail; persistence controls how quickly the amplitude decays; lacunarity controls how quickly the frequency increases.
Domain warping uses a second noise evaluation to distort the input coordinates before the main evaluation, creating organic, swirling patterns.
WGSL loading
The default import uses Vite's ?raw suffix:
import shaderSource from './noise.wgsl?raw';
If you're not using a bundler, load via fetch:
const shaderSource = await fetch(new URL('./noise.wgsl', import.meta.url)).then((r) => r.text());
Modifying
Change the texture format
Edit the storageTexture format in noise.ts and the textureStore output in noise.wgsl. For example, to output raw floats:
- In
noise.ts: changeformat: 'rgba8unorm'toformat: 'r32float'in the bind group layout - In
noise.wgsl: changetexture_storage_2d<rgba8unorm, write>totexture_storage_2d<r32float, write>, andtextureStore(output, ..., vec4f(...))to store a single float
Use a custom hash function
Replace the hash2 and hash1 functions in noise.wgsl. Any function that maps vec2f → vec2f (or vec2f → f32) with good distribution will work. The current implementation uses Dave Hoskins' hash-without-sine approach.
Inline the noise into your own shader
Copy the perlin, simplex, fbm, and domain_warp functions from noise.wgsl directly into your own shader. They're self-contained — they only depend on the hash and grad functions above them.
Extend to 3D
The Perlin and Simplex algorithms extend naturally to 3D. You'd need:
- A 3D hash function (
vec3f → vec3f) - 3D gradient vectors (8 corners for Perlin, 4 simplex vertices)
- Updated skew/unskew constants for Simplex:
SKEW = 1/3,UNSKEW = 1/6 - An extra interpolation dimension in Perlin, or an extra simplex corner
Further Reading
Resources on the algorithms and techniques used in this module.
Perlin Noise
Ken Perlin, "An Image Synthesizer" (SIGGRAPH 1985) The original paper introducing gradient noise for procedural texture generation. Perlin received an Academy Award for Technical Achievement for this work. https://dl.acm.org/doi/10.1145/325165.325247
Ken Perlin, "Improving Noise" (SIGGRAPH 2002) Revisits the original algorithm with improved gradient selection and interpolation (the quintic curve used in this module). https://mrl.cs.nyu.edu/~perlin/paper445.pdf
Simplex Noise
Ken Perlin, "Noise Hardware" (Real-Time Shading course, SIGGRAPH 2001) Introduces simplex noise as a faster, lower-artifact alternative to classic Perlin noise, using a simplex grid instead of a hypercubic grid. https://www.csee.umbc.edu/~olano/s2002c36/ch02.pdf
Stefan Gustavson, "Simplex noise demystified" (2005) A clear, practical walkthrough of the simplex noise algorithm with implementation guidance. Excellent for understanding the skew/unskew math. https://weber.itn.liu.se/~stegu/simplexnoise/simplexnoise.pdf
Ian McEwan, David Munoz, Art Tevs, Ashima Arts, "Efficient computational noise in GLSL" (2012) GPU-friendly noise implementations without lookup textures, using arithmetic hash functions — the approach this module's WGSL shader is based on. https://jcgt.org/published/0001/01/02/
Fractal Brownian Motion (FBM)
Benoit Mandelbrot, "The Fractal Geometry of Nature" (1982) The foundational text on fractal geometry. FBM (fractional Brownian motion) is a core concept — layering self-similar noise at multiple scales.
Inigo Quilez, "FBM — Fractal Brownian Motion" Practical guide to implementing FBM for procedural graphics, with interactive examples and parameter explanations. https://iquilezles.org/articles/fbm/
Domain Warping
- Inigo Quilez, "Domain Warping" Explains and visualizes the technique of distorting noise input coordinates with another noise evaluation to create organic, swirling patterns. https://iquilezles.org/articles/warp/
Hash Functions
- Dave Hoskins, "Hash without Sine" (Shadertoy) The arithmetic hash functions used in this module's WGSL shader. Avoids trigonometric functions for better GPU performance and portability. https://www.shadertoy.com/view/4djSRW
General References
The Book of Shaders, "Noise" chapter by Patricio Gonzalez Vivo and Jen Lowe An interactive introduction to noise functions in shaders, covering Perlin, simplex, and FBM with live code examples. https://thebookofshaders.com/11/
GPU Gems 3, Chapter 1: "Generating Complex Procedural Terrains Using the GPU" Covers GPU-based noise generation for terrain, including compute shader approaches similar to this module. https://developer.nvidia.com/gpugems/gpugems3/part-i-geometry/chapter-1-generating-complex-procedural-terrains-using-gpu