Sign in to follow this  

Dynamic Injection of Particles Using the CS

This topic is 1252 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts



I'm having a bit of trouble implementing a fully GPU based particle system. I've implemented the one similar to what's presented in J. Zink's book and it works fine for 99% of the time. The problem is that some of the particles seem to get stuck: they don't move forward along their given direction vector and flicker for a couple of frames and then suddenly jump forward again. I'm not sure as to what could cause this kind of behavior.


In the following shaders, particleCount is from a constant buffer that gets updated with the CopyStructureCount method from the UAV holding the newest data.


The update shader:

[numthreads(512, 1, 1)]
void CSMain(uint3 dispatchThreadID : SV_DispatchThreadID) {
       uint threadID = dispatchThreadID.x + dispatchThreadID.y * 512 * dispatchThreadID.z * 512 * 512;
       if(threadID < particleCount) {
           Particle p = oldState.Consume();
           p.velocity += acceleration * dt;
           p.position += p.velocity * dt;
           p.time += dt;
           if(p.time < particleLifetime) {

The particle adding shader:

[numthreads(1, 1, 1)]
void CSMain(uint3 dispatchThreadID : SV_DispatchThreadID) {
     if(particleCount < 512) {
        Particle p;
        p.position =;
        p.velocity =;
        p.time = 0.0f;

Checking with NSight, the particleCount stays at 512 all the time. If I swap the order of operations to Update(); Add();, the value for the constant buffer before update is 512 and after is 513 (i.e. buffer overflow). However, when I use the Add(); Update(); order they seem to be the same.


I'd submit a screenshot of what's happening but it's really difficult to capture since the particles are stuck for about 1-2s, sometimes less, sometimes more.


Thanks in advance!

Edited by dr4cula

Share this post

Link to post
Share on other sites
Sign in to follow this