Custom Particle System

My question is a bit weird, but I figured by posting it in this section there’s a higher chance someone will be able to help.

I’m building from scratch kind of a Custom Particle System using the C# Job System, it still needs a lot of optimization but right now the biggest bottleneck seems to be handling dead particles. I ran a very simple benchmark and comparison with Shuriken, 50000 particles, destroying and re-emitting about 300 per frame, and had these results:

My System – just simulation: 150 fps
My System – destroying particles: 50 fps
Shuriken – with any number of dying particles: 190 fps

My approach for dead particles is, during the Update Job, I save the dead IDs into a NativeQueue<>.Concurrent and then sort the particle array (alive ones at start, dead at the end) in the main thread, before Rendering.

I was wondering what is the approach used in Shuriken? Looks like there is no performance impact when many particles die at the same time. Is the full array sent to the GPU along with the state of the particles and the shader filters the dead ones?

Kind of a separate question…. Right now I use a custom shader, but what would I need to do, to use the existing Unity Particle Shaders? Is there some documentation/tutorial somewhere that describes how to draw custom geometry with the standard Particle Shaders, what are the required buffers or streams?

When a particle dies in Shuriken, we copy the particle at the end of the array, into the slot of the dead particle, when it dies.

How do you draw them currently? Presumably a copy to a ComputeBuffer, and DrawProcedural? If so, you’ll be manually fetching the particles in the vertex shader, which is incompatible with the Standard Particle Shader, which relies on the data being pre-expanded into 4-verts-per-particle, in world space, in a Vertex Buffer. I don’t think Unity currently provides an API to let you populate a Vertex Buffer from script.

1 Like