godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
91.01k stars 21.17k forks source link

emit_particle doesn't work (GPUParticles2D and 3D) #83245

Closed aXu-AP closed 1 year ago

aXu-AP commented 1 year ago

Godot version

v4.2.beta1.official [b1371806a]

System information

Windows 10 / NVIDIA Geforce GTX 1060 3GB / all backends

Issue description

GPUParticles2D/3D emit_particle doesn't do anything in the 4.2 beta 1. In the last snapshot it worked fine. Tested in Forward+, Mobile and Compatibility backends.

Steps to reproduce

Create a GPUParticles2D and set up as normal. Add following script:

extends GPUParticles2D
func _process(delta: float) -> void:
    emit_particle(global_transform, Vector2.ZERO, Color.WHITE, Color.WHITE, 0b11111)

or GPUParticles3D

extends GPUParticles3D
func _process(delta: float) -> void:
    emit_particle(global_transform, Vector3.ZERO, Color.WHITE, Color.WHITE, 0b11111)

Minimal reproduction project

ParticleMRP.zip

WagnerGFX commented 1 year ago

I've made a little reproduction project to test the issue in 2D and 3D. It works directly on the editor and exposes the emission settings to test the issue.

From the tests, I've found out that the CUSTOM color's Alpha and Green channels are being used for the particle's lifetime.

I'm not completely sure on how emit_particle() works, but from more testing, I've also found that it doesn't seem to be applying Rotation, Scale or Color. This behavior is the same in Godot 4.1.2-stable.

Also, the compatibility renderer explicitly warns on the console that it does not support manually emitting the particles.

GPUParticle Emit.zip

aXu-AP commented 1 year ago

Thanks for insight, good job!

Also, the compatibility renderer explicitly warns on the console that it does not support manually emitting the particles.

Oops, my bad, I'll remove this part from the issue.

QbieShay commented 1 year ago

I'm not so sure either how my PR broke it, but of note CUSTOM always had lifetime in green and lifetime randomness in alpha. That is intended behaviour, unless there's some strange interaction now that wasn't there before

aXu-AP commented 1 year ago

You unbroke it! I guess that means this can be closed then? Might need still some testing as to what was the earlier behavior, wasn't CUSTOM not set at all?

WagnerGFX commented 1 year ago

CUSTOM always had lifetime in green and lifetime randomness in alpha.

The lifetime in Alpha seems to be the same as in Green, except that it's using the value in reverse and they are incrementing each other. There is no randomness to Alpha. Although, when CUSTOM is activated, the default particle randomness is disabled.

That is intended behaviour

Then we also need some documentation, since CUSTOM has no description of what each value does. For example, Red and Blue also seem to do nothing, so I couldn't test them.

QbieShay commented 1 year ago

You unbroke it!

Haha no i think emit_particle still needs to be fixed

Then we also need some documentation, since CUSTOM has no description of what each value does.

Yeah fair!

CUSTOM.x = angle (for billboard) CUSTOM.y = current lifetime CUSTOM.z = animation for flipbook CUSTOM.w = lifetime randomness

actual lifetime (in 0-1 value) is INSTANCE_CUSTOM.y/INSTANCE_CUSTOM.w

WagnerGFX commented 1 year ago

CUSTOM.x = angle (for billboard) CUSTOM.y = current lifetime CUSTOM.z = animation for flipbook CUSTOM.w = lifetime randomness

I moved the Red channel's values around, but didn't see any changes to the texture (the texture is already in Particle Billboard mode)

I also set "Particle Anim" and changed the Blue channel's value, but there were no changes in the animation. Even when I played around with the particle's animation settings, the blue value made no changes to them.

At this point, only the "current lifetime" is applying for CUSTOM. Although I wonder if it was supposed to be the inverse (like how Alpha is doing), with full green meaning full lifetime, as right now it seems counterintuitive.

Rotation, Scale and Color also seem to not be working.

QbieShay commented 1 year ago

@aXu-AP can you reproduce in beta2?

I tested the MRP and they behave exactly the same if i revert the big particle PR

QbieShay commented 1 year ago

I'm having a hard time debugging this issue. In the MRP I am observing the same behaviour when I revert the PR, so I'm wondering if I'm missing something somewhere.

To help me understand the issue and fix it faster, I need to have a clear idea of expected behaviour and current behaviour. Comparative videos of one and the other would also help a lot :pray:

aXu-AP commented 1 year ago

I just tested with the Wagner's MRP, yes it is the same; however that MRP sends (0,0,0,1) as custom, my case was with (1,1,1,1). So change the exported custom property to white. Which, according to your explanation is expected to be not working as green = lifetime. However, on 4.1 it works.

QbieShay commented 1 year ago

So, green = lifetime when it's used by the main particle system. If you script the shader yourself, it can mean anything.

aXu-AP commented 1 year ago

Here's a new MRP. Sorry for not supplying one before: ParticleMRP.zip On 4.1, particles (white boxes) show, on 4.2 beta 2, nothing shows. particles

QbieShay commented 1 year ago

I think it makes sense that nothing shows. If your particles have already outlived their lifetime (green=1) then they should disappear. So if you spawn them, they spawn "already dead". This sounds like a bug in 4.1, if i understood correctly everything that's happening.

aXu-AP commented 1 year ago

Yes, this is what I meant when I said that you unbroke it and this issue can be closed. The behavior is different, but earlier behavior was a bug and this was just me not knowing what parameters to set with emit_particle. So user error essentially.

QbieShay commented 1 year ago

Alright then we agree :+1: Thanks everyone for taking the time to investigate this <3

aXu-AP commented 1 year ago

Thank you for being patient 😅 Had I supplied an MRP straight away or at least tested the other MRP earlier to see that it differed from my case we could've solved this way faster.

QbieShay commented 1 year ago

No worries!

WagnerGFX commented 1 year ago

So, about the Rotation, Scale, Color, CUSTOM Red/Blue/Alpha and CUSTOM documentation? Do they deserve issues of their own to look into that later?

aXu-AP commented 1 year ago

@WagnerGFX Yeah I think we should track that as a separate documentation issue. If custom parameter's behavior on standard processing paterial was documented properly, I would've used emit_particle properly in first place 😁

QbieShay commented 1 year ago

I do think that emit particle probably can't be used together with a standard particle material in that way. the particle material has to override the custom data with its own calculated randomness inside. I don't think that can change so it should be documented both on emit particle and somewhere for the custom vector.