Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enabling particle turbulence causes massive performance hit #83744

Closed
djrain opened this issue Oct 21, 2023 · 4 comments · Fixed by #83749
Closed

Enabling particle turbulence causes massive performance hit #83744

djrain opened this issue Oct 21, 2023 · 4 comments · Fixed by #83749

Comments

@djrain
Copy link

djrain commented Oct 21, 2023

Godot version

4.1.2 stable

System information

macOS, Android. All renderers

Issue description

After adding a GPUParticles2D node to our project, I was surprised to find it suddenly running at 10FPS on Android. Disabling particle turbulence brought the FPS back to the normal 90. Turns out the real culprit is not the turbulence itself, but this conditional check for collision in the particle shader:

if (!COLLIDED) {
		
		float vel_mag = length(VELOCITY);
		float vel_infl = clamp(mix(turbulence_influence_min, turbulence_influence_max, rand_from_seed(alt_seed)) * turbulence_influence, 0.0, 1.0);
		VELOCITY = mix(VELOCITY, normalize(noise_direction) * vel_mag * (1.0 + (1.0 - vel_infl) * 0.2), vel_infl);
	}	

This check gets generated even when collision is disabled. Luckily I don't need collision and simply removing it solved the issue (I've included this fixed version of the particles in the MRP). However, it's still odd that this is so slow in the first place. Replacing the if statement with a ternary or a step expression did not help.

The problem is not only on mobile - running the example project on my M1 Mac, I get a drop from 1500 FPS to 600 after enabling turbulence on a default particle system emitting only 1 particle. Also happens regardless of rendering backend. Have not confirmed on iOS or Windows.

I assume it applies to 3D too, but didn't check.

Steps to reproduce

Run MRP scene, should run well at first.
Then enable turbulence and observe FPS drop.

Minimal reproduction project

SlowParticleTurbulenceIssue.zip

@RPicster
Copy link
Contributor

Ah, thanks for the report. Adding a condition in the shader compilation code (in the engine) to check if collision is enabled should be easy 👍

@clayjohn
Copy link
Member

Looks like if COLLISION in a 2D particles shader it flags for the engine to enable the screen SDF automatically. So the cost you are seeing is not from the particles per se, but from generating the screen SDF, which is expected to be super slow on mobile. Avoiding adding the COLLISION built in should be enough to fix the issue.

As RPicster says, it is a quick fix

@k0T0z
Copy link
Contributor

k0T0z commented Oct 21, 2023

@djrain I got an FPS drop from 4800+ to 3900+ on enabling the collision, but now I think this will do it. I got also another error don't know if it's related or not:

  :436 - Unknown identifier in expression: 'noise_direction'.
  Shader compilation failed.

This happens in the above MRP when I change the collision mode from DISABLED to RIGID as below:

image
image

@Calinou
Copy link
Member

Calinou commented Oct 21, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment