Procedural Generation with Wave Function Collapse

https://news.ycombinator.com/rss Hits: 4
Summary

Procedural Generation with Wave Function Collapse February 21, 2019 in algorithms gamedev procgen (Edit 2022-05-03: I found out that the Wave Function Collapse algorithm was heavily inspired by an existing algorithm called “Model Synthesis”. I’ve added a section to further reading with links to the author’s website for more information.) Wave Function Collapse is a procedural generation algorithm which produces images by arranging a collection of tiles according to rules about which tiles may be adjacent to each other tile, and relatively how frequently each tile should appear. The algorithm maintains, for each pixel of the output image, a probability distribution of the tiles which may be placed there. It repeatedly chooses a pixel to “collapse” - choosing a tile to use for that pixel based on its distribution. WFC gets its name from quantum physics. The goal of this post is to build an intuition for how and why the WFC algorithm works. I will break WFC into two separate algorithms and explain them separately. Each is interesting in its own right, and the interface between them is simple. fn wfc_core( adjacency_rules: AdjacencyRules, frequency_rules: FrequencyHints, output_size: (u32, u32), ) -> Grid2D<TileIndex> { ... } This is the low-level part of the algorithm which solves the problem of arranging tiles into a grid according to some specified rules. I’ll give a “black box” description of the core here, and explain how it works internally below. The “core” receives a set of adjacency rules describing which tiles may appear next to other tiles in each cardinal direction. Some example rules are “Tile 6 may appear in the cell ABOVE a cell containing tile 4”, and “Tile 7 map appear in the cell to the LEFT of a cell containing tile 3. It also receives a set of frequency hints, which is a mapping from each tile to a number indicating how frequently the tile should appear in the output, relative to other tiles. If tile 4 maps to 6, and tile 5 maps to 2, then tile 4 sho...

First seen: 2025-10-03 20:54

Last seen: 2025-10-03 23:54