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.
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.
Sorry if this is somewhat old and I’m reviving it, but this is really cool and would be a great sample to add to the documentation or to the official samples? I searched for quite a while before stumbling across this post.
At the moment, the wiki page on Compute Shaders is somewhat short and the sample even shorter. This sample here is much closer to an actual application IMHO and shows how quickly some very complex things can be done in Panda3D…
It is a very simple and crude example, I am not sure it is worth adding to the samples. Especially because compute shaders are actually completely unnecessary for this, and I don’t want to give people the idea that this is the recommended way to do such a particle effect.
But, it is probably better than the complete lack of compute shader samples we have right now. So, I will consider it.
I understand the hesitation, but all of this could be noted in the Readme for the sample?
Without your sample, I would not have been able to code what I have right now. And it took me quite a while to find, because I was mainly searching the documentation.
If you don’t want to place it in the official samples, how about adding it to the Compute Shaders documentation website (Compute Shaders — Panda3D Manual)? People who read that page are probably looking for samples of how to use compute shaders and aren’t worried about whether compute shaders make sense for this particular sample…
(Side note: As with all engines I’ve worked with, I find it very hard to get deeper into shaders because usually you have to learn the Shader/OpenGL side at the same time as learning how the engine deals with it - so samples of shaders and how they’re used within the engine always help me out immensely).