Wave Function Collapse¶
Wave function collapse is one of my favorite procedural generation algorithms. I just think it’s really neat. The idea for WFC is that you have a grid of cells that each could take a variety of possible options, and you have adjacency rules that restrict which types of cells can neighbor which types.
For example, if you’re generating elements in a top-down grid, you might have cells be able to be rivers, plains, farmland and trees, and you could restrict where the tiles could go such that farmland can only be adjacent to farmland, rivers, and plains; and trees can only be adjacent to trees and plains.
Note
Outside of the realm of procedural generation, wave function collapse can be used in a Sudoku solver, which is kind of neat.
We won’t be going over too many details on the algorithm on this page, partially because I think this could be an interesting avenue for a final project, and partially because an explanation is much better motivated by a visual aide, as in the first demo mentioned in the next section.
Hands-On Demos¶
There’s a bunch of fantastic demos and explanations for wave function collapse online. One of my favorites was created by Martin Donald on itch.io. It also comes along with a fantastic video on how WFC works. This demo is cool because it will let you see how choosing one option can update other cell’s possible options.
He also made another demo which shows how the adjacency rules can be inferred by an prototype model, found here. This one is interesting because sometimes the results can be very good and other times they can be not so good. Wave function collapse on its own is very powerful, but this demo goes to show that introducing some intelligent design can greatly improve outcomes, as can be seen in the first demo.
Townscaper¶
Source: https://townscapergame.com
Townscaper is a game about building island towns by placing blocks onto an irregular grid. Using WFC, Townscaper turns these blocks into houses, arches, stairways, towers, and more.
Tiny Glade¶
Source: https://store.steampowered.com/app/2198150/Tiny_Glade/¶
Tiny Glade is a sandbox diorama builder with a medieval theme. You can build little castles, cottages, ruins, and so on. It’s a very cute game that also uses WCF when placing details.
Note
As an aside, both Tiny Glade and Townscaper are great examples of incredible sound design.