Procedural Cave Generation Using 3D Noise
Procedural generation of subterranean cave networks relies on sampling three-dimensional noise fields to determine whether specific points in space are solid rock or open air. Game developers achieve realistic, interconnected caverns by combining diverse mathematical noise functions, manipulating those fields through domain warping, and applying isosurface extraction algorithms to convert raw mathematical density values into rendered 3D geometry.
3D Density Fields and Thresholding
The foundation of noise-based cave systems is the 3D scalar density field. Unlike 2D heightmaps that can only represent single-elevation terrain surfaces, a 3D noise function assigns a density value to any coordinate \((x, y, z)\) in volumetric space. Developers commonly utilize Perlin or Simplex noise for this purpose.
A carving threshold is established to define the presence of caves. If the sampled noise value at a given point falls below this threshold, the algorithm classifies that voxel as empty space (air); if it exceeds the threshold, it remains solid matter. To prevent caves from breaking through the surface or digging infinitely into the core, developers introduce a vertical gradient bias. Adding or subtracting an offset proportional to the depth ensures that caves naturally seal off near the surface and terminate at specified depths.
Domain Warping for Organic Morphology
Pure 3D noise functions often produce uniform, repetitive patterns that look artificial. To introduce winding, geological realism, developers use domain warping (coordinate perturbation).
Domain warping involves using secondary and tertiary noise passes to offset the input coordinates before querying the primary cave noise. For example, instead of sampling density at \((x, y, z)\), the engine samples at:
\[(x + Noise_A(x, y, z), y + Noise_B(x, y, z), z + Noise_C(x, y, z))\]
This mathematically bends and stretches the noise space, transforming generic spherical pockets into organic, twisting tunnels, fault lines, and irregular subterranean passages.
Swiss Cheese, Spaghetti, and Noodle Noise Combinations
Modern procedural systems, such as the generation pipeline used in large-scale voxel games, rarely rely on a single noise sample. Instead, they blend multiple specialized noise profiles:
- Cheese Caves (Volumetric Pockets): Low-frequency 3D noise with a low threshold carves vast, spherical, or oblong underground caverns.
- Spaghetti Caves (Connecting Tunnels): Created using ridged multifractal noise or by taking the absolute value of standard noise. By carving spaces where the noise value is exceptionally close to zero, developers create thin, sinuous tubes that travel horizontally and vertically, linking larger chambers together.
- Noodle Caves (Tight Crevices): High-frequency, high-distortion noise variants carved at narrow thresholds to generate claustrophobic crawl spaces and micro-fissures.
Combining these profiles using intersection (Boolean AND) or union (Boolean OR) operations yields a cohesive subterranean network featuring both grand central hubs and narrow interconnecting passageways.
Cellular (Worley) Noise for Cavern Rooms
While Perlin and Simplex noise provide smooth transitions, Worley (cellular) noise generates structures based on distance to scattered feature points. When inverted or thresholded, Worley noise yields sharp, angular fissures, columnar basalt formations, or massive crystal-like geodes. Blending cellular noise with gradient noise allows developers to transition smoothly between smooth, water-eroded limestone caverns and sharp, jagged tectonic fractures.
Isosurface Extraction: Converting Noise to Geometry
Once the density field is computed, it must be translated into renderable polygons. Developers use several key isosurface extraction algorithms:
- Marching Cubes: Evaluates the eight corners of each virtual cube in the grid. Based on which vertices are inside or outside the solid threshold, it maps the configuration to a lookup table to generate corresponding triangles.
- Dual Contouring: Uses the Hermite data (exact points and surface normals where the isosurface crosses grid edges) to generate vertices inside the cells. This approach preserves sharp geological features, sheer cliffs, and jagged rocks far better than Marching Cubes.
- Surface Nets: A computationally lighter alternative to Dual Contouring that smooths voxel boundaries while maintaining high performance for real-time terrain modification.