Wave Function Collapse (algorithm)
   HOME

TheInfoList



OR:

Model synthesis (also wave function collapse or 'wfc') is a family of constraint-solving
algorithm In mathematics and computer science, an algorithm () is a finite sequence of Rigour#Mathematics, mathematically rigorous instructions, typically used to solve a class of specific Computational problem, problems or to perform a computation. Algo ...
s commonly used in
procedural generation In computing, procedural generation is a method of creating data algorithmically as opposed to manually, typically through a combination of human-generated content and algorithms coupled with computer-generated randomness and processing power. I ...
, especially in the
video game industry The video game industry is the tertiary industry, tertiary and quaternary industry, quaternary sectors of the entertainment industry that specialize in the video game development, development, marketing, distribution (marketing), distribution, ...
. Some video games known to have utilized variants of the algorithm include ''
Bad North ''Bad North'' is a real-time strategy video game developed by Plausible Concept (a game studio in Malmö, Sweden, founded by Oskar Stålberg and Richard Meredith) and published by Raw Fury. The game was released on August 20, 2018, for the Nint ...
'', ''
Townscaper ''Townscaper'' is a city builder game by Oskar Stålberg. It was released for Windows and Mac in August 2021. A port to the Nintendo Switch was released in August 2021 when the Steam version left early access. The mobile version was released in ...
'', and ''
Caves of Qud ''Caves of Qud'' is a roguelike role-playing video game developed by American studio Freehold Games set in an open world that is partially pre-made and partially randomly generated. The game takes place in a post-apocalyptic science fantasy setti ...
''. The first example of this type of algorithm was described by Paul Merrell, who termed it 'model synthesis' first in his 2007 i3D paper and also presented at the 2008
SIGGRAPH conference SIGGRAPH (Special Interest Group on Computer Graphics and Interactive Techniques) is an annual conference centered around computer graphics organized by ACM, starting in 1974 in Boulder, CO. The main conference has always been held in North ...
and his 2009 PhD thesis. The name 'wave function collapse' later became the popular name for a variant of that algorithm, after an implementation by Maxim Gumin was published in 2016 on a GitHub
repository Repository may refer to: Archives and online databases * Content repository, a database with an associated set of data management tools, allowing application-independent access to the content * Disciplinary repository (or subject repository), an ...
with that name. Gumin's implementation significantly popularised this style of algorithm, with it becoming widely adopted and adapted by technical artists and game developers over the following years. There were a number of inspirations to Gumin's implementation, including Merrell's PhD dissertation, and
convolutional neural network A convolutional neural network (CNN) is a type of feedforward neural network that learns features via filter (or kernel) optimization. This type of deep learning network has been applied to process and make predictions from many different ty ...
style transfer. The popular name for the algorithm, 'wave function collapse', is from an analogy drawn between the algorithm's method and the concept of
superposition In mathematics, a linear combination or superposition is an expression constructed from a set of terms by multiplying each term by a constant and adding the results (e.g. a linear combination of ''x'' and ''y'' would be any expression of the form ...
and observation in
quantum mechanics Quantum mechanics is the fundamental physical Scientific theory, theory that describes the behavior of matter and of light; its unusual characteristics typically occur at and below the scale of atoms. Reprinted, Addison-Wesley, 1989, It is ...
. Some innovations present in Gumin's implementation included the usage of overlapping patterns, allowing a single image to be used as an input to the algorithm. Some have speculated that the reason Gumin's implementation proved more popular than Merrell's, may have been due to the 'model synthesis' implementation's lower accessibility, its 3D focus, or perhaps the general public's computing constraints at the time. One of the differences between Merrell & Gumin's implementation and 'wave function collapse' lies in the decision of which cell to 'collapse' next. Merrell's implementation uses a scanline approach, whereas Gumin's always selects as next cell the one with the lowest number of possible outcomes.


Description

The WFC or 'model synthesis' algorithm has some variants. Gumin and Merrell's implementations are described below, and other variants are noted:


Gumin's implementation

# The input bitmap is read, and the patterns present within the bitmap are counted. # An array is created with the dimensions of the output desired. # Each cell of the array is initialized in an 'unobserved' state # The following steps are repeated: ## The cell with the lowest number of possible output states is located ## 'Collapse' this cell into one of its possible states according to the rules ## Check that all cells are still valid and follow the rules # Once all cells are 'collapsed' into a definite state, return the output. If the output is illegal, discard it, and repeat the process until legal.


Merrell's implementation

Merrell's earlier implementation is substantially the same as Gumin's with some minor differences. (1) In Merrell's version, there is no requirement to select the cell with the lowest number of possible output states for collapse. Instead, a scanline approach is adopted. According to Merrell, this results in a lower failure rate of the model without any negative effect on quality. Some commentators have noted however that the scanline approach to 'collapse' tends to result in directional artifacts. (2) Merrell's approach performs the algorithm in chunks, rather than all-at-once. This approach greatly reduces the failure rate for many large complex models; especially in a 3D space.


Developments

In April 2023 Shaad Alaka and Rafael Bidarra of
Delft University The Delft University of Technology (TU Delft; ) is the oldest and largest Dutch public technical university, located in Delft, Netherlands. It specializes in engineering, technology, computing, design, and natural sciences. It is considered one ...
proposed 'Hierarchical Semantic wave function collapse'. Essentially, the algorithm is modified to work beyond simple, unstructured sets of tiles. Prior to their work, all WFC algorithm variants operated on a flat set of tile choices per cell. Their generalised approach organizes tile-sets into a hierarchy, consisting of abstract nodes called 'meta-tiles', and terminating nodes called 'leaf tiles'. For example, on the first pass, WFC might make a certain tile a meta-tile of 'castle' type; which on a second pass will be collapsed into other tiles based on a rule, e.g. a 'wall' or 'grass' tile.


References


External links

* https://github.com/mxgmn/WaveFunctionCollapse Combinatorial algorithms Constraint programming Procedural generation {{Algorithm-stub