Papers
Topics
Authors
Recent
Search
2000 character limit reached

Wave Function Collapse (WFC)

Updated 3 March 2026
  • Wave Function Collapse (WFC) is a procedural content generation algorithm that uses local pattern constraints to create globally consistent arrangements in 2D grids.
  • It employs pattern extraction, entropy-driven cell selection, and constraint propagation to generate textures, paths, and layouts with quantifiable performance metrics.
  • Recent adaptations integrate obstacle pre-fixing, stretch-space, and wildcard masking to extend WFC's versatility in game-level design while balancing exemplar fidelity and designer control.

Wave Function Collapse (WFC) is a class of algorithmic frameworks for procedural content generation that leverage local pattern-based constraint satisfaction to synthesize globally coherent arrangements of discrete tiles or patterns, primarily in two-dimensional grids. Originating from example-based texture synthesis, WFC has seen rapid adoption in game development and computational creativity due to its capacity for flexible, data-driven synthesis of textures, paths, and complex scenes from minimal designer input.

1. Fundamental Principles and Algorithmic Structure

The Wave Function Collapse algorithm is based on overlapping pattern constraints informed by local contexts in a sample input. The core workflow consists of the following steps:

  • Pattern Extraction: Sliding an n×n window over the input exemplar to extract the complete set of unique local tile patterns and their occurrence frequencies.
  • Adjacency Constraints: For each extracted pattern, constructing directional adjacency rules that enumerate all patterns compatible (i.e., overlapping identically) in each relative direction—typically up, down, left, right.
  • Wave Function Representation: Each cell in the output grid is initially considered to be in a superposition, able to take any pattern from the set, until it is "collapsed" to a definite state through observation.
  • Entropy-Driven Collapse and Constraint Propagation: At each iteration, the algorithm selects the output cell with the lowest Shannon entropy (computed from the weighted pattern options), samples a legal pattern there—weighted by frequency in the exemplar—and then recursively propagates the resulting constraints to neighboring cells, intersecting their possible pattern sets with the adjacency lists imposed by the chosen pattern.
  • Contradiction Handling: Should an output cell end up with no valid patterns (i.e., a contradiction), the algorithm typically restarts, optionally with backtracking.

This entropy-based observation and constraint propagation proceeds until all cells in the output grid are assigned a unique pattern, completing the collapse process (Scurti et al., 2018).

2. Adaptations for Path Generation and Complex Content

While the original WFC was designed for densely tiled texture synthesis, recent work has adapted the algorithm for structured path and layout synthesis, introducing several key mechanisms:

  • Obstacle Pre-fixing: Output grid cells corresponding to obstacles (walls, impassables, etc.) are hard-constrained to a unique pattern representing the obstacle, ensuring global coherence.
  • Stretch Space Integration: A distinct stretch-space (buffer zone) color or pattern is introduced in the exemplar, permitting flexible expansion or contraction in generated outputs and mediating the minimal distance between paths and obstacles.
  • Wildcard Masks for Unseen Configurations: Mask patterns with wildcard entries are automatically synthesized for output-localized regions around obstacles, enabling the framework to gracefully handle novel shaped obstacles not found in the input by relaxing local constraints rather than causing outright failure.
  • Pattern Selection Distribution Modulation: Both frequency-weighted and uniform pattern sampling strategies are supported, controlling the degree to which the output statistically mirrors the exemplar's local pattern frequencies versus emphasizing diversity (Scurti et al., 2018).

These adaptations are necessary for practical deployment in game-level pathing, ensuring the synthesis is robust on large, heterogeneous maps and is flexible to designer control.

3. Data Structures, Complexity, and Performance

The central data structures of WFC implementations include:

  • Pattern Set (P): All unique n×n tiles extracted from the exemplar, each with an associated weight (frequency).
  • Adjacency Table (A): For each pattern p ∈ P and each of the four directions, a table listing all patterns q ∈ P with valid overlap.
  • Wave Function (W): For each output grid cell, the current set of still-allowed patterns.

Implementation detail highlights:

  • The adjacency table is a sparse four-directional mapping of potential pattern transitions and can dominate memory for large P.
  • Propagation employs a queue for local-to-global constraint updating; each change can cascade recursively.
  • Output grid initialization immediately hard-codes obstacles and, if required, pre-drawn path segments.

Empirical results demonstrate scalability to maps on the order of 10⁴–10⁵ tiles, with generation times scaling linearly with output area and super-linearly with pattern set size; e.g., a 168×145 grid with ∼300–400 patterns can be synthesized in one to two minutes on standard desktop hardware (Scurti et al., 2018).

4. Expressivity, Limitations, and Comparison with Other PCG Methods

WFC's expressivity is fundamentally constrained to enforcing local n×n adjacency consistencies, rendering it highly effective for textures and locally consistent features (e.g., ornamented wall segments, decorative motifs, simple paths), but unsuitable for globally constrained features such as:

  • Ensuring path non-intersection or a fixed number/length of closed loops.
  • Imposing exact turn counts or global coverage quotas.
  • Specifying long-range structural properties (e.g., perfect maze constraints, or Hamiltonian paths) (Scurti et al., 2018).

Attempts to extend WFC to more global constraints have focused on augmenting it with higher-order Markov patterns, pairwise pattern histories, or incorporating WFC in outer metaheuristics (e.g., simulated annealing, genetic programming) that post-process WFC outputs for fitness.

The method's data-driven, example-based nature sets it apart from hand-crafted constraint solvers, while its reliance on local constraint propagation distinguishes it both from cellular automata (which typically apply purely local rules without explicit constraint satisfaction) and from global optimization frameworks that operate over entire maps at once.

5. Extensions, Implementations, and Future Directions

Emerging work has sought to circumvent both scaling limitations and constraint conflict issues. Strategies include:

  • Wildcards and Masking: Increased use of output-local wildcard patterns to ensure termination on arbitrarily complex output obstacle maps, at the cost of local fidelity to the exemplar.
  • Parameterized Pattern Synthesis: Varying n (the patch size), rotation/reflection symmetries, and the ratio of stretch-space patterns modulates the algorithm's bias toward certain output features.
  • Parallelism and Game Engine Integration: WFC has been implemented as a Unity plugin with parallelization of post-processing steps (e.g., path extraction, waypoint simplification), and supports real-time visualization of constraint propagation (Scurti et al., 2018).

Open challenges remain in guaranteeing global properties necessary for complex procedural level design (non-repetitive, non-intersecting, topologically optimal paths) within a strictly local-constraint paradigm. A plausible implication is that further progress will depend on hybridization with outer optimization loops or the introduction of non-local constraint propagation architectures within the WFC framework.

6. Empirical and Quantitative Evaluations

Quantitative assessments provide timing and memory benchmarks for various scenarios. The following table summarizes key empirical results reported in (Scurti et al., 2018):

Exemplar/Map Pattern Count Output Size Generation Time (s)
Poly 2 / arena1 206 49×49 0.89
Poly 2 / orz000d 253 79×137 7.61
Square / lak519d 304 168×145 49.59
Octagon / lak519d 320 168×145 53.11
Poly 1 / lak519d 348 168×145 58.71
Poly 2 / arena2 267 281×209 78.43

These results indicate that WFC remains computationally tractable for practical game design contexts involving mid-scale maps and moderate pattern set sizes. Output quality is sensitive to exemplar design, pattern size, and the parameterization of stretch space and wildcard masking.

7. Synthesis, Outlook, and Research Directions

Wave Function Collapse represents the leading constraint-propagation–based method for example-driven, local-pattern–consistent content synthesis. Its effectiveness in reproducing high-level motifs with minimal input and its extensibility via pattern-masking and stretch-space innovations have spurred wide adoption, particularly in creative computational domains and procedural pathing for game levels. However, its inherent locality imposes hard limitations on enforceable global properties, suggesting a research trajectory toward more expressive constraint-logic hybrid models or multi-level WFC variants capable of handling large-scale or infinite content generation. The method's robust, data-driven nature, together with efficient propagation and practical engine integrations, ensures its continued relevance and serves as a canonical reference model for procedural content generation methodologies (Scurti et al., 2018).

Definition Search Book Streamline Icon: https://streamlinehq.com
References (1)

Topic to Video (Beta)

No one has generated a video about this topic yet.

Whiteboard

No one has generated a whiteboard explanation for this topic yet.

Follow Topic

Get notified by email when new papers are published related to Wave Function Collapse (WFC).