Compute Shaders in Bevy

Поділитися
Вставка
  • Опубліковано 25 чер 2024
  • In this video I cover the basics of compute shaders in bevy including how to modify the bevy render graph to add our shader steps. Our end goal is to create a beautiful gpu accelerated particle system but we still have a ways to go on that goal.
    Git: github.com/mwbryant/logic_com...
    Discord Invite: / discord
    Patreon: / logicprojects
    Resources:
    Particle System Blog: gpfault.net/posts/webgl2-part...
    Bevy Hanabi: github.com/djeedai/bevy_hanabi
    Render Graph Git Question: github.com/bevyengine/bevy/di...
    Bevy: bevyengine.org/
    Bevy Cheatbook: bevy-cheatbook.github.io/
    Bevy Examples: github.com/bevyengine/bevy/tr...
    Chapters:
    0:00 Intro
    0:52 What/Why Compute Shaders
    2:01 High Level Overview
    2:55 Main/Render Graph
    5:27 Implementing Node
    10:03 Dispatching the Shaders
    11:33 FromWorld Resources
    13:37 queue_bind_groups
    15:08 Reading back to CPU
    16:30 Duplicating for Rendering
    17:25 Writing the Shaders
    19:44 Final Result
    20:26 Recap/Outro
  • Наука та технологія

КОМЕНТАРІ • 21

  • @patrick1532
    @patrick1532 Рік тому +15

    I really wish there was more documentation and examples on shader integration in bevy, I'm trying to do something relatively simple but unconventional and I don't want to completely tear out the bevy render pipeline and lose out on their parallelism, but most of the bits you actually have to write in their abstractions are standard wgpu boilerplate but more obfuscated and spaghettified because the control flow is not entirely clear from their examples. I'm probably wrong but it's a little frustrating. Thanks for doing your part to help.

    • @logicprojects
      @logicprojects  Рік тому +4

      Yeah the best documentation is to look at how the engine does things. I often have to look at how they handle lights and UI rendering to understand how I could add something myself.

  • @DristusFalchion
    @DristusFalchion Рік тому +8

    So hyped for this. Thank you for making it!

  • @sveinjohansen6271
    @sveinjohansen6271 Рік тому +2

    I was looking for something like this to learn more Rust, and here it is ! thanks, will study this.. Im into particle simulation.

  • @Otakutaru
    @Otakutaru Рік тому +2

    This is soooo niche.... and sooo goood :D

  • @SEOTADEO
    @SEOTADEO 11 місяців тому

    Thanks, so interesting!

  • @feathersm7966
    @feathersm7966 Рік тому +2

    Brilliant info, tried to do this a while back.

  • @michaeljamescollins6800
    @michaeljamescollins6800 Рік тому +1

    thank you

  • @IMPOSING-NOOB2233
    @IMPOSING-NOOB2233 Рік тому +3

    I have a project where FPS drops after I render about 50,000 batched sprites per frame. Looking forward to moving to GPU shader like this. Thanks!!!

  • @rotteegher39
    @rotteegher39 Рік тому +1

    Cool

  • @jeffg4686
    @jeffg4686 Рік тому +1

    Great topic. Are you able to build this with wasm-pack or similar and run with same result?

    • @logicprojects
      @logicprojects  Рік тому +2

      I'm away from my home setup for holidays so I can't test that anytime soon. My intuition would be no, because I've seen some issues with the storage buffers we use and WebGL but the overall compute shader techniques should work. But also I've seen bevy internally use them for point lights so maybe it would work, needs testing

    • @jeffg4686
      @jeffg4686 Рік тому +1

      @@logicprojects - thanks, I'll give it a try this week. Just getting back into this. The compute is where it's at, for sure. A lot more legwork, but worth it. I wonder if they'll be able to do a "derive" for this at some point like they did with the regular shaders. That was nice to see all that come together. they really highlighted the power of the derive. Oh, and thanks again for putting this together. You're not kidding when you say there isn't much documentation out there, and I'm not talking about Bevy. I'm talking about Compute. Combine the two, and there's just a few videos now, so each is much appreciated, and all including this one have been a big help.
      Curious also, if you've looked into, or used "Multi Draw Indirect" functionality in any game frameworks before. I believe this is able to be done through wgpu using compute shaders, but I haven't looked into it yet. I think in some cases can be very helpful performance wise especially for dedicated (not on chip) gpus in scenes with lots of unique objects (not having to round trip to cpu for each) - not sure how much it buys. probably very scene dependent.

  • @redberries8039
    @redberries8039 7 місяців тому

    Re reading buffer data back to cpu: Can your read_buffer fn run as a Bevy 'system' on 'update' or do we need to run it from the Render-World ie render node run() or something similar? Since you were 'vague' on getting the buffer data to the App-World I assume it's called from somewhere like a render node run()?? Have you had any further thoughts on getting the renderworld vec back into the appworld?
    There's Struct bevy::render::render_resource::BufferSlice which has 'pub fn map_async' which looks like it might do something similar to your custom fn, but doesn't help us get the data to the appworld. This is all a bit beyond me so any help would be appreciated.

    • @redberries8039
      @redberries8039 7 місяців тому

      'render_resource::BufferSlice ' is a bust. The buffer being referred to is the command buffer, not any ad-hoc storage buffer

  • @soupborsh6002
    @soupborsh6002 Рік тому +2

    Can you rewrite The Powder Toy with compute shader? It will be amazing!
    This game is FOSS.

    • @jacques-dev
      @jacques-dev Рік тому +2

      I wonder what kind of logic you need for a gas and fluid sim like Powder Toy and how that code would need to run on the GPU

  • @hak0bu
    @hak0bu Рік тому +1

    Actually first :D

  • @airman122469
    @airman122469 9 місяців тому

    Why exactly do you need to copy from the GPU to CPU? The material should just stay on the texture buffer on the GPU.

    • @buren77
      @buren77 8 місяців тому

      Just for debugging purposes

  • @airman122469
    @airman122469 9 місяців тому

    I feel like shaders should just be dealt with in the material render pass.