This is a custom particle system I wrote in Unity that runs entirely on the GPU using compute shaders. It can get up to around 1 million particles on my crappy laptop before it starts getting any lag.
Compute shaders can’t write and read to the same buffer at the same time, so in order to simulate anything a function is needed on CPU that swaps the read buffer and the write buffer every frame, and this has to be done with every piece of persistent data that is maintained between frames, so a lot of the problems that the program had to overcome arose from that dynamic.
The first iteration of this particle system was the result of my first foray into writing compute shaders on the GPU. Back then it was pretty much just a single function that ran on every particle that caused tem to orbit around a point in space. I eventually went back and expanded it a ton, adding gravity and ground collision, as well as turning it into a real particle system with emission/particle death.
In order to add emission and particle death to the system I needed to pretty much restructure it entirely. Instead of running a single function on every particle in the system, I split the compute shader into two primary functions; one to handle the emission of the particles, and another to handle the simulation of particle
I also wrote the shader that renders the particles as well; the version that I show off here has all the particle as just billboarded triangles. The process of writing the shader was a bit different from writing a normal shader however, as before I got to the vertex-fragment functions I needed to use geometry function to construct the particles geometry first. The shader currently is pretty simplistic and is something I plan to come back to and expand upon more in the future.