Slime Mold Physarum Simulation - C++ & Compute Shaders

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

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

  • @DisgruntledPeasant
    @DisgruntledPeasant 7 หลายเดือนก่อน +1

    Wow!
    I love organis systems in code, would you ever do a tutorial series, at least outlining the concepts?

    • @marf1610
      @marf1610  7 หลายเดือนก่อน +2

      Check out Sebastian Lague's video titled 'Coding Adventure: Ant and Slime Simulations' He goes into great detail on how make this.

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

    I bet this would make a kickass visualiser

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

      Yooo it would. I was thinking it would be cool to pull data from music and use it to influence the simulation. I might look into that.

  • @fnbs-l9o
    @fnbs-l9o 8 หลายเดือนก่อน +1

    Bro did you find the code to life? this is insane...

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

    Very Nice

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

    they make reaction diffusion structures!

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

    coooooooooooooooooooollllll!

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

    looks amazing! when i try to do it i can see all the little particles still, but whenever i increase diffusion there's an ugly glowing effect, how did you make is look so clean?

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

    Amazing video! I took inspiration from this and followed the process you described in one of the comments to come up with a decent simulation.
    However, I feel like it's not as optimized as it could be, since both you and the sagejenson page have achieved much better results. Mine manages 30fps on 2560x1440, 1 million agents (graphics card is 1660Ti). BUT that's only if i make the blur kernel size 1, and sensor size 1. If I make it 3 then it can't handle it anymore i.e. the output becomes garbage, and 5fps).
    Would you mind giving some optimization tips?

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

      Hey nice job getting it working at all! Working with the GPU can be immensely frustrating, tedious, and opaque.
      I guess I never linked the code or a build in the video because I wanted to improve it before sharing it.
      I have added links in the video description to the code so you can review and compare if you'd like. Also linked is a build you can download and run to do a direct comparison of your simulation and mine. There isn't much as far as documentation as of now so you'll have to mess with the sliders to see what each one does.
      As far as optimizations, its honestly been awhile since I did this and nothing comes to mind immediately. Although increasing sensor size does tank performance because the amount of cells to check each frame increases exponentially. So that is expected.

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

      @@marf1610 Thanks for replying! I've managed to find out so far that mine wasn't actually running on the nvidia gpu (whoops, rookie mistake) - if I fix that by adding "__NV_PRIME_RENDER_OFFLOAD=1 __GLX_VENDOR_LIBRARY_NAME=nvidia" to the command line then the performance doubles. Also mine uses a vertex shader on a texture to represent the agents instead of a compute shader like yours (as in the gpuParticleSystemExample), so that might not be optimal; I'll look into it.

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

    Would you mind releasiing it so we can make our own mold?

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

      Hey I have linked a build you can download and launch. Unfortunately its not in a very documented and user friendly state. But there are a bunch of sliders you can use to modify parameters in the app for dynamic simulations.

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

    whats GLSL how did you use it for this? I always thought you needed opengl for C++ graphics

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

      GLSL stands for 'Graphics Language Shader Language'
      This is the language that OpenGL reads to perform drawing and data manipulation on the GPU. So 'shaders' or shader files are written in GLSL. This is the code that runs 'on' the GPU.
      You have to use OpenGL commands to do things like initializing data structures, reserving space, sending data to be stored on the GPU, load the shader files, etc and this is done using OpenGL commands in C++. This code runs on the CPU.
      I used 'OpenFrameworks' which has a bunch of classes that make working with OpenGL really easy. Knowing how to use the correct OpenGL commands and in the right sequence and in the right state is really challenging and a lot to learn so OpenFrameworks simplified that a lot for me.
      If you google 'openframeworks introducing shaders' click the first link (should say ofBook) and that is where I got started with all of this.

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

      @@marf1610 thanks so much for the in depth and thoughtful response :)

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

      @@marf1610 thank you so much for taking the time to respond. This was really helpful

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

      @@8ngine For sure. Good luck with your experimenting!

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

    I am very interested in trying to make my only slime mold simulation but I have never worked with OpenGL, GLSL, or Open Framework before. Do you have any suggestions on how I could start out?

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

      Unfortunately I was not able to find any single resource that helped me figure out how to do this.
      I can tell you the process which I went through to build this though.
      I watched Sebastian Lague's slime mold video which inspired me to want to build my own. And then I made a simple implementation in p5.js to understand how to get the algorithm working with the data structures. This was helpful prior knowledge for when I ported it to c++ and GLSL.
      OpenFrameworks has a good tutorial for setting up shaders and GLSL. Google "OpenFrameworks Introducing Shaders" and the ofBook link will walk you through that. OpenFrameworks has some built in classes you can use that will make working with shaders easier.
      The really challenging part is understanding data structures on the GPU, and how to upload/access/manipulate data in them. Additionally, because you can't set breakpoints in GLSL code it can be really hard to debug or understand what is going wrong. You can't see values at runtime and a lot of times errors are swallowed and you don't even know if/when something is going wrong.
      Understanding the following data structures (and the OpenFrameworks wrapper classes) will be helpful for figuring out how to make this simulation work.
      You should know what a Shader Storage Buffer Object (SSBO) is. The OF wrapper class for this is ofBufferObject. I used this data structure for both the trail map and the particle buffer (logic performed in the compute shader). And then used a fragment shader to draw the data from the trail map to the screen. SSBOs are unique because they are high throughput and able to read and write data in the same draw call. (Whereas Images and Textures may be only read or only write).
      I referenced the Examples provided by OpenFrameworks. Go to the OpenFrameworks github repository. Open the examples folder, open the 'gl' folder and the 'gpuParticleSystemExample' was particularly helpful in being able to figure this out.
      Working with GLSL can be very confusing and frustrating but satisfying when you get it to work the way you expect. I spent many hours just reading about data structures before it started to make sense.
      Good luck! If you have further questions let me know.

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

      @@marf1610 Thank you for taking the time to write out such a thorough comment. I'll take a look at all the resources and get back to you if I ever get it working.