godotengine / godot

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

Setting custom color for method "emit_particle" not working (GPUParticles3D) #76360

Open krzmig opened 1 year ago

krzmig commented 1 year ago

Godot version

4.0.2 stable, 4.1.dev1

System information

Linux Debian 11, Vulkan, NVIDIA GeForce GTX 1050

Issue description

Hi, I have a problem to change the color of manually emitted particles 3D. The particles still have the default color selected in the inspector. Other properties, such as position or velocity, work fine (I also included them in the project).

Steps to reproduce

Use method "emit_particle" with custom color on GPUParticles3D:

emit_particle( Transform3D(), Vector3(), Color( 1.0, 0.0, 0.0 ), Color(), GPUParticles3D.EMIT_FLAG_COLOR )

Minimal reproduction project

particles.zip

dreadlocks-dude commented 1 year ago

emit_subparticle() from inside the shader has the same issue.

8uurg commented 1 year ago

For those wanting a workaround for this issue - convert the Process Material to a shader (warning: is somewhat destructive), there is a line in the shader that sets the color based on two attributes of the shader:

COLOR = hue_rot_mat * color_value;

If you uncomment this the per-particle color will work, albeit with the caveat that color_value and hue rotation will go unused.

Calinou commented 1 year ago

there is a line in the shader that sets the color based on two attributes of the shader:

Would making that line use COLOR *= fix the issue? The existing color would be multiplied instead of being overridden entirely.

8uurg commented 1 year ago

there is a line in the shader that sets the color based on two attributes of the shader:

Would making that line use COLOR *= fix the issue? The existing color would be multiplied instead of being overridden entirely.

I've quickly tested this, and this has an effect similar to (identical to?) modulating the custom particle color with hue_rot_mat * color_value. This however messes up when no custom color is set: the color is multiplied by the previous color over time.

I've made a few attempts - but it is quite difficult to preserve the hue-varying behavior while doing so and not turning the particle into a rainbow.

andreisbarnea commented 1 year ago

I confirm experiencing same issue in mono 4.1.3 and even 4.2 beta5.

kakatoto-collab commented 9 months ago

Same thing happens here in Mono 4.2.1 stable.

kakatoto-collab commented 9 months ago

For those wanting a workaround for this issue - convert the Process Material to a shader (warning: is somewhat destructive), there is a line in the shader that sets the color based on two attributes of the shader:

COLOR = hue_rot_mat * color_value;

If you uncomment this the per-particle color will work, albeit with the caveat that color_value and hue rotation will go unused.

I don't see this line in the shader code (Godot Mono 4.2.1 stable). The only line I see about COLOR is

COLOR = params.color;
clayjohn commented 9 months ago

This looks like it's the same issue as https://github.com/godotengine/godot/issues/83245

The ParticleProcessMaterial is not designed to handle colors coming from custom emitted particles. The logic for handling color just uses the parameters that go into the shader. If you want to use custom color from custom emitted particles, you need to write your own shader that handles that case.

kakatoto-collab commented 9 months ago

This looks like it's the same issue as #83245

The ParticleProcessMaterial is not designed to handle colors coming from custom emitted particles. The logic for handling color just uses the parameters that go into the shader. If you want to use custom color from custom emitted particles, you need to write your own shader that handles that case.

But then why do the emit_particle function has "color" in its arguments if it does not work ?

kakatoto-collab commented 9 months ago

I don't understand also how to modify the shader code in order to take into account the color passed into the emit_particle function. How do I get this color in the shader code ?