How to Render MILLIONS of Blades of Grass Efficiently in Godot (godot 3.X)

Поделиться
HTML-код
  • Опубликовано: 8 сен 2024

Комментарии • 39

  • @leonstansfield
    @leonstansfield  2 года назад +53

    Hi I recently noticed something about the scatter plugin which is pretty important. It seems to store each blade of grasses transform in the scene file, making larger scenes (like the one in my repo) absolutely massive... like over 100MB massive. It is still a great solution for smaller scenes though.
    In other news I saw this new plugin called spatial gardener which is a great solution for larger scenes. I haven't tried it out much yet, but it looks like it has automatic chunking of multi mesh instances and has built in LOD switching as well... It can be used for more than just grass as well, with the demo showing off an entire forest instanced using the plugin. It seems like a really good option and the demo runs smoothly in a large scene, make sure to check it out!
    Link: github.com/dreadpon/godot_spatial_gardener

    • @norodix6857
      @norodix6857 Год назад +4

      I was also missing these features from scatter so I decided to make them. The chunking was done a couple months ago and its called split multimesh in scatter. Just yesterday I also created a PR that enables you to not save the transforms of the instances to disk but generate them on the fly when loading the scene so they only live in ram. This obviously means it is only practical in case of modifiers that are quck to generate, like random distribution.
      Separating the chunking to a different thread is a good idea, maybe Ill implement it later! For now, it doesnt seem to impact the game much.
      A nice way to deal with the blocky edge of the chunks is to lower the grass blades in shader by the time they are about to be culled. That leads to a quite nice effect where the grass blends into the texture below it.

  • @psuw
    @psuw 2 года назад +29

    You can speed up the chunking system at the end of the video by using math and hashmaps/dictionaries. Assign each chunk with a chunk position.(0,0),(1,0)... Then keep a small list of all active chunks. (Chunks around the player). So if the player is at global 12.5,5.4 and the chunk size is 10 -> 12.5/10 = 1, 5.4/10= 0 => (1,0). Then get the all chunks with in that area (x+cull ->x -cull,y+cull->y-cull) and update the active map. This way time complexity remains constant (O(1) per chunk and total O(4*(cull**2)). This way you dont need a timer to check for the grass but rather have to check if the players chunk position changed.
    This technically also works for infinite worlds.
    Edit : this should work if i didnt do a thinking mistake.

  • @davidmurphy563
    @davidmurphy563 2 года назад +44

    You can also do it with draw passes. It's quite good for clouds too. You start on the surface of the mesh and put a load of green dots surrounded with alpha. Then in the next pass you raise it a bit and add a little movement. Repeat until you have grass. As long as you're not looking sideways on it looks pretty good and it's dirt cheap.

    • @tehcookiemon
      @tehcookiemon 2 года назад +1

      is there a video of this technique in action?

    • @danyCD17
      @danyCD17 2 года назад +3

      Isn't that also used for fur in games, also called "alpha shell"

    • @KillahMate
      @KillahMate 2 года назад +1

      @@danyCD17 yes. It's called shells because usually the dots are an alpha texture on concentric polygonal shells that surround the object.

  • @addmix
    @addmix 2 года назад +17

    Just in the past few days someone contributed multimesh splitting to Scatter, so now it will automatically "chunk" the multimesh nodes.

    • @leonstansfield
      @leonstansfield  2 года назад +6

      That is super cool! Thanks for letting me know!

  • @avivshvitzky2459
    @avivshvitzky2459 2 года назад +2

    The bg music is perfect. I can sit down with a cup of coffee, relax, and listen to your explanation

  • @Snikur
    @Snikur 2 года назад +5

    Instead of looping through all the grass and cull per timeout, you could do 1 (or more) chunk per frame to smooth it out.

    • @leonstansfield
      @leonstansfield  2 года назад +2

      This is true and would be optimal. However I could not be bothered haha. This is the best solution tho

  • @thygrrr
    @thygrrr Час назад

    Ace Roller mentioned!

  • @boerbol9422
    @boerbol9422 2 года назад +1

    Thanks so much for this great tutorial. This is the kind of tutorials we need in the Godot community. It was so helpful.

  • @Uwishiii
    @Uwishiii 2 года назад +3

    Awesome video! Really entertaining on top of being helpful :)

  • @HeyItsDoodler
    @HeyItsDoodler 2 года назад +4

    Just noticed the description engineering 🤣

  • @warsin8641
    @warsin8641 11 месяцев назад +1

    I like how grass has been one of the most unexpectidly hardest things I've had to do 🤣

  • @AnnCatsanndra
    @AnnCatsanndra 10 месяцев назад

    Excellent video! Thank you!

  • @ThiccestMayo
    @ThiccestMayo 2 года назад

    you are almost at 1k! Good job!

  • @user-og6hl6lv7p
    @user-og6hl6lv7p Год назад +3

    You really should be using "distance_squared_to" instead of "distance_to" for this particular scenario. It is even recommended by the documentation if you have read it. Precision doesn't matter because you're just activating/de-activating giant "chunks, you don't need to calculate collision or anything. You will most likely need to scale the resulting value. You should seriously do this straight away, because although it may run well initially, you're gonna have problems when you start adding AI and collision.
    Use "distance_squared_to". Do it.

  • @HeyItsDoodler
    @HeyItsDoodler 2 года назад

    Subscribed!
    Race to a thousand

  • @Aragubas
    @Aragubas 2 года назад

    raccoons are so cute!

  • @sanaysspace
    @sanaysspace 6 месяцев назад

    A Short Hike? ❤

  • @narrenschlag
    @narrenschlag 2 года назад +1

    Good video

  • @lecloutpanda
    @lecloutpanda 2 года назад

    well made

  • @Asteinkai
    @Asteinkai 2 года назад +1

    what's the music in background uwu ?

    • @leonstansfield
      @leonstansfield  2 года назад +1

      Mix between animal crossing, Zelda and a short hike in this one!

  • @yudi8204
    @yudi8204 2 года назад

    📌

  • @Allen-cx6yi
    @Allen-cx6yi Год назад

    where can i get the grass blades?

    • @leonstansfield
      @leonstansfield  Год назад

      I just made them in blender, they are also in the github repo in the description.

  • @sakamotoshinonome
    @sakamotoshinonome 2 года назад +3

    Am I first ?

    • @davidmurphy563
      @davidmurphy563 2 года назад +3

      No, that was Neil Armstrong.

    • @leonstansfield
      @leonstansfield  2 года назад +3

      No it was yuri gagarin

    • @davidmurphy563
      @davidmurphy563 2 года назад

      @@leonstansfield I was going to say we were both wrong and it was Ernest Shackleton but it turns out it was Billy Simmons in third grade behind the bike sheds.

  • @FriskDreemurr66669
    @FriskDreemurr66669 Месяц назад

    outdated