Skip to content

Enabling particle turbulence causes massive performance hit #83744

Closed
@djrain

Description

@djrain

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

Activity

RPicster

RPicster commented on Oct 21, 2023

@RPicster
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

clayjohn commented on Oct 21, 2023

@clayjohn
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

added this to the 4.2 milestone on Oct 21, 2023
k0T0z

k0T0z commented on Oct 21, 2023

@k0T0z
Contributor

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Enabling particle turbulence causes massive performance hit · Issue #83744 · godotengine/godot