Why I use Wave Function Collapse to create levels for my game

แชร์
ฝัง
  • เผยแพร่เมื่อ 15 พ.ย. 2024

ความคิดเห็น • 377

  • @user-ex6xc5ox3k
    @user-ex6xc5ox3k 2 ปีที่แล้ว +2447

    A beginners guide to making your first simple game!
    Chapter one: quantum physics

    • @petermuller608
      @petermuller608 2 ปีที่แล้ว +29

      You made me lol xD

    • @Illmare
      @Illmare 2 ปีที่แล้ว +61

      Chapter 2: Probabilistic String Theory

    • @9636dev
      @9636dev 2 ปีที่แล้ว +30

      Chapter 3: Relativity

    • @timothy6966
      @timothy6966 2 ปีที่แล้ว

      😂😂😂

    • @DyslexicFucker
      @DyslexicFucker 2 ปีที่แล้ว +7

      Chapter 4 Subatomic Quantum Mechanics

  • @h1ndlet
    @h1ndlet 2 ปีที่แล้ว +516

    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 TH-camrs using it in a real project

    • @someonewithsomename
      @someonewithsomename 2 ปีที่แล้ว +1

      so who's one of your favourite youtubers than?

    • @gachastorys5129
      @gachastorys5129 2 ปีที่แล้ว +8

      @@someonewithsomename jdh

    • @w花b
      @w花b 2 ปีที่แล้ว

      @@gachastorys5129 smc

  • @Adam-cn5ib
    @Adam-cn5ib 2 ปีที่แล้ว +590

    Jdh: "I wanna generate new content without having to do Much Work"
    Also Jdh:

    • @bosch5303
      @bosch5303 2 ปีที่แล้ว +36

      @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
      @Adowrath 2 ปีที่แล้ว +2

      @@bosch5303 More like 5h of manual work saved. Or 2h. But that's how we be. xD

  • @carterisonline
    @carterisonline 2 ปีที่แล้ว +186

    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
      @jdh  2 ปีที่แล้ว +53

      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
      @morgan0 2 ปีที่แล้ว +9

      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
      @ZephrymWOW 2 ปีที่แล้ว +6

      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.

  • @nix3l_
    @nix3l_ 2 ปีที่แล้ว +144

    i remember going down the wave function collapse rabbit hole a while ago, i was surprised at how ingenious it was

  • @ratio6677
    @ratio6677 2 ปีที่แล้ว +18

    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

  • @MasterHero10000
    @MasterHero10000 2 ปีที่แล้ว +34

    jdh Is an Indie GOD Developer. You keep impressing me with each and every single video that comes up.

  • @ClokworkGremlin
    @ClokworkGremlin 2 ปีที่แล้ว +12

    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
      @The-python-guy ปีที่แล้ว

      I'm making a AOE style game and use Perlin noise. Because IM better

  •  2 ปีที่แล้ว +301

    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
      @player111q7 2 ปีที่แล้ว +7

      He's just smart

    • @ZephrymWOW
      @ZephrymWOW 2 ปีที่แล้ว +32

      @@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
      @adrycough 2 ปีที่แล้ว +7

      Good, I need every ego boost I can get.

    • @branthebrave
      @branthebrave 2 ปีที่แล้ว +8

      He's already made this, like he said

    • @mmdts
      @mmdts 2 ปีที่แล้ว +5

      ​@@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.

  • @sirflimflam
    @sirflimflam 2 ปีที่แล้ว +63

    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
      @jdh  2 ปีที่แล้ว +30

      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
      @newtonbomb 2 ปีที่แล้ว +3

      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
      @tendies 2 ปีที่แล้ว +1

      @@newtonbomb That is some great insight

    • @newtonbomb
      @newtonbomb 2 ปีที่แล้ว +1

      @@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

  • @petermuller608
    @petermuller608 2 ปีที่แล้ว +19

    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

  • @stuin01
    @stuin01 2 ปีที่แล้ว +28

    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..."

  • @Logan-nz5jk
    @Logan-nz5jk 2 ปีที่แล้ว +13

    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.

  • @porx
    @porx 2 ปีที่แล้ว +11

    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
      @evannibbe9375 2 ปีที่แล้ว

      Are you talking about operator overloading or templates?

    • @katto1937
      @katto1937 2 ปีที่แล้ว

      If you mean pointers and all the other abstract concepts you get used to them after a couple hundred lines of code, try it :)

  • @jasoneve
    @jasoneve 2 ปีที่แล้ว +4

    I've never seen wave function collapse before, this is so cool!

  • @alexisrodriguez7127
    @alexisrodriguez7127 2 ปีที่แล้ว +1

    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

  • @dvgen
    @dvgen 2 ปีที่แล้ว +3

    Very nice. I'm also very onboard with the plant loving robot theme!

    • @jdh
      @jdh  2 ปีที่แล้ว +3

      glad you approve! when’s the next devlog coming out though 👀

    • @dvgen
      @dvgen 2 ปีที่แล้ว +1

      @@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.

  • @graydhd8688
    @graydhd8688 ปีที่แล้ว +1

    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!

  • @AwesomeGames56
    @AwesomeGames56 2 ปีที่แล้ว +1

    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.

  • @gwenturo9550
    @gwenturo9550 2 ปีที่แล้ว

    Those stylized electron orbitals were my desktop background for a while; now it's footage of Venus's surface from the Vanera Lander

  • @MagicThanos7
    @MagicThanos7 2 ปีที่แล้ว +2

    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

  • @melonfromthevoid1377
    @melonfromthevoid1377 ปีที่แล้ว

    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.

  • @wearr_
    @wearr_ ปีที่แล้ว +1

    I watched this first when I was incredibly sick, watched it again now and it made just about as much sense

  • @sippingtexastea
    @sippingtexastea 2 ปีที่แล้ว +2

    It's always a good day when jdh uploads

  • @Trupen
    @Trupen 2 ปีที่แล้ว +1

    Awesome video :D

  • @smellthel
    @smellthel 2 ปีที่แล้ว +1

    You are one of the greatest coding TH-camrs of all time. You make your videos extremely interesting and I learn a lot from them. Legend.

  • @av3stube480
    @av3stube480 2 ปีที่แล้ว +2

    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
      @haha71687 2 ปีที่แล้ว +1

      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.

  • @anispinner
    @anispinner 2 ปีที่แล้ว +7

    Brain Collapse Function

  • @Sushant-ot1fp
    @Sushant-ot1fp 2 ปีที่แล้ว +84

    This guy is the reason why Google is getting mad over their employees

    • @shoeshoe6837
      @shoeshoe6837 2 ปีที่แล้ว +1

      true

    • @gokusaiyan1128
      @gokusaiyan1128 2 ปีที่แล้ว +7

      i don't get it ?

    • @azizaza8287
      @azizaza8287 ปีที่แล้ว +1

      @@gokusaiyan1128 this guy is way smarter than google guys

  • @BenDol90
    @BenDol90 2 ปีที่แล้ว +31

    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?

  • @Kestrel_
    @Kestrel_ 2 ปีที่แล้ว

    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.

  • @smalllixin
    @smalllixin ปีที่แล้ว +1

    Unbelievable C++ skill ever seen...

  • @timothy6966
    @timothy6966 2 ปีที่แล้ว +1

    So happy I subscribed to you a week ago.

  • @wholesome8691
    @wholesome8691 2 ปีที่แล้ว +1

    I like your words magic man

  • @helio6839
    @helio6839 2 ปีที่แล้ว +2

    If it fails, just try again until it doesn’t fail. Works every time.

  • @chopkeys
    @chopkeys 2 ปีที่แล้ว +3

    NEW JDH VIDEO LETS GOOOOOOO

  • @nevokrien95
    @nevokrien95 2 ปีที่แล้ว +1

    U can use wave functions to define a probabilty space where the player mive in. Player measurment chqnges the map

  • @davidfails2866
    @davidfails2866 2 ปีที่แล้ว +1

    You have officially made me feel dumb… I needed this. Thank you.

  • @jakubmichalenko7990
    @jakubmichalenko7990 2 ปีที่แล้ว

    Your videos has always this 5 head vibe that I really like

  • @hamadaag5659
    @hamadaag5659 2 ปีที่แล้ว

    This is so past my knowledge I barely understand it, I love it.

  • @eppiox
    @eppiox 2 ปีที่แล้ว +2

    As someone whos been doing code maintenance on a project they did not start I see this as nightmare fuel

  • @almahnak12
    @almahnak12 2 ปีที่แล้ว +2

    When programmers stack more words onto something like "Wave Function Collaspe algorithm", I can't tell if I understand more or less

  • @thomaskarbowiak540
    @thomaskarbowiak540 2 ปีที่แล้ว

    I love how I have absolutely no idea what is going on, yet it is somehow entertaining

  • @vaquarshaikh9790
    @vaquarshaikh9790 2 ปีที่แล้ว +3

    bro please teach us on youtube or a course or whatever man , you are a legend

  • @JakubSK
    @JakubSK 3 หลายเดือนก่อน

    I wrote my entire wfc mechanism in 50 lines of code. Works flawlessly.

  • @slothinahat
    @slothinahat 2 ปีที่แล้ว +3

    OMG he uploaded

  • @eboatwright_
    @eboatwright_ 2 ปีที่แล้ว

    I actually love how this looks. Great job! 👍

  • @CedarGroveOrganicFarm
    @CedarGroveOrganicFarm 2 ปีที่แล้ว +1

    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

  • @williamn1055
    @williamn1055 2 ปีที่แล้ว

    I have no idea what you're saying but you do it really well

  • @outcast-festival
    @outcast-festival 2 ปีที่แล้ว +1

    honey wake up new jdh video just dropped

  • @grantwilliams630
    @grantwilliams630 2 ปีที่แล้ว +1

    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

  • @williamist
    @williamist 2 ปีที่แล้ว

    yay new devlog :D i just rewatched the other ones the other day.

  • @fonkinstubbleduck9163
    @fonkinstubbleduck9163 2 ปีที่แล้ว

    Hm. First video that I genuinely didn't understand. Congrats JDH, you finally did it!

  • @ganglians
    @ganglians 2 ปีที่แล้ว

    May your gardens be vibrant and plentiful, brave little robot

  • @theseusRJ7
    @theseusRJ7 2 ปีที่แล้ว +4

    Haha, I like your magic words, funny man

  • @shinrakishitani1079
    @shinrakishitani1079 2 ปีที่แล้ว

    Lots of people making videos on wave function collapse lately, interesting to see the different way they explain it though

  • @taurgoo3670
    @taurgoo3670 2 ปีที่แล้ว

    WOW! Nice original idea I've never seen a video like this one before

  • @jamesmorrison9893
    @jamesmorrison9893 2 ปีที่แล้ว +1

    Jdh is one of those drop what you are doing and watch the new video type TH-camr

  • @chriswaller8780
    @chriswaller8780 2 ปีที่แล้ว +1

    Annunciation will help your viewers' comprehension immensely

  • @teunissenstefan
    @teunissenstefan 2 ปีที่แล้ว +1

    I'm simple: I see vim, I subscribe.

    • @jtms1200
      @jtms1200 2 ปีที่แล้ว +1

      i'm simple: I see comment about vim and I reply with enthusiastic approval

  • @PorkSKing
    @PorkSKing 2 ปีที่แล้ว +1

    love wave function collapse, so cool

  • @R4ngeR4pidz
    @R4ngeR4pidz 2 ปีที่แล้ว +3

    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 ?

  • @Assassin_Droid
    @Assassin_Droid 2 ปีที่แล้ว +25

    I can't even make a start menu and this guy is using quantum physics...

    • @shiftless215
      @shiftless215 2 ปีที่แล้ว +5

      He started somewhere just like you did so if you work long enough you can get here too

  • @Skeffles
    @Skeffles 2 ปีที่แล้ว

    Fantastic to see the generation happening!

  • @pablojosegorigoitiacastro568
    @pablojosegorigoitiacastro568 2 ปีที่แล้ว

    Very nice video. I will show it to my students.

  • @TheShelfman
    @TheShelfman 2 ปีที่แล้ว

    I somehow understand less than nothing about this, but I'm still very interested in following along and learning from you haha

  • @JohnnySix
    @JohnnySix ปีที่แล้ว +1

    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.

  • @OneEgg42
    @OneEgg42 2 ปีที่แล้ว +1

    no clue what you just said but i like it

  • @bumpwavy
    @bumpwavy 2 ปีที่แล้ว

    Im deeply interested in this procedural generation techniques but the more games i play where the map was designed by a person the more i wish we would have more games like that.

  • @yqqbey8779
    @yqqbey8779 2 ปีที่แล้ว

    Feels like some kind of 2D Markov's chain.

  • @mfucek_
    @mfucek_ 2 ปีที่แล้ว +1

    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! :)

  • @Test-iv4pm
    @Test-iv4pm 2 ปีที่แล้ว

    The generated map at 2:55 makes me want to play a dungeon crawler where each dungeon takes weeks to complete.

  • @mkrichey1
    @mkrichey1 2 ปีที่แล้ว

    That is awesome, never seen that before and eager to give it a go! Thank you :)

  • @darkerrorcode
    @darkerrorcode 2 ปีที่แล้ว

    Idk what i just watched but im impressed

  • @legendrags
    @legendrags ปีที่แล้ว

    this guy making an entire commercial quality game using native code:
    me struggling to make a game in godot:

  • @its_fzx5275
    @its_fzx5275 2 ปีที่แล้ว +4

    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
      @null6482 2 ปีที่แล้ว

      Same bro (im so bad at math)

  • @JellySword8
    @JellySword8 2 ปีที่แล้ว +5

    Sounds simple enough, now to teach it to middle schoolers in Scratch

  • @abogame6852
    @abogame6852 2 ปีที่แล้ว

    Love your stuff! Big help!

  • @Stich270
    @Stich270 2 ปีที่แล้ว +1

    very cool. I wonder if you can combine different Maps to get some more interesting stuff.

  • @ЭнрикеЧурин
    @ЭнрикеЧурин 2 ปีที่แล้ว +2

    I still can't stop marveling your coding skills, it seems impossible. Like how could you think of the whole WFC algorithm implementation and code it real time, it takes me many tries and iterations to code even a simple algorithm, i can't keep it all in my mind all at once

    • @Zuckerkome
      @Zuckerkome 2 ปีที่แล้ว +7

      He did not code it in one go as seen in the video. It is mentioned at 12:11.

  • @rohitkushvaha2481
    @rohitkushvaha2481 ปีที่แล้ว

    It's all got out of my mind but looks cool

  • @klutch4198
    @klutch4198 2 ปีที่แล้ว +1

    This is badass!

  • @palmberry5576
    @palmberry5576 2 ปีที่แล้ว

    So basically, you have the best minesweeper ai make video game maps

  • @elin4364
    @elin4364 2 ปีที่แล้ว +1

    This is so cool! Where did you get the idea to use wave function collapse for level generation like this?

  • @38abrahams
    @38abrahams 2 ปีที่แล้ว +1

    Wave function collapse? Oh yeah, super easy! [opens vim]..

  • @zix2421
    @zix2421 3 หลายเดือนก่อน

    I love this thing

  • @sirberg4599
    @sirberg4599 2 ปีที่แล้ว +2

    i like your funny words magic man 😂

  • @paradoxicalegg6112
    @paradoxicalegg6112 ปีที่แล้ว

    that is actually so cool what

  • @aSingularPhoton
    @aSingularPhoton 2 ปีที่แล้ว +1

    So you’re just future future proofing

  • @NavoNova
    @NavoNova 2 ปีที่แล้ว +1

    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
      @kilian9448 2 ปีที่แล้ว

      @jdh I also want to know

  • @deinvater42069
    @deinvater42069 2 ปีที่แล้ว

    Thank you, bro!

  • @ezrapierce1233
    @ezrapierce1233 2 ปีที่แล้ว

    When you stumble onto an awesome channel out of nowhere

  • @DerSolinski
    @DerSolinski 2 ปีที่แล้ว +1

    Wow never heard before that somebody would get rid of a ECS before that's a first.
    But I guess it can be cumbersome.

  • @LineOfThy
    @LineOfThy 2 ปีที่แล้ว

    I too dabble in a bit of quantam physics when making my game

  • @wmd2556
    @wmd2556 2 ปีที่แล้ว

    amazing work

  • @star80doessdastuff
    @star80doessdastuff 2 ปีที่แล้ว +1

    Bad summary: *complex circuit board generator*

  • @damonjones5726
    @damonjones5726 2 ปีที่แล้ว

    Who knew an algorithm could be viral

  • @agent-33
    @agent-33 2 ปีที่แล้ว +2

    Man... the amount of time to practice coding until he reach that level is probably insane.

  • @owfan4134
    @owfan4134 2 ปีที่แล้ว +1

    *A R E Y O U **_C L I C K I N G_** I N V I M ?*

  • @chelonianegghead274
    @chelonianegghead274 2 ปีที่แล้ว +1

    you should call it robotanist