godotengine / godot

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

GPUParticles2D Turbulence parameters are affected by the rectangular (box) emission shape and particle flags #74541

Open Novark opened 1 year ago

Novark commented 1 year ago

Godot version

v4.0.stable.official [92bee43ad]

System information

Windows 11 [Vulkan]

Issue description

The turbulence influence min/max properties seem to apply across the emitter shape in a linearly increasing fashion instead of randomly on a per-particle basis as per the documentation:

The actual amount of turbulence influence on each particle is calculated as a random value between turbulence_influence_min and turbulence_influence_max and multiplied by the amount of turbulence influence from turbulence_influence_over_life.

IMPORTANT: This issue is resolved when the "Disable Z" Particle Flags checkbox is un-checked. This checkbox is enabled by default when the GPUParticles2D node is enabled.

P.S. the documentation for turbulence_influence_min and turbulence_influence max are incorrectly swapped.

image

Steps to reproduce

To reproduce this is fairly simple:

  1. Create a GPUParticles2D Node
  2. Emit a significant number of particles (I'm emitting 50,000) and set the emission shape to "Box" (X=500, Y=1, Z=1)
  3. Set the gravity to (X=0, Y=1000, Z=0), and enable turbulence
  4. Set the turbulence_influence_min property to 0.1 (default) and turbulence_influence_max to 1
  5. Observe how the turbulence influence applies the "min" value to the left of the emission shape, and linearly scales up to the "max" value to the right of the emission shape.

The expected behaviour would have the turbulence influence take a random value between [min, max] and apply a random value to each particle along the emission shape.

Un-check the "Disable Z" Particle Flag to see the intended behaviour. I'm unsure why this checkbox is affecting the way turbulence influence is distributed across the emission shape, but it may have something to do with the way VELOCITY is being calculated in the shader. Digging into the code a bit, it seems that there's some pretty large discrepancies with how the velocity spread is calculated for PARTICLE_FLAG_DISABLE_Z enabled vs. disabled. I'm not familiar enough with the code to say for certain where this might be occurring, however.

Minimal reproduction project

No sample project provided, as the reproduction is quite simple to replicate.

clayjohn commented 1 year ago

Might be fixed by https://github.com/godotengine/godot/pull/64606

QbieShay commented 1 year ago

Hey, #64606 was superseded by https://github.com/godotengine/godot/pull/77154 . Can you test if the issue persists?

Novark commented 1 year ago

Hey, #64606 was superseded by #77154 . Can you test if the issue persists?

I don't have my environment set up at the moment to be able to build from source. Is there anywhere I can grab a compiled build of the master branch? If not, I'll be happy to test this in the next pre-release distribution.

Novark commented 1 year ago

Hey, #64606 was superseded by #77154 . Can you test if the issue persists?

I've just tested this in v4.1.dev3.official [a67d37f7c], and the issue still persists. Moreover, the new implementation doesn't seem very "turbulent" at all - I'm not sure why this is, but playing with the turbulence settings, I'm not able to get anywhere near the same behaviour as before. Particles just seem to wiggle around a little bit now, but the visual characteristics are completely different. Please let me know if there's something that I'm missing with the new implementation, and I can re-test.

Edit: I've filed a new bug report for the unexpected turbulence changes. See #77491 for details

image

KdotJPG commented 1 year ago

It seems to have something to do with the distribution of the results of rand_from_seed(alt_seed) after certain numbers of calls. Adding one dummy call before the line here seems to fix it.

image

I'd like to better figure out what exactly is causing the issue to begin with, though.

QbieShay commented 1 year ago

Hey @KdotJPG , did you figure it out in the end? Otherwise we can just add an extra random call and call it a day.

QbieShay commented 1 year ago

@Novark could you test with https://github.com/godotengine/godot/issues/74541 ?

Novark commented 1 year ago

@Novark could you test with #74541 ?

Issue still persists in v4.2.dev2.official

QbieShay commented 1 year ago

The PR isn't merged yet, it needs to be tested on a custom build. In the checks tab of the PR, there's an "artifacts" button. You can download the custom build from there: image

Please test on an empty project with just one turbulence particle system, this is a WIP PR and may change existing particle systems (although it shuoldn't)

Novark commented 1 year ago

The PR isn't merged yet, it needs to be tested on a custom build. In the checks tab of the PR, there's an "artifacts" button. You can download the custom build from there: [Image])

Please test on an empty project with just one turbulence particle system, this is a WIP PR and may change existing particle systems (although it shuoldn't)

Alright, I've tested it with your PR and noticed the following things:

image

QbieShay commented 1 year ago

Does it happens also if you turn off interpolation?

Novark commented 1 year ago

Does it happens also if you turn off interpolation?

Disabling interpolation seemed to fix a lot of the system-wide jitter (the Y-position issue I described above). I'm assuming this behaviour is not intended. Let me know if you want me to open a new bug report for it.

The turbulence jitter that occurs when turbulence_influence_max is cranked up still persists, however.

Calinou commented 1 year ago

Disabling interpolation seemed to fix a lot of the system-wide jitter (the Y-position issue I described above). I'm assuming this behaviour is not intended. Let me know if you want me to open a new bug report for it.

Interpolation issues are already being tracked in https://github.com/godotengine/godot/issues/51318.

QbieShay commented 1 year ago

Thank you @Novark ! I'll investigate the issue with max turbulence and try to address it with my PR. If I don't figure it out I'll address it in a subsequent PR.