gitmyhub

WaveFunctionCollapse

C# ★ 25k updated 3mo ago

Bitmap & tilemap generation from a single example with the help of ideas from quantum mechanics

An algorithm that generates new images or tile maps by learning patterns from a single example, creating infinite varied content that feels hand-crafted.

C#C++PythonJavaScriptUnityUnreal Engine 5Godot 4setup: moderatecomplexity 3/5

Wave Function Collapse (WFC) is an algorithm that generates new images or tile maps by learning patterns from a single example image you provide. Think of it like this: you give it a small sample texture or tile set, and it creates a larger, new image that looks locally consistent with the original — same kinds of patterns appear in similar proportions, and neighboring tiles fit together the same way they did in the example.

The name is borrowed from quantum mechanics (where "wave function collapse" describes a particle settling into a definite state), but the math here is simpler. The algorithm starts with every pixel or tile in "unknown" state, then repeatedly picks the most constrained spot, locks it in based on the patterns learned from your input, and ripples that decision outward. It keeps doing this until the whole output is filled in, or hits a contradiction and restarts.

Game developers use WFC to generate levels, dungeons, and landscapes procedurally — meaning by algorithm rather than hand-crafting each one. It's been used in published games like Bad North, Caves of Qud, and Townscaper. You'd reach for it when you need infinite, varied content that still feels cohesive and hand-crafted in style. It works on pixel art bitmaps and tile-based maps, and has been ported to C++, Python, JavaScript, Unity, Unreal Engine 5, Godot 4, and more. The original implementation is written in C#.

Where it fits