Why I use Wave Function Collapse to create levels for my game
Ғылым және технология
this was so much work i'm about to (wave function) collapse
sorry I used the terms "element", "cell", and "pixel" interchangeably :c
they all mean the same thing!
SEE THE CODE (utilities, etc. coming soon!)
gist.github.com/jdah/ad997b85...
Oskar Stålberg's visualization tool:
oskarstalberg.com/game/wave/w...
Thanks to Maxim Gumin for the original implementation of WFC:
github.com/mxgmn/WaveFunction...
TWITTER: / jdah__
PATREON: / jdah
GITHUB: github.com/jdah
EDITOR: NeoVim
CONFIGS: github.com/jdah/dotfiles
THEME: gruvbox
RESOURCES:
cppreference.com/
learnopengl.com
opengl-tutorial.org
shadertoy.com
stackoverflow.com
0:00 Wave Function Collapse
3:29 Code
12:16 Demo
13:16 Extras!
Пікірлер: 371
A beginners guide to making your first simple game! Chapter one: quantum physics
@petermuller608
Жыл бұрын
You made me lol xD
@Illmare
Жыл бұрын
Chapter 2: Probabilistic String Theory
@9636dev
Жыл бұрын
Chapter 3: Relativity
@DannyLeWasTaken
Жыл бұрын
@@9636dev Chapter 4: Particle physics and the double slit experiment through light simulation
@timothy6966
Жыл бұрын
😂😂😂
Jdh: "I wanna generate new content without having to do Much Work" Also Jdh:
@bosch5303
Жыл бұрын
@Creepi why waste 10h manually doing the work when you can write a program in 10h that will do that work in 2 minutes
@Adowrath
Жыл бұрын
@@bosch5303 More like 5h of manual work saved. Or 2h. But that's how we be. xD
I've seen one or two videos on wave function collapse before, and it's always been one of my favourite ways to generate terrain. Definitely glad to see one of my favourite KZreadrs using it in a real project
@someonewithsomename
Жыл бұрын
so who's one of your favourite youtubers than?
@gachastorys5129
Жыл бұрын
@@someonewithsomename jdh
@whannabi
Жыл бұрын
@@gachastorys5129 smc
People that don't code are being tricked into thinking people code an entire program like this without testing its small pieces a thousand times throughout the process (and at times changing the logic multiple times half-way through haha)
@player111q7
Жыл бұрын
He's just smart
@ZephrymWOW
Жыл бұрын
@@player111q7 He just has put lots of hours into doing it so he doesnt need to double check anymore. It takes lots of effort to get to this level dont just play it off "yeah he is smoret boi lkr dog"
@adrycough
Жыл бұрын
Good, I need every ego boost I can get.
@branthebrave
Жыл бұрын
He's already made this, like he said
@mmdts
Жыл бұрын
@@branthebrave It helps to know that practice makes perfect here. My first programs were relatively simple ones that didn't work as I expected them to. Right now, I can write 1000~2000 LoC of relatively simple logic (low cyclomatic complexity, no recursion) without any mistakes. For code that's heavy on while loops with undefined iteration count, recursive functions (esp. not pure ones), and heavy maths (optimization and whatnot), I still need to think a lot (pen and paper, as jdh shows himself doing in this video) before I write it, and I usually still miss one or two edge cases.
I absolutely love using WFC as a means of world generation! I've always wanted to do this in my voxel game, but each dimension makes the algorithm exponentially slower. I'd definitely look into using it with an LOD perspective; stuff like biome meshes can be generated first in low detail and rendered as a placeholder while structures and environment details are generated in the background.
@jdh
Жыл бұрын
you could maybe also try an approximate approach - collapse/propagate some of the wave elements and use that as an LOD while saving the data for when the player moves closer? 🤔
@morgan0
Жыл бұрын
yea i’ve thought about this for a game i’d like to make eventually. start out with low detail plate tectonics sim for planet-scale coherence, then use wfc to refine the base height and roughness a bit, then figure out biomes, then further refine height and roughness using biome info as well, then do stuff like individual mountain peaks, valleys, small lakes, etc, then probably another pass for final features (still above the scale of individual voxels), and then get a smooth voxel output of the terrain for most stuff with either wfc or noise for detail on rougher areas
@ZephrymWOW
Жыл бұрын
Use layers of WFC. Im working on a game that you start as a quark and the cause / effect generates a playable universe where you can "control" anything. But WFC is not "slow" just stop trying to do everything in a superfunction. break up your 1 WFC into 50 different smaller ones and only run them as you actually need them. I am able to process literally TB worth of data like this in real time. Theoretically scaling up to PB via cassandra.
i remember going down the wave function collapse rabbit hole a while ago, i was surprised at how ingenious it was
@gabitheancient7664
Жыл бұрын
same
@joosephzoostarakajoozoo879
Жыл бұрын
basil pfp tho
i didn't understand a single thing because all of this is way above my level, but i still watched the whole thing because good music and code flashing across screen
Your game is really coming together! It looks amazing already and I can’t wait to see what else you have to implement and the furthering of your terrain generation process.
Wave Function Collapse has actually existed for decades. Age of Empires and Starcraft both used a similar technique in their map tile selection. It just hadn't been named until a couple of years ago.
@The-python-guy
8 ай бұрын
I'm making a AOE style game and use Perlin noise. Because IM better
jdh Is an Indie GOD Developer. You keep impressing me with each and every single video that comes up.
I spent some time with this algorithm myself. It's deceptively simple once you understand what's going on but man when you start getting into the third dimension the thing bogs down hard. Hard enough that I'd probably advocate for pregenerating many random iterations from it in development instead of generating it during end user gameplay.
@jdh
Жыл бұрын
yeah it can get very slow, especially for larger pattern sizes (size 3 -> size 5 more than doubles the time to process each pattern 😬). I've tried parallelising it without success in making it noticeably faster, but pregenerating is definitely a good solution, maybe even storing many partially-collapsed datasets and then doing the last bit of process on demand and with a little bit of randomness.
@newtonbomb
Жыл бұрын
Isn't that a bit of the excitement that comes along with the thought of quantum computers? When we can cost effectively compute and render 3+ dimensional wave collapse algorithms in real time the kind of expansive interactive digital content we will be able to create will be WILD.
@tendies
Жыл бұрын
@@newtonbomb That is some great insight
@newtonbomb
Жыл бұрын
@@tendies Tbf, I'm fairly certain its not an original thought lol. I can't remember for sure, but I vaguely remember reading an article somewhere a couple years ago about the unique possibilities for applications of quantum mechanical computational systems beyond just search algorithms like Shor's or cryptography that is typically discussed, and the usefulness of realtime higher dimensional wave collapse algorithm computation is the one that really stuck with me. Of course what I'd latch onto is how it could help make better games lol
I love your style if presentation. Judging from your previous videos I expect you going down this rabbit how and designing your own quantum computer doing wave function collapse on breadboards :P
I actually love how this looks. Great job! 👍
For a second there I thought you were going to say "I need a physics engine and the best way to do that is from scratch. So here's how I implemented quantum mechanics..."
Can you do a video explaining why you abandoned the ECS in favor of the standard OO approach? From my understanding you can have both with a Component?
THANK YOU FOR CREATING THIS I SPENT WAY TO LONG TRYING TO DO SOMETHING LIKE THIS AND FAILING. this video very well explains a topic that I had trouble with.
I find it really interesting that you went back to oop approach after you initially started with it then transitioned to entity component. Makes me realize why its there in the first place
I've never seen wave function collapse before, this is so cool!
You are one of the greatest coding KZreadrs of all time. You make your videos extremely interesting and I learn a lot from them. Legend.
I have no earthly idea what's going on in this video but I still somehow find it interesting. I really love this type of game and seeing the actual work that goes into making it happen makes me even more interested in it. Can't wait to see the finished product.
It's always a good day when jdh uploads
I really like the effect fading out the wall in chunks gives! One thought I had was that it would be cool if instead of just the walls immediately around the player, walls the character is facing (up to a certain distance) would also fade so you don't need to run along the entirety of a back wall to see what's hidden behind it.
Your videos has always this 5 head vibe that I really like
So happy I subscribed to you a week ago.
Very nice. I'm also very onboard with the plant loving robot theme!
@jdh
Жыл бұрын
glad you approve! when’s the next devlog coming out though 👀
@dvgen
Жыл бұрын
@@jdh Soon™. I got a little delayed taking a second job this summer. Also I get distracted by the technical details, so it is going to have to be a couple of videos. I'll link back to your video one when I talk about implementation.
This is awesome, love the series! I was wondering - you mention you wrote an 'ultra fast mesh instancer' - in terms of speed/optimisation of code is this something you simply learned over time or are there key principles that you follow when writing your code to make sure you are always writing optimally? Cheers!
@kilian9448
Жыл бұрын
@jdh I also want to know
yay new devlog :D i just rewatched the other ones the other day.
It's nice to see more progress since the serializer stream. I've been looking more into C/C++ since then, but concepts (the C++ thing, not concepts as in "ideas") still confuse me. Looking forward to the next video in two months!
@evannibbe9375
Жыл бұрын
Are you talking about operator overloading or templates?
@katto1937
Жыл бұрын
If you mean pointers and all the other abstract concepts you get used to them after a couple hundred lines of code, try it :)
That is awesome, never seen that before and eager to give it a go! Thank you :)
Wait, do you calculate entropy and collapse a pixel or a 3x3 overlapping area?
back in the day, for terrain generation, I used plasma algorithm (aka Diamond-square). How does this one compare?
Those stylized electron orbitals were my desktop background for a while; now it's footage of Venus's surface from the Vanera Lander
Do you think you could estimate how long this whole algorithm took to create? I'd really like to know whether i should even attempt coding something like this for fun, given that i'm a relatively noobie programmer.
If you have compete entropy and all pixels are the same color how do you determine where anything is? Or is that answered at 9:02?
WOW! Nice original idea I've never seen a video like this one before
This is so cool! Where did you get the idea to use wave function collapse for level generation like this?
I've been working on an implementation recently as well. I decided it would be interesting to take the famous dancing links (DLX) sudoku solver and attempt to use it for constraint solver in WFC
ok this is officially by far the most alien (to me) video you've made...
Is it possible to implement smooth camera rotation in your game? Like in Fez when you change the perspective of the world. It would be quite cool visual feature to add.
NEW JDH VIDEO LETS GOOOOOOO
Hm. First video that I genuinely didn't understand. Congrats JDH, you finally did it!
I watched this first when I was incredibly sick, watched it again now and it made just about as much sense
Hello sir I wanted to know which degree or qualification do you need to generate cpu or GPU of your own
what is the font you are using in your terminal? it's so beautiful.
This guy is the reason why Google is getting mad over their employees
@shoeshoe6837
Жыл бұрын
true
@gokusaiyan1128
Жыл бұрын
i don't get it ?
@azizaza8287
Жыл бұрын
@@gokusaiyan1128 this guy is way smarter than google guys
I have no idea what you're saying but you do it really well
Love your stuff! Big help!
You have officially made me feel dumb… I needed this. Thank you.
This is so past my knowledge I barely understand it, I love it.
How do you add specific constraints to the function in the future?
This might be a huge task, but the blinking light on your characters head, it would be an amazing way to ray tracing / some kind of ambient lighting to add some immersion to your levels, right now his headlight seems a bit too distinct from its surroundings
Awesome video :D
Very nice video. I will show it to my students.
I tend to prefer levels design that's not randomly generated, but I have a black and white pixel tileset I had spent weeks creating a ton of cool and complicated geometric designs and structures and variations. Kinda got stuck moving on to creating actual level design with them though, but I think I'll use WFC to construct a bunch of potential level layouts- and I'll take the most promising ones and build more handcrafted levels again from there! I went wild creating a ton of elements I don't have a specific plan for, but I think this algorithm will at least present me with combinations I may not have expected that I can make what I want out of!
what color scheme do you use? it looks awesome
I've only used OMP in Fortran, so maybe its different in C++, but don't you have to specify private and shared variables in the directive? Is it done automatically in C++? For example, in Fortran I would need to declare that i is private and whatever the struct or class or whatever thats being modified would need to be shared, in order to see an actual speed up.
@12345origamimaster
Жыл бұрын
In cpp default modifier for class is private and for struct is public, except for that they are exactly the same
Fantastic to see the generation happening!
OMG he uploaded
Hi man! This is the first video of yours I've watched, and heard you said "just making a game about a ROBOT who loves PLANTS" and immediately I've become immensely interested in what you're going for! Immodestly got flashes of Undertale and OneShot ha, might be different though, super interested! Do you have music figured out yet? I'd like to support you with that while your making the game, have a musician/sound designer yet? I don't post stuff on YT but if you're interested I could definitely do that for your to check out, or can send you some music of mine to see what stuff & style you would like you would like, still cool if you're not thinking about hat now Also is the mic you used, is it the same one in the video? What mic is that?
honey wake up new jdh video just dropped
This is badass!
I somehow understand less than nothing about this, but I'm still very interested in following along and learning from you haha
very cool. I wonder if you can combine different Maps to get some more interesting stuff.
Why do you use raw iterator for loops instead of `for (auto element : iterable)` ?
@jdh
Жыл бұрын
for the Bitset-s, it's because they have two iterators, {begin, end}_on() and {begin, end}_off() to iterate all of the set and unset bits respectively. it should probably be improved though to something like for (auto index : bitset.on()) though!
I love how I have absolutely no idea what is going on, yet it is somehow entertaining
I'm starting my first year at university in a couple of months and I have no clue what the things you said mean. I'll come back to this video again when I know more stuff and see if I can understand lol
really interesting, however i did not understand too much of the implementation ( i am in highschool ). i have done some algorithms but none this difficult. could you recommend any resources on math/programming that could help me understand algorithms like this? Thanks.
@_PranavDesai
Жыл бұрын
Discrete Math, Differential and Integral Calculus and Statistics+Probability is the way to go. Don't overburden yourself with these concepts too much. Learn the basics and if there are courses in your high school, take them up. Have a basic working knowledege because you can always learn more and dive deeper once the situation demands.
@fghjkcvb2614
Жыл бұрын
Look at Sudoku solvers for a simpler implementation of the same Idea Hope that helps ^^ Also doing the steps by hand with some simple examples always helped me understanding complex math in university
U can use wave functions to define a probabilty space where the player mive in. Player measurment chqnges the map
12:19 Did you code a visualisation to visualise coding. Very cool - you made the coding part just as compelling as the visual as it was easy to follow along.
When programmers stack more words onto something like "Wave Function Collaspe algorithm", I can't tell if I understand more or less
how do you edit your videos?
Haha, I like your magic words, funny man
Hey sir, great video! I wonder what font you're using for your neovim? It looks so clean.
@jamieb2563
Жыл бұрын
It looks similar to Roboto Mono
Brain Collapse Function
very cool :) excited to see how this game turns out. may i also ask what the music you play in your videos is called? i like how chilled out it is.
@fraelitecagnin7628
Жыл бұрын
You can search "music for coding" and it's basically the same I think.
I think this algorithm could quite easily be modified somewhat to dictate the overall shape of the entire map by modifying the function that chooses which pattern to collapse a cell into. Say you want to create an objective for a dungeon map (the dungeon map is just a full size image like the ones you generated), and want it to be somewhere in the middle. You can simply look at the distance from the map border when looking at a cell to collapse, and make it so that the further away from the border it is, the higher the chance for it to collapse into the objective. You could even make a minimum distance from the border to become a particular type of cell. You could also overlay a noise map onto the entire grid and vary the chance of a cell's collapse based on the value of the noise map in that spot. Imo, that would be really interesting and (should be) possible to program.
@haha71687
Жыл бұрын
I'm working on a roguelike shooter and we're doing that by doing 2-3 levels of WFC generation. Each level defines the tileset/example bitmaps for the level below it.
amazing work
Just a suggestion regarding the player visibility through walls. If you are making a mask of the player, why do the extra step of raycasting when you can just overlay the player sprite over everything with a bit of transparency. Also, awesome vid, learned a lot! :)
how do you actually compile this? I mean as the project grows it would start taking too long to compile
hey jdh! your videos are aewsome and insipiring, I have always wanted to tinker with a lot of the stuff regarding computer science such as the stuff you do on this channel but a big problem I usually face is the lack of math knowledge and for me a 16 yo guy these stuff can seem aggravating so can you tell where and how can I learn the neccessary MATH needed for CS? and THx
@null6482
Жыл бұрын
Same bro (im so bad at math)
love wave function collapse, so cool
As someone whos been doing code maintenance on a project they did not start I see this as nightmare fuel
May your gardens be vibrant and plentiful, brave little robot
whats the vim color scheme called?
The non-descriptive template parameters with the comments describing what they are made me cry.. why not just name them something similar to that TYPE, DIMS (maybe even DIMENSIONS) PATTERNS, BITSETS ?
Love your videos and i just say your website and its stunning
do you write your own music for the videos?
Cool idea! Though, at 1:45, isn't every generated map not a map at all? Your drawing looks like a cave system, and the generated maps look like noise functions.
What mac do you have?
From where did you learn all this stuff? Can you make a course for beginners?
Thank you, bro!
Jdh is one of those drop what you are doing and watch the new video type KZreadr
What code editor do you use?
I always wondered what the fuss is about the Wave Form Collapse algorithm. Isn't it the same as the Breadth First Search algorithm? As in: you're searching the state space for a state that satisfies the constraints you put on it? I get how the quantum physics framing of it is enticing, but to me it sounds like old wine in a new package. Unless I am missing something crucial. It's still a great algorithm, but with all this hype I feel like we're reinventing the wheel.
What is your Neovim Colorscheme?
14:00 "the ECS hurt more than it helped..." I'm curious, what did the refactor involve? What about the ECS made it difficult to work with? Did you end up removing it entirely?
@truefaceofevil
Жыл бұрын
Also curious about this - and also what the new implementation looks like
I can't even make a start menu and this guy is using quantum physics...
@shiftless215
Жыл бұрын
He started somewhere just like you did so if you work long enough you can get here too
How do you deal with WFC not being guaranteed to terminate?
Lots of people making videos on wave function collapse lately, interesting to see the different way they explain it though
Hello jdh, which language do you use thé most?