on it!
Well I see no error:
A PG with a GPUParticle and a targetStopDuration set up:
Explosion | Babylon.js Playground (babylonjs.com)
Please note that you need to register to onStop if you want to manually dispose the particles else the system (as stated in the doc) will keep running in the GPU
This PG uses an hemispheric emitter, GPU PS created in code and works as expected, the particles dies out and a blank screen is left behind:
This one is faulty. Hemishperic emitter, GPU PS from snippet. The particles didn’t die out after targetStopDuration
:
After 10 seconds still some on the screen:
s
The plot thickens
What do you mean?
As in that it works in @Deltakosh PG with everything done in code, but not in the others.
Guess we are actually closer to pinpointing the issue, that seems related to the way snippets are parsed.
So maybe is: the plot thinnes
Yes this is the problem I have, but I’m using code to create PS.
Investigating…
So!
Actually everything works as expected but it is a bit complex to understand
Some prerequesites:
- GPU particles are not created. The system has a define pool and only iterate through them. Dead particles are recycled and new ones are built from the same structure. For instance the system creates a buffer of 100 particles at start and the GPU goes through all of them every frame. It updates every particles and then render the same buffer. At the beginning until we reach max capacity we ask the GPU to only process the first few ones while every particles in the buffer are emitted
- This means that when a particle dies, it is simply repositioned at the source with a fresh set of values
- When targetDuration is hit, the system stop recycling, meaning that the dead particles remain and become zombies
So on the examples provided by @roland:
- The first one SEEMS to work but this is only because the deadColor is set to black. If I set it to anything else you can see the zombies particles: Babylon.js Playground (babylonjs.com)
- So on the contrary for the second one, if I set the colorDead to black, zombies are invisible (but still computed): Explosion | Babylon.js Playground (babylonjs.com)
This is why with GPU particles you need to add this code if you want to really terminate the system when targetDuration is hit:
ps.onStoppedObservable.addOnce(() => {
ps.dispose();
})
Mystery solved
Thank you for taking time and explaining it!
But this disposes the whole system at targetStopDuration
, which is not the desired effect :S
I’d like the system to stop emitting new particles at targetStopDuration
, BUT still let the existing active particles live out their lifetime, just like how the CPU system does.
I tried adding the dispose code here: https://playground.babylonjs.com/#X37LS1#258
As you can see this doesn’t match the CPU system behavior :S
Isn’t here some way where the GPU particles that is still active at targetStopDuration
could live out their lives and then be disabled (alpha = 0 or something)?
Oh I did not get your ask initially…
Simply set deadColor to 0:
Explosion | Babylon.js Playground (babylonjs.com)
Hmmm really weird this doesn’t just work from the snippet. Again here is my PG where I setup both CPU and GPU system from the same snippet: https://playground.babylonjs.com/#X37LS1#270
The snippet has deadColor
as #FFFFFF00
(alpha = 0)
Gahh seems that is not enough for GPU, it has to be #00000000
and then it works https://playground.babylonjs.com/#X37LS1#271
Thanks for all the help
I’m glad it works
Remember it is a OneOne blending so alpha is not the key here but the color (as the blending is additive)
Ahh of course, have been through too many variations to think clearly
Guess also just “confusing” when it behaves differently between CPU/GPU and I didn’t easily see why, but now starting to make total sense
FWIW: Here is what I’ve been working on (and now works with GPU): https://playground.babylonjs.com/#X37LS1#272
I’m using this PG to easily edit all the particle systems together using inspector, then saving snippets (which auto updates version in the PG source), and then shift LMB to export the whole particle system set as JSON to clipboard, ready to paste into application code.
Almost like a full blown particle system set editor