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

Fix noise_direction variable used before initialized in particle shader when using turbulence with collisions #83881

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions scene/resources/particle_process_material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -962,10 +962,6 @@ void ParticleProcessMaterial::_update_shader() {
code += " VELOCITY = mix(VELOCITY,vec3(0.0),clamp(collision_friction, 0.0, 1.0));\n";
code += " } else {\n";
code += " VELOCITY = vec3(0.0);\n";
// If turbulence is enabled, set the noise direction to up so the turbulence color is "neutral"
if (turbulence_enabled) {
code += " noise_direction = vec3(1.0, 0.0, 0.0);\n";
}
code += " }\n";
code += " }\n";
} else if (collision_mode == COLLISION_HIDE_ON_CONTACT) {
Expand All @@ -984,14 +980,16 @@ void ParticleProcessMaterial::_update_shader() {
}
code += " \n";
code += " vec3 noise_direction = get_noise_direction(TRANSFORM[3].xyz);\n";
// The following snippet causes massive performance hit. We don't need it as long as collision is disabled.
// Refer to GH-83744 for more info.
if (collision_mode != COLLISION_DISABLED) {

// Godot detects when the COLLIDED keyword is used. If it's used anywhere in the shader then Godot will generate the screen space SDF for collisions.
// We don't need it as long as collision is disabled. Refer to GH-83744 for more info.
if (collision_mode == COLLISION_RIGID) {
code += " if (!COLLIDED) {\n";
code += " \n";
code += " float vel_mag = length(final_velocity);\n";
code += " float vel_infl = clamp(dynamic_params.turb_influence * turbulence_influence, 0.0,1.0);\n";
code += " final_velocity = mix(final_velocity, normalize(noise_direction) * vel_mag * (1.0 + (1.0 - vel_infl) * 0.2), vel_infl);\n";
}
code += " float vel_mag = length(final_velocity);\n";
code += " float vel_infl = clamp(dynamic_params.turb_influence * turbulence_influence, 0.0,1.0);\n";
code += " final_velocity = mix(final_velocity, normalize(noise_direction) * vel_mag * (1.0 + (1.0 - vel_infl) * 0.2), vel_infl);\n";
if (collision_mode == COLLISION_RIGID) {
code += " }\n";
}
}
Expand Down
Loading