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

Deterministic chain of random values in particle shader can be broken when turbulence is used #82837

Closed
greycheeked opened this issue Oct 5, 2023 · 2 comments · Fixed by #79527

Comments

@greycheeked
Copy link

Godot version

v4.1.1.stable.official [bd6af8e]

System information

Windows 10.0.22621 - Vulkan (Forward+) - dedicated NVIDIA GeForce GTX 1650 SUPER (NVIDIA; 31.0.15.3130) - Intel(R) Core(TM) i5-10400F CPU @ 2.90GHz (12 Threads)

Issue description

The error is basically known: A random value is generated within an IF-THEN-block. As soon as the condition for IF changes, all subsequent random values change once.
This concerns the following location (turbulence):

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);
}

I think the right thing to do would be to pull the random value before IF:

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

Steps to reproduce

I found the error directly in the source code.

Minimal reproduction project

N/A

@Calinou
Copy link
Member

Calinou commented Oct 5, 2023

cc @RPicster @QbieShay @KdotJPG

@clayjohn
Copy link
Member

clayjohn commented Oct 5, 2023

Will be fixed by #79527

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

Successfully merging a pull request may close this issue.

3 participants