Hierarchical WaveFunction Collapse

Michael Beukman, Branden Ingram, Ireton Liu, Benjamin RosmanAIIDE 2023

Abstract

Hierarchical WaveFunction Collapse (HWFC) extends the popular constraint-solving algorithm by allowing designers to specify high-level structural components that are recursively filled with finer details. This approach solves the "lack of global structure" problem inherent in standard WFC, enabling the generation of complex, controllable levels for 2D and 3D environments without sacrificing procedural diversity.

Introduction

WaveFunction Collapse (WFC) has become a staple of the procedural content generation (PCG) community due to its ability to transform small example images into sprawling, coherent levels by enforcing local adjacency constraints. However, WFC is fundamentally "nearsighted." Because it typically only evaluates small overlapping windows (e.g., 3x3 tiles), it struggles to maintain global structure. For instance, while WFC can ensure a "path" tile connects to another, it cannot easily guarantee that a level contains exactly one castle or a logical perimeter wall. Designers often find it difficult to enforce these large-scale requirements without significant hand-coding. HWFC bridges this gap by introducing a hierarchy that allows for "big picture" planning followed by "small scale" detailing.

Methodology

The core innovation of HWFC is a multi-pass approach to the standard WFC algorithm. Instead of collapsing the entire map in a single pass using a uniform set of tiles, HWFC operates in recursive stages:

  1. Constraint Discovery: Similar to standard WFC, the system extracts patterns and adjacency rules from human-designed examples.
  2. Hierarchical Elements: Designers define larger patterns (e.g., a building footprint or room layout). These high-level patterns utilize a specialized "Unfilled" tile as a placeholder.
  3. Recursive Generation: The algorithm first runs WFC using only high-level patterns to create a structural "sketch" of the world. It then identifies the "Unfilled" regions within those high-level structures and runs subsequent passes of WFC to fill them with medium-level components and, finally, low-level tiles (pixels or voxels).
The iterative process of WaveFunction Collapse, involving pattern filtering, sampling, and propagation.

By using the "Unfilled" tile as a placeholder, the algorithm ensures that lower-level details are only placed where they make structural sense according to the high-level plan.

Experimental Setup

The authors evaluated HWFC across three distinct environments to test scalability and flexibility:

  • Maze: A simple 2D binary grid used for benchmarking structural complexity.
  • Roguelike: A complex 2D domain with 38 distinct tile types, inspired by classic adventure games.
  • Minecraft: A 3D environment used to demonstrate the algorithm's scalability in three dimensions.

Results and Discussion

HWFC demonstrates a significant improvement in the controllability-diversity balance. While a common fear in PCG is that increased control leads to repetitive results, HWFC maintains high diversity (measured via KL-Divergence) while significantly increasing the designer's ability to dictate where specific structures appear.

3D environments generated using HWFC, demonstrating coherent structures like castle walls and paths.

Key findings include:

  • Controllability: In the Roguelike domain, HWFC successfully placed a much higher fraction of medium-level elements inside their intended high-level containers compared to non-hierarchical baselines.
  • Structural Complexity: HWFC consistently generated more large-scale, coherent structures (like complete castle walls) than standard WFC, which often produced fragmented layouts when faced with complex tiles.
  • Visual Quality: Qualitative results in 3D showed the system could generate coherent walled areas and moats that felt intentionally designed rather than randomly scattered.

Conclusion and Future Work

While HWFC offers a robust framework for structured PCG, it faces several limitations. Like standard WFC, it cannot currently guarantee level solvability (e.g., ensuring a path exists from start to finish). Additionally, while it requires less data than machine learning approaches, it still necessitates manual effort from designers to craft hierarchical components. Future work may focus on automatically extracting these hierarchies from single complex examples and optimizing the computational cost for large-scale 3D generation.

Summary updated

BibTeX
@inproceedings{beukman2023hierarchical,
  author = {Michael Beukman and Branden Ingram and Ireton Liu and Benjamin Rosman},
  title = {{Hierarchical WaveFunction Collapse}},
  booktitle = {AIIDE},
  year = {2023},
  doi = {10.1609/aiide.v19i1.27498},
}
Figure