
Infinite procedurally-generated city with the Wave Function Collapse algorithm - guessmyname
https://marian42.itch.io/wfc
======
abetusk
Here's a collection of relevant links for the lazy:

    
    
        * Animated gif: https://twitter.com/marian42_/status/1061785383057440768
        * GitHub page (demo in Unity): https://github.com/marian42/wavefunctioncollapse
        * Original Wave Function Collapse Algorithm: https://github.com/mxgmn/WaveFunctionCollapse

~~~
delinka
I’m too lazy to copypasta the links. Can you please reformat to make them
clickable?

~~~
MrStonedOne
Animated gif
[https://twitter.com/marian42_/status/1061785383057440768](https://twitter.com/marian42_/status/1061785383057440768)

GitHub page (demo in Unity)
[https://github.com/marian42/wavefunctioncollapse](https://github.com/marian42/wavefunctioncollapse)

Original Wave Function Collapse Algorithm
[https://github.com/mxgmn/WaveFunctionCollapse](https://github.com/mxgmn/WaveFunctionCollapse)

~~~
colecut
and they call you people lazy

~~~
MisterTea
We're focused.

------
mrspeaker
Amazing work! I've been excited about this technique since I first saw the
original demos of it
([https://github.com/mxgmn/WaveFunctionCollapse](https://github.com/mxgmn/WaveFunctionCollapse))
- but can someone explain (at a very high level) how Wave Function Collapse
works? I've read through some of the documentation on various repos - it
starts with the nitty-gritty details, and I haven't been able to grasp the
concepts.

~~~
justinpombrio
Here's my high-level understanding.

You're going to tile (say) the plane with a set of tiles you've chosen
beforehand. (In this example, it looks like the tiles are 3d.) There are rules
for which tiles can go next to each other---the edges must match.

As you go, there are two regions: a region in which you've settled on which
tiles to use, and a boundary region in which you haven't. In the boundary
region, you keep track of a _probability distribution_ over the tiles. This
distribution is influenced by the neighboring tiles (exactly how is probably
the most interesting bit of the algorithm; I don't know).

The algorithm proceeds by repeatedly (i) picking a tile on the boundary that
has a very skewed probability distribution, and fixing it to be the most
likely tile; and (ii) updating the probability distributions of the
neighboring tiles in the boundary.

It's possible that you end up making poor tile placements at the beginning
that gets you stuck later, so the algorithm must sometimes backtrack to undo
past decisions. You want to pick a set of tiles such that the algorithm
doesn't need to backtrack _too_ often, or it will take too long.

Note that the distribution is an ordinary probability distribution, not a sum
of complex amplitudes like the name "Wave Function Collapse" would make you
think.

~~~
vokep
Oh my....perhaps this backtracking to fix past inconsistencies could allow for
a game environment in which "Mandela effect" events happen naturally from time
to time. Could make for an interesting game mechanic.

~~~
marian42
You're right. There is backtracking in the demo and when it happens it looks
quite eerie. The world around you just decides it wants to look different and
changes.

~~~
yoklov
That sounds like it could be mechanically cool. Or at least lead to a cool
setting.

------
BorisTheBrave
WFC collapse is an awesome algorithm, but I think this demo really illustrates
that to get nice looking output with procedural generation also requires an
excellent eye for design.

I've played around a bit with WFC and wrote a library for using it[1], but
I've never made anything as pretty as this.

[1]:
[https://boristhebrave.github.io/DeBroglie/](https://boristhebrave.github.io/DeBroglie/)

------
yters
I imagine a counter strike scenario where the area of engagement is constantly
moving throughout this infinite city, so the fight is waged over a constantly
changing landscape. Hecka fun or hecka confusing?!

~~~
ozmbie
I’ve worked as a level designer on FPS games. Dynamic generation might suit
certain types of games (or something like an event mode), but a huge amount of
design work and iteration goes into the layout of multiplayer game levels to
make them enjoyable.

It’s also important that players/teams can memorise the level layouts in order
to form strategies.

Still a cool idea though!

~~~
tikhonj
I haven't designed levels, but playing maps across a few games, I'm constantly
amazed at how well small details are thought out. A seemingly random crate
actually blocks off a line of fire that would give one team a major positional
advantage; a tree breaks up the line of sight between two objectives; a
decorative fire provides visual cover in an otherwise overly open lane; a
curved passage has exactly the right proportions to give cover on one side
while being open on the other, letting players choose when to engage.

In a well-designed map, every part has to play well with everything else, at
least within line of sight. Even small changes to the layout result in
unbalanced maps that lead to frustrating play. Randomly generated maps might
be fun out of novelty, but they won't play well in the long run, at least for
games like Counterstrike.

~~~
nrb
Compared to Fortnite, where every match is a unique experience with the
addition of player-crafted buildings, and the static game map is under
constant transformation each season.

~~~
falsedan
"Guided by human actions" isn't exactly random; chaotic and unpredictable,
sure!

------
ajuc
So, does this algorithm need to remember all already decided tiles forever to
be consistent? Or to recalculate everything from the start each time you
teleport?

I've been working on similar (but much simpler and 2d) algorithm, and the gist
of it was:

\- divide infinite world into 2d chunks of constant size that easily fit in
memory

\- when player is nearby - deterministicaly generate edges of the visible
chunks basing on perlin/simplex noise and random number generator seeded with
the world coordinates of the chunk

\- fill the chunks basing on 2d markov chains trained on hand-crafted map,
starting with the edges going inwards

It needed a lot of training data to produce something that makes sense with
even small number of possible tiles, so in the end I just generated everything
with simplex/perlin noise and some heuristics.

I guess instead of markov chains I could use explicit rules to fill the
chunks, like this seems to do.

But it had the advantage that it was very fast - because you didn't need to
remember everything from the starting place of the player. You could teleport
1000 screens left, and then back, and everything worked fast and regenerated
everything the exact same way.

~~~
marian42
My implementation keeps the entire world in memory, forever. This is obviously
not desirable, but I didn't figure out a way around it. You can't generate a
place again that you have been to because the result would be different.

If you do chunks and generate the edges first, you could run into a situation
where it's impossible to fill the chunk based on it's edges.

For generating terrain, using noise functions makes a lot of sense since they
are local (= don't need to know nearby values to evaluate) and deterministic.

~~~
falsedan
You'd use something like Perlin noise to seed whatever makes the decision
about which tile to pick. Perlin noise is deterministic, so it's perfect to
generate from the (x,y,z) of the tile & you can be certain that the location
will resolve to the same tile if you recalculated the area from scratch.
Divide up your world into areas, and force the centre of the area you're in
and adjacent areas before filling out the area the player is in.

~~~
marian42
If you have two adjacent chunks, collapsing one will impose constraints on the
other one. Even if the RNG part is deterministic, as you suggested, the result
will be different depending on which chunk you collapse first.

~~~
falsedan
I don’t get it. If you have some location between two regions, and you fill it
in starting from some regular point (say, centre of the south-west region),
you will get the same tiling every time.

If you randomly choose a point to start at (like the player avatar’s current
position), then I see that you might get different tilings when regenerating
the location.

------
pugworthy
It's strange, but for many, many years (40 at least?), I have had dreams that
are in places like this. Endless halls, rooms, corridors, and so forth with no
exit.

It is really oddly triggering to run around in this thing.

~~~
eddy_chan
I came here to find your comment. All the vivid dreams I have are either 1)
resitting an exam from 20 years ago and being completely unprepared for it or
2) running around in an endless dreamscape that is created by taking a known
familiar area like a university, my local neighbourhood or a shopping centre
and then scaling it up by using exactly this Wave Function Collapse algorithm.
Funny thing is I can't backtrack in my dreams either.

------
notnot
Admittedly without yet reading but just looking at the pictures, I'd love to
see examples of where it creates patterns of patterns. Sort of like the biomes
in Minecraft: one pattern to draw out where the biomes are, one to fill them
in with content. Could it be made to do patterns of patterns of patterns?

If this were used to create level design where the local view is several
iterations deep of patterns of patterns but not yet all the way to the bottom,
I guess a fractal, that would be a trip.

Awesome work!

~~~
marian42
Each block has a probability of being selected. You could make this
probability location dependent, for example by sampling a noise function. That
way you get something like biomes.

------
J253
Anyone have any experience applying this to the generation of time series
data?

It's easy enough to generate random time series data but this looks like a
promising way to generate interesting signals with prescribed shapes or
features while still being "random".

~~~
ShamelessC
"One of the dimensions can be time. In particular, d-dimensional WFC captures
the behaviour of any (d-1)-dimensional cellular automata."

------
mygo
Imagine creating a Tony Hawks Pro Skater course with this. Can’t learn the
course ahead of time, just have to be a badass street skater.

~~~
ryall
Great minds: [https://arcadia-clojure.itch.io/proc-
skater-2016](https://arcadia-clojure.itch.io/proc-skater-2016)

------
dev_dull
This is a really good example of an uncanny valley. Things like two staircases
side-by-side of different sizes just looks... strange, even though there’s
technically nothing wrong with it.

~~~
mcphage
There's a book called "Possible Palladian Villas" which gets into procedurally
generated houses (in the style of Palladio), and that kind of thing came
up—they'd run their algorithm to generate some houses, and then notice details
in what was generated that were just... off. Not impossible, just... not quite
right, either. Things you wouldn't think about unless you saw plans for a
house that didn't consider it. So they'd tweak their algorithm, and re-run it,
finding new details to fix. It's a cool book.

~~~
roywiggins
I assume McMansion builders use the same design process.

~~~
mcphage
Honestly I think that's giving them too much credit ;-)

------
sspencer
Someone skin this to mimic 'Dark City'! Complete with signs to Shell Beach...

~~~
dwd
Dark City is a great film, though this had me personally thinking more of
Inception.

------
mrfusion
This is great. Can you Please and thank you port it to the vive?

Edit: this might not be too hard. It’s open source and has instructions for
loading it into unity. You might just have to add the vive camera and toolkit.

~~~
marian42
I don't currently have access to a Vive, but I worked with it earlier. All
that needs to be done is add SteamVR to the project and hook up teleportation.
That's it.

~~~
mcphage
If possible, I'd love to be able to run it on a Mac, too.

~~~
marian42
If you (or someone with a Mac) wants to create a build with the Unity Editor,
I'll add it to the itch.io page.

~~~
matuszeg
I have a vive, but I don't have a mac. I could throw the SteamVR plugin in and
get it up on windows, but someone would have to test it on mac

~~~
mrfusion
I’d love to try it on windows if you can do it.

~~~
matuszeg
I'm at work and my Vive is at home, threw together a build that "in theory"
works but I have yet to test it. If you wanna take a stab it you can download
it here.
[https://drive.google.com/drive/folders/1uRP9uan3iViBddmQ5iZ3...](https://drive.google.com/drive/folders/1uRP9uan3iViBddmQ5iZ385yy5c_khnss?usp=sharing)

or check out the source here
[https://github.com/matuszeg/wavefunctioncollapse](https://github.com/matuszeg/wavefunctioncollapse)

I'll update the build (and this comment) and make sure it works later when I
get back to my Vive.

~~~
mrfusion
Awesome! I’m going to fire up the vive Pc tomorrow morning and try it out.
I’ll provably have to sit through an hour of updates :-(

------
trippypig
This is tectonic. If it's purely WFC, I'm really amazed and excited. It's not
the novelty, it's the perfection of each. They remind me of the Laurentian
library by Michelangelo.

[https://goo.gl/images/HHQLUv](https://goo.gl/images/HHQLUv)
[https://goo.gl/images/njGNLC](https://goo.gl/images/njGNLC)

Would love to see the output using Gothic architecture as the input.

~~~
a1369209993
Links are broken (without javascript?), direct links appear to be:

[https://s.hswstatic.com/gif/michelangelo-
buildings-10.jpg](https://s.hswstatic.com/gif/michelangelo-buildings-10.jpg)

[http://www.perfectraveller.com/media/k2/items/cache/2cebfdae...](http://www.perfectraveller.com/media/k2/items/cache/2cebfdae7a8ea5d691033c085990a9d4_XL.jpg)

------
rntz
If this is based on wave-function collapse, what does it do when it hits an
impossible/contradictory state?

(See
[https://github.com/mxgmn/WaveFunctionCollapse](https://github.com/mxgmn/WaveFunctionCollapse)
where it mentions "It may happen that during propagation all the coefficients
for a certain pixel become zero. That means that the algorithm has run into a
contradiction and can not continue.")

~~~
marian42
In the algorithm as it's described on that page, nothing is returned in case
of a failure. I first implemented it so that single blocks would fail and a
white cube would spawn at that position. Now, it uses backtracking. It keeps a
history of its decisions and removes some whenever it reaches a contradiction.

------
bryced
Minecraft has an add on that does this called “The Lost Cities”

“There are highways, bridges, tunnels, a subway system, tons of dungeons with
spawners and loot and so on. ”

[https://minecraft.curseforge.com/projects/the-lost-
cities](https://minecraft.curseforge.com/projects/the-lost-cities)
[https://youtu.be/OZYZ0kV7Uw0](https://youtu.be/OZYZ0kV7Uw0)

~~~
ShamelessC
Does it use WFC or another genration algorithm?

------
msie
This is sufficiently advanced to be magic to me.

~~~
msie
Ok, I understand a little bit more from reading this page:
[https://www.grendel-games.com/procedural-
generation/?lang=en](https://www.grendel-games.com/procedural-
generation/?lang=en)

------
ryanmarsh
This would make so many games much more fun. Imagine if every drop in PUBG was
onto an island with familiar features but not like any before it. Would
definitely level the playing field too.

------
chaoticmass
This evokes a deep House of Leaves kind of horror in me when I play it.
Similar to when I play No Man's Sky or Zoom in on the Mandelbrot set. Infinite
sameness... forever...

~~~
chaoticmass
The unity game engine and everything worked really well though. It immediately
used my HOTAS controllers, which I wasn't expecting. Impressive demo!

------
swiftcoder
How does the infinite part work?

The key problems with Wave Function Collapse tend to be that it gets
exponentially slower as the area you need to collapse increases, and that it
easily gets "stuck" (i.e. finds an combination of tiles that cannot be
resolved, and has to backtrack arbitrarily far).

I assume the speed is solved by operating only on new chunks at the edge of
the explored space, but backtracking across chunks seems... painful.

------
agentultra
I can see echoes of Borges, Kafka, Euclid, Escher, Greg Egan... nice work.
Some existential and strange tales to tell with an environment like this.

------
goodmachine
Pretty cool. Is everywhere reachable on foot? Are there blind interiors that
are not reachable?

------
mrfusion
Does this remember what’s been generated if you come back to an area you’ve
been before?

~~~
marian42
Yes, it does. However the algorithm is not deterministic. If you close the
game and start it again, you will see a different world.

~~~
mrfusion
If you want to shoot me an email I could help port it to the vive? I might
just need a few detailed instructions and I can figure it out from there.

------
scotty79
That's why I hate being a tourist.

\- "Look at this wonderful stairs!"

\- "I see them. They are really uniquely same as any other stairs I've seen so
far. And after all they are ... just staris."

------
crazygringo
For all those of us not running Windows, is there a video anywhere showing
this off?

~~~
kowdermeister
It's on the page:

[https://www.youtube.com/watch?v=VqGDxNsAkKE](https://www.youtube.com/watch?v=VqGDxNsAkKE)

~~~
crazygringo
Thanks! It wasn't before :)

------
lsh
I'm reminded of Greg Bear's The Way. I thought it would be cool if user
generated graffiti could be used as a seed for new generative graffiti so the
further 'in' you go the stranger it gets

------
nixpulvis
Would it be fair to call the "Wave Function" here a case of parallel
constraint satisfaction?

------
mmjaa
This is just a few ghosts and some pellets away from being awesome .. ;)

------
davidw
It's very unrealistic: in a real city people would have shit bricks because of
the total lack of parking, and forced the planning commission to enact big
parking minimums.

