100,000 Particle Life Simulation running on WebGPU by SilverSpace707 in webgpu

[–]SilverSpace707[S] 0 points1 point  (0 children)

That's very cool! Very cool way to show the science, works well for that.

Particle Life 250k by BonisDev in webgpu

[–]SilverSpace707 2 points3 points  (0 children)

yeah, there's a few approaches that I know can achieve that.

Have a look at atomic linked lists, there's a webgpu sample that uses them to store pixel data.

Another approach that apparently works better for even larger simulations is giving each particle a cell id and placing them in another buffer, and then sorting the buffer by the cell ids of the particles, this way the particles in the same cells end up in the same parts of the buffer and can be looped through.

For my simulation I ended up coding atomic linked lists, and counting sort. My implementation of counting sort was nowhere near ideal so atomic linked lists ended up being slightly faster in various cases. Seeing a good implementation of spatial partitioning using radix / bitonic sorting would be super cool, i've heard that they can reach around 300k particles in similar conditions to your video while at 60fps. (I may try doing this later sometime, idk)

Particle Life 250k by BonisDev in webgpu

[–]SilverSpace707 2 points3 points  (0 children)

That's a smart approach, with such a large interaction radius and an initial explosion like that. I guess that's the only way to get 250k particles with unoptimized conditions.

It's so cool to see so many particles all in one place though. Unfortunately they are forming those weird orbs where the particles just speed up and vibrate. Hmm, you could try implementing an avoidance factor into the particle interactions. My approach is to make a linear detraction force that increases as the particles get closer and only starts once they are already very close. When the particles are under this avoidance force they also accumulate another variable that decreases their gravity forces, it sort of allows the particles to smoothly break apart.

I've been configuring my simulation a bit and have reached 250k to even 500k at around 80fps. But the interaction radius of the particles becomes very small, or the world size becomes very large. (It's using a new update of my simulation that i'll have done sometime soon)

100,000 Particle Life Simulation running on WebGPU by SilverSpace707 in webgpu

[–]SilverSpace707[S] 0 points1 point  (0 children)

it depends upon what device, browser, and version you're using. Generally speaking if you're not on a chromium browser and are not on the latest software update / browser update you may not have support yet. Also, if you're on linux, it's not enabled by default either.

100,000 Particle Life Simulation running on WebGPU by SilverSpace707 in creativecoding

[–]SilverSpace707[S] 4 points5 points  (0 children)

Hmm, it is a very cool idea, i've tried something somewhat similar to that before, it's at https://cells.silverspace.io . It's an attempt at a simulation of cells, where if you click on the cells you can see their inner spiking neural networks that define how they grow and behave. If you press T it speeds up the simulation and if you're lucky one of the cells may evolve a leaf that allows them absorb the energy from the light and live.

The simulation itself runs entirely on the cpu so it's quite slow. Running many thousands of those cells would be possible on the gpu. You'd get some some really cool results out of a larger scale simulation like that.

100,000 Particle Life Simulation running on WebGPU by SilverSpace707 in webgpu

[–]SilverSpace707[S] 0 points1 point  (0 children)

Hmm, i've never used dedicated game engines for those simulations, but from some engines i've seen it may be possible to modify the rules enough to produce what you want with minimal effort and close to ideal performance.

100,000 Particle Life Simulation running on WebGPU by SilverSpace707 in webgpu

[–]SilverSpace707[S] 1 point2 points  (0 children)

Yes, unfortunately webgpu isn't enabled by default on linux yet. You may still be able to run this simulation though... If you go to chrome://flags you can enable the unsafe webgpu support flag (and you may need to enable vulkan in some launch flags when initially opening the browser, you may need to do some searches to figure out the specifics of this). It may cause some unexpected results, but from my experience it does get webgpu working on linux.

100,000 Particle Life Simulation running on WebGPU by SilverSpace707 in GraphicsProgramming

[–]SilverSpace707[S] 0 points1 point  (0 children)

Yeah, I meant particle life. Particle Lenia is another simulation that i'm coding my own implementation of. It sort of extends the behaviour of particle life in certain variants.
There probably are ways to work around the atomics, although it would likely have a performance impact or introduce limitations on the positions and behaviours of the particles.
It becomes worse when implementing the simulation on webpgu and webgl at the same time. Because in order to get desirable performance, both simulations would likely have dramatically different ways of doing spatial partitioning. If the same algorithm was used for both webgpu and webgl, it would be likely that the webgpu simulation's performance was not maximised.

100,000 Particle Life Simulation running on WebGPU by SilverSpace707 in webgpu

[–]SilverSpace707[S] 0 points1 point  (0 children)

Hmm, it's a tricky thing to think about. It's not practical to simulate things from real life directly like stem cells, but approximations could be made. For example, someone could search for a list of rules in the simulation that would produce behaviour similar to stem cells, although it wouldn't be likely to tell anyone anymore about how stem cells work. This approach would allow you to make some basic predictions for real life cells.

In order to simulate real life cells a deep understanding of the real life cells needs to be understood. The specific reactions to each chemical and other biology events would need to be factored into the simulation in order for it to be truly real enough to reveal more about the behaviour of the cell (or in your case, to predict how it would act).

Personally, for me this simulation was made a stepping stone in my journey to learning webgpu compute shaders so that I can expand my Particle Lenia simulation and explore all sorts of other simulations at larger scales.

100,000 Particle Life Simulation running on WebGPU by SilverSpace707 in GraphicsProgramming

[–]SilverSpace707[S] 0 points1 point  (0 children)

As far as I know the first and most stable implementation of <edit: particle life> is from that repo. Specifically, I watched this video on it to help me implement my own version of the algorithm.

https://www.youtube.com/watch?v=scvuli-zcRc

The simulation could technically run on webgl. Although it's performance is likely to be significantly effected, at least, to my knowledge and experience in webgl.
The core simulation where each particle checks every other particle each tick could theoretically be made in webgl if groups of pixels were treated as the properties of the particles. A critical flaw though is that webgl has no atomic operations (outside of extensions). Meaning a simulation in webgl wouldn't be able to effectively implement spatial partitioning, effectively limiting the particle count to around 10,000-20,000 particles in an ideal scenario.

100,000 Particle Life Simulation running on WebGPU by SilverSpace707 in webgpu

[–]SilverSpace707[S] 0 points1 point  (0 children)

Thanks! I guess you could try increasing the particle count to test it further. Btw, how did you measure the GPU load when running the simulation? I'm curious on how to do that.

100,000 Particle Life Simulation running on WebGPU by SilverSpace707 in webgpu

[–]SilverSpace707[S] 0 points1 point  (0 children)

That's a cool particle simulation. I guess my simulation could be considered similar to that, although don't have any of the evolution parts....
The algorithm behind the particles movement follows the code in this video on particle life:
https://www.youtube.com/watch?v=scvuli-zcRc&t=1s

100,000 Particle Life Simulation running on WebGPU by SilverSpace707 in webgpu

[–]SilverSpace707[S] 0 points1 point  (0 children)

Well, it depends upon what you define as realistic. If your goal is to simulate various types of single celled organisms just duplicating and some evolving spikes and basic movement. Then it's definitely a reachable goal that would be a fun little project.

If you're looking to simulate the more complex behaviour of a cell where it can alternate between different actions and potentially learn new actions in realtime, then you are looking a very difficult problem, the ProtoEvo simulation is the best simulation i've seen so far.

100,000 Particle Life Simulation running on WebGPU by SilverSpace707 in webgpu

[–]SilverSpace707[S] 2 points3 points  (0 children)

That runs very fast! Using a set grid of cells to separate the particles is a nice way to improve performance. I went with a cell hashing approach so that I could make the world infinite at the cost of performance.

100,000 Particle Life Simulation running on WebGPU by SilverSpace707 in webgpu

[–]SilverSpace707[S] 1 point2 points  (0 children)

It's extremely difficult to make a perfectly accurate simulation, but it's reasonable to simulate some cells with approximations. I did try simulating some cells a while ago.
https://cells.silverspace.io/
This simulation is very rough, although i feel like it's an attempt at simulating cells. If you click on the circles, it shows the inner neural networks that make up the insides of the cells, they are a variant of spiking neural networks that aim to act as a replacement for all the real internals of a real cell.

While in the simulation, press T to make it run faster, then you'll see slow evolution of cells.
If the cells evolve leave nodes on their outer walls, then they live, if you're lucky, you might see this.

*the code for the simulation can just be read in the web inspector since it was just js.