Building a Procedural Hex Map with Wave Function Collapse
5 hours ago
- #webgpu
- #wave-function-collapse
- #procedural-generation
- Procedural medieval islands generated using Wave Function Collapse (WFC) algorithm.
- Hex tiles with 6 edges add complexity compared to traditional square tiles.
- Tile definitions include terrain types for each edge and weights for selection bias.
- WFC starts with all possibilities, collapses cells with lowest entropy, and propagates constraints.
- Multi-grid approach splits the map into 19 hexagonal grids to manage complexity.
- Backtracking and a layered recovery system handle WFC failures and cross-grid boundary issues.
- Elevation adds a 3D constraint, requiring roads and rivers to align across levels.
- Hex coordinates use cube coordinates (q, r, s) for easier neighbor finding and distance calculations.
- Perlin noise is used for organic placement of trees and buildings, separate from WFC.
- Water effects include animated caustics and coastal waves, with special handling for coves.
- 3D tiles are created in Blender, ensuring alignment and correct UV mapping.
- WebGPU and TSL shaders enhance rendering, with post-processing for atmosphere.
- Optimizations include BatchedMesh for efficient rendering and shared materials to reduce GPU load.
- The project combines procedural generation with artistic touches to create explorable, varied maps.