Godot version:
3.0
OS/device including version:
Win 10
Issue description:
When changing the Amount parameter, the particle system resets the simulation. Expected to just start emitting the new amount without deleting the already emitted particles. Intention: Changing it from code so that it emits more or less under certain circumstances.
Steps to reproduce:
Make Particles2D, drag the Amount slider.
By the look of the code, the gles3 renderer sets a bunch of parameters and the entire simulation is run on the GPU in the vertex shader (I suppose using transform feedbacks the result of the simulation). Because resizing causes godot to allocate new buffers for the particle data, the previous buffer ends up lost.
The editor could expose a maximum number of particles and allocate a buffer of that size so that the data is not lost. That's probably straightforward to implement.
The rendering engine could also support reallocating buffers without losing the content of the previous buffer. shrinking the buffer doesn't require much work (just sample from the previous frame's buffer with new frame's particle count), growing it would require a draw call to do the simulation with the number of particles from the previous frame and another draw call to take care of the new particles (maybe a bit more fiddly).
@akien-mga I don't think this issue should be labeled as enhancement, i think it's a bug: it makes it impossible to use particles for effects with a varying amount (in my case, i needed to modify the drops of water from a shower depending on how much the valves were open)
Should probably just have a 'current' amount and a 'max' amount?
I recently ran into this as well. It's not perfect, but I was able to somewhat work around it by having multiple Particles2D
nodes at the same position, making only one of them visible initially, and controlling the modulate (transparency) to "merge" the other particle systems in as the effect animates (in my case, I was trying to get a flame effect, so having semi-transparent particles was fine).
Same in Godot 3.1 alpha 5.0, the bug persist :/
Until this is solved, there is a shader that does that made by @karroffel https://gitlab.com/thola/ShowerSimulator/blob/master/ShowerParticles.shader
Also CPUParticles2D are affected by this behaviour.
It's not a bug, so far it's expected behaviour. I agree it should be improved, but I'm not sure it can slip into 3.1
Try hiding the particles first, change the amount and make them show then
@emarod Won't that effectively do the same thing? "Reset" the existing particle system's emissions?
This also affects Particles (the 3D equivalent), I believe the shader posted above is for Particles2D, so if anyone has a 3D equivalent of that shader I'd massively appreciate it :)
I believe if you set the "preprocess" value on the particles you can get something a little better, although not perfect. It works well enough for fire and such.
still present on 3.2.1 (3D particle)
Most helpful comment
By the look of the code, the gles3 renderer sets a bunch of parameters and the entire simulation is run on the GPU in the vertex shader (I suppose using transform feedbacks the result of the simulation). Because resizing causes godot to allocate new buffers for the particle data, the previous buffer ends up lost.
The editor could expose a maximum number of particles and allocate a buffer of that size so that the data is not lost. That's probably straightforward to implement.
The rendering engine could also support reallocating buffers without losing the content of the previous buffer. shrinking the buffer doesn't require much work (just sample from the previous frame's buffer with new frame's particle count), growing it would require a draw call to do the simulation with the number of particles from the previous frame and another draw call to take care of the new particles (maybe a bit more fiddly).