Flying embers effect using compute shaders and vertex pulling from SSBOs

I quickly hacked up a little sample to demonstrate how to create a particle effect system on the GPU using compute shaders and vertex pulling from shader-generated buffers.

I could have used a point cloud for this, of course, but wanted to show how one could do this using triangles. (21.5 KB)

An interesting exercise for the reader would be to modify it to create motion streaks by elongating the triangles in the direction of motion.


This is great, thanks for sharing !

One naive question, what is the advantage of this technique compared to using a geometry shader to generate the triangles and imageLoad/Store to update the data of the embers ?

There is no substantial difference between imageLoad/imageStore and SSBOs, except that SSBOs are more convenient because they allow more structured access without having to pack/unpack values into the vec4 of individual texels. If you are only storing a single vec4, then you might as well use imageLoad/Store.

Geometry shaders are generally considered inefficient, and there is no need for them in this case. I don’t know how inefficient compared to this, though.

PS. I just updated the code; the speed of the embers was not being properly respected by the shader, resulting in a less compelling effect.

On macOS there is no support for compute, so instead I generate a list of points, I do the update in the geometry shader and generate at the same time the triangle primitives. But if indeed it’s inefficient, I say I would switch to your workflow and keep the geometry path only for mac.

To be honest, there is no need to use a compute shader in this example. Modifying the buffer in the vertex shader would have worked just fine as well.