Godot version:
3.2 alpha3
OS/device including version:
windows 10
Issue description:
particles animation ending prematurely if life time is set below 1
Steps to reproduce:
create Particle2D node and give the process material some sort of animation and set the life time to below 1
Minimal reproduction project:
minimalRecreation.zip
see that the color is suppose to go from blue to green to red but it never reaches red unless the life time is above 0.8
first time posting sorry for any noobness
I assume the problem is it using some kind of integer type?
Bug is absent in the v3.1.1 stable release on steam
I think the issue firstly appears 5ef33742582ef0455653db6c7f92114853498ebb.
It looks like the error is here in the shader code for the particles:
As far as I understand CUSTOM.y contains a value between 0 and 1. It can only be bigger than CUSTOM.w if the lifetime is smaller than 1. This leads to a prematurely ending of the animation if it has a smaller lifetime than 1.
I'm currently working on a pull-request to resolve this issue.
I stumbled over a question in relation to the lifetime randomness together with particle animation.
What if the particles get a shorter lifetime through the lifetime randomness modifier.
Should the animation play faster to complete in time?
If someone wants to test it, this is my current implementation: https://github.com/Kaonnull/godot/commit/b7f6b9b4d0b65300e9f316f824aad7e760f60cab
Your current commit will completely break "lifetime_randomness" CUSTOM.y increases up to lifetime. CUSTOM.W stores a value less than lifetime at which point the particle resets.
This bug just needs something that takes lifetime into account when blending values over lifetime.
Are you sure that CUSTOM.y increases to LIFETIME?
It looks like that CUSTOM.y is normalized, in every tick CUSTOM.y is increased by a normalized DELTA:
https://github.com/godotengine/godot/blob/36a785513fb1424b17c7ae217668f7ca402b5790/scene/resources/particles_material.cpp#L379-L382
I currently have two working fixes, one where the animation is played faster when a particle gets a shorter lifetime:
https://github.com/Kaonnull/godot/commit/b7f6b9b4d0b65300e9f316f824aad7e760f60cab
Build: https://gofile.io/?c=PyCCEd

With "lifetime_randomness":

My other approach is that the particle just disappears when its lifetime ends:
https://github.com/Kaonnull/godot/commit/cb7e65e564e7f95089f094f038858fbf7427afd4
Build: https://gofile.io/?c=IuZBZc

With "lifetime_randomness":

I think in both is the "lifetime_randomness" still working correctly.
But in the first one, the minimal reconstruction example looks kind of odd with "lifetime_randomness". If a particle has a relay short lifetime, it reaches its maximum size really fast.
Most helpful comment
I think the issue firstly appears 5ef33742582ef0455653db6c7f92114853498ebb.
It looks like the error is here in the shader code for the particles:
https://github.com/godotengine/godot/blob/8570b9b0c2972b7aa191475342d0dd8030fd4188/scene/resources/particles_material.cpp#L291-L295
https://github.com/godotengine/godot/blob/8570b9b0c2972b7aa191475342d0dd8030fd4188/scene/resources/particles_material.cpp#L333-L336
https://github.com/godotengine/godot/blob/8570b9b0c2972b7aa191475342d0dd8030fd4188/scene/resources/particles_material.cpp#L381
As far as I understand
CUSTOM.ycontains a value between 0 and 1. It can only be bigger thanCUSTOM.wif the lifetime is smaller than 1. This leads to a prematurely ending of the animation if it has a smaller lifetime than 1.I'm currently working on a pull-request to resolve this issue.