Emitting bug in GPUParticles3D?

Hi…,

when I switch off Emitting in GPUParticles3D my particles live longer than the Lifetime property, and fly on.

Is this a bug in Godot 4.5.1? What to do?

Thanks

Mike

Post your shader code.

Hi @normalized,

sure, here is the code:

Here is my particles shader code:

shader_type particles;

uniform float tube_radius : hint_range( 0.0, 10.0 ) = 2.0;
uniform float tube_length : hint_range( 0.0, 100.0 ) = 50.0;

float rand_from_seed(in uint seed) {
int k;
int s = int(seed);
if (s == 0)
s = 305420679;
k = s / 127773;
s = 16807 * (s - k * 127773) - 2836 * k;
if (s < 0)
s += 2147483647;
seed = uint(s);
return float(seed % uint(65536)) / 65535.0;
}

uint hash(uint x) {
x = ((x >> uint(16)) ^ x) * uint(73244475);
x = ((x >> uint(16)) ^ x) * uint(73244475);
x = (x >> uint(16)) ^ x;
return x;
}

void start(){
uint alt_seed1 = hash(NUMBER + uint(1) + RANDOM_SEED);
// set particle position in model space with tube_radius and tube_length
float angle_rand = rand_from_seed( alt_seed1 ) * 6.283185;
TRANSFORM[3].x = tube_length;
TRANSFORM[3].y = sin( angle_rand ) * tube_radius;
TRANSFORM[3].z = cos( angle_rand ) * tube_radius;
// calculate VELOCITY in negative x direction
VELOCITY.x = -tube_length / LIFETIME;
// calculate 2D normal and send it to “Pass 1” shader with CUSTOM variable
angle_rand -= 1.570796;
CUSTOM.yz = vec2( sin( angle_rand ), cos( angle_rand ) );
}

Thanks

Mike

When using a custom shader you’re responsible for deactivating the particle when its lifetime is up. You can see how it’s done if you convert a particle process material to a shader and peek into shader code:

void process(){
	CUSTOM.y += DELTA / LIFETIME;
	CUSTOM.y = mix(CUSTOM.y, 1.0, INTERPOLATE_TO_END);
	float lifetime_percent = CUSTOM.y / LIFETIME;
	if (CUSTOM.y > CUSTOM.w) {
		ACTIVE = false;
	}	
}
2 Likes

Hi @normalized,

I didn’t know that.

Thank you very much

Mike

1 Like