HeadlinesBriefing favicon HeadlinesBriefing.com

Procedural Hex Maps with Wave Function Collapse

Hacker News •
×

A developer has built a procedural medieval island generator using Wave Function Collapse (WFC) and WebGPU, creating 4,100 hex tiles across 19 grids in about 20 seconds. The project brings together procedural generation techniques with Three.js and TSL shaders to produce unique medieval worlds with roads, rivers, coastlines, and villages.

The core algorithm, originally created by Maxim Gumin, works like the board game Carcassonne but with hex tiles instead of squares. Each tile has 6 edges that must match adjacent tiles — grass connects to grass, roads to roads. With 30 tile types, 6 rotations, and 5 elevation levels, each cell has 900 possible states. The system uses a layered recovery approach to handle failures, including unfixing constraints, local-WFC patching, and mountain tiles as a last resort.

Hex coordinates add complexity since there are 6 directions instead of 4, requiring cube coordinates (q, r, s) for proper neighbor calculations. The project also incorporates elevation with 5 levels, creating cliffs and slopes that connect different heights. While WFC excels at local edge matching, the developer found it unsuitable for large-scale features like tree and building placement, which require different approaches.