Daniel Gray

Thoughts, Notes, Ideas, Projects

Contact

Graphics Gems GLSL - Perlin Noise

Perlin Noise, introduced by Ken Perlin in 1985 and featured in Graphics Gems II, revolutionized procedural texture generation. This gradient-based interpolation technique creates seamless, natural-looking noise that has become the foundation for countless visual effects in games, films, and real-time graphics.

Interactive Demo

Move your mouse to rotate the camera and explore the 3D volumetric cloud. The cloud is generated using Perlin Noise with multiple octaves (Fractal Brownian Motion):

Mathematical Foundation

Perlin Noise works by:

  1. Grid-based gradients: At each integer grid point, assign a random gradient vector
  2. Distance vectors: For any point, compute vectors to the 8 surrounding grid corners (in 3D)
  3. Dot products: Compute dot product between each gradient and its corresponding distance vector
  4. Interpolation: Smoothly interpolate the 8 dot product values using a smoothstep function

The Algorithm

For a 3D point p\mathbf{p}, Perlin Noise:

  1. Find the 8 grid corners: i=p\mathbf{i} = \lfloor \mathbf{p} \rfloor, f=fract(p)\mathbf{f} = \text{fract}(\mathbf{p})
  2. Get gradients at each corner: g000,g100,,g111\mathbf{g}_{000}, \mathbf{g}_{100}, \ldots, \mathbf{g}_{111}
  3. Compute dot products: dijk=gijk(fiijk)d_{ijk} = \mathbf{g}_{ijk} \cdot (\mathbf{f} - \mathbf{i}_{ijk})
  4. Trilinear interpolation: noise=trilinear(d000,d100,,u)\text{noise} = \text{trilinear}(d_{000}, d_{100}, \ldots, \mathbf{u})

Where u=s(f)\mathbf{u} = s(\mathbf{f}) is the smooth interpolation factor.

Smooth Interpolation

The smoothstep function ensures continuity:

s(t)=t2(32t)s(t) = t^2(3 - 2t)

This creates a smooth S-curve that eliminates discontinuities at grid boundaries. The function satisfies s(0)=0s(0) = 0, s(1)=1s(1) = 1, and has zero derivatives at both endpoints.

Fractal Brownian Motion (FBM)

By combining multiple octaves of Perlin Noise at different frequencies and amplitudes, we create Fractal Brownian Motion:

FBM(p,n)=i=0n1ainoise(pfi)\text{FBM}(\mathbf{p}, n) = \sum_{i=0}^{n-1} a_i \cdot \text{noise}(\mathbf{p} \cdot f_i)

Where:

  • ai=a0ria_i = a_0 \cdot r^i is the amplitude of octave ii (typically r=0.5r = 0.5)
  • fi=f02if_i = f_0 \cdot 2^i is the frequency of octave ii (typically f0=1f_0 = 1)

This creates natural-looking patterns with detail at multiple scales—perfect for clouds, terrain, marble, wood grain, and more.

Applications

Volumetric Clouds

The demo above uses FBM to create volumetric clouds:

  • Multiple octaves create detail at various scales
  • Density is computed from noise values
  • Lighting uses noise gradients as normals

Terrain Generation

Perlin Noise excels at terrain:

  • Use noise as height maps
  • Combine multiple octaves for realistic landscapes
  • Add domain warping for more complex patterns

Procedural Textures

Create endless variations:

  • Marble: Use noise as a coordinate for sine waves
  • Wood: Use noise along one axis for grain patterns
  • Stone: Combine multiple noise layers

Performance

Perlin Noise is remarkably efficient:

  • Runs at 60 FPS on modern hardware
  • Even works well on mobile GPUs
  • Can generate complex scenes in a single shader pass

The key is the grid-based structure, which allows efficient computation without expensive random number generation per pixel.

References

Related Articles

Related Content

Graphics Gems GLSL Series

Graphics Gems GLSL Series The Graphics Gems series (1990-1995) contains timeless algorithms and techniques that remain fundamental to computer graphics today. This series adapts these classic algorith...