Carlos Correa
← VenRad

Cave generatorvshcave

Caves that generate themselves: first as a 2D map, then as 3D walls inside VenRad.

C++ · version 1.5
Source on GitHub

A cave map generated in the console: walls drawn with hashes, floor with dots

How it works

  1. Noise. A grid is filled at random from a seed.
  2. Smoothing. Each cell looks at its neighbours and decides whether it’s wall or floor. After a few passes, rooms appear. (cellular automaton)
  3. Connecting. Rooms are detected and joined with the shortest possible paths. (flood fill and minimum spanning tree)
  4. Corridors. They’re traced between rooms with an uneven width, so they don’t look ruler-drawn. (Bresenham and value noise)

The same seed always gives the same cave.

From map to 3D

At first it was one cube per cell, and it looked like Minecraft. Now the walls follow the cave’s outline: the edge is extracted, smoothed and raised into 3D. (marching squares and Chaikin)

First-person view down a cave corridor, with the walls smoothed along the outline
Smoothed walls, seen from inside the cave.

Still to do

The floor and ceiling are still built per cell and don’t match the smoothed walls.

Next

A noise module shared across the engine, going from caves to worlds (villages, fields, cities), and a version that runs on this site.