Skip to content

Commit

Permalink
fix performance hit due to enabling collision
Browse files Browse the repository at this point in the history
Signed-off-by: Saif Kandil <74428638+k0T0z@users.noreply.github.com>
  • Loading branch information
k0T0z committed Oct 22, 2023
1 parent f71f4b8 commit 98db2b4
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions scene/resources/particle_process_material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -984,12 +984,16 @@ void ParticleProcessMaterial::_update_shader() {
}
code += " \n";
code += " vec3 noise_direction = get_noise_direction(TRANSFORM[3].xyz);\n";
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 += " }\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) {
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 += " }\n";
}
}
code += " \n";
code += " // limit velocity\n";
Expand Down

0 comments on commit 98db2b4

Please sign in to comment.