From 8f2a2ece80c1ab867a8acd0add8f4f80dd83c117 Mon Sep 17 00:00:00 2001 From: QbieShay Date: Fri, 27 Oct 2023 00:57:25 +0200 Subject: [PATCH] Fix friction being in the correct if/else branch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: RĂ©mi Verschelde --- scene/resources/particle_process_material.cpp | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/scene/resources/particle_process_material.cpp b/scene/resources/particle_process_material.cpp index 6075db4ffb8..f26b0d2227e 100644 --- a/scene/resources/particle_process_material.cpp +++ b/scene/resources/particle_process_material.cpp @@ -958,21 +958,22 @@ void ParticleProcessMaterial::_update_shader() { code += " {\n"; code += " // copied from previous version\n"; code += " if (physics_params.damping > 0.0) {\n"; + code += " float v = length(VELOCITY);\n"; if (!particle_flags[PARTICLE_FLAG_DAMPING_AS_FRICTION]) { - code += " float v = length(VELOCITY);\n"; + code += " v -= physics_params.damping * DELTA;\n"; + } else { + code += " if (v > 0.001) {\n"; code += " // Realistic friction formula. We assume the mass of a particle to be 0.05kg.\n"; code += " float damp = v * v * physics_params.damping * 0.05 * DELTA;\n"; code += " v -= damp;\n"; - code += " if (v < 0.0) {\n"; - code += " VELOCITY = vec3(0.0);\n"; - code += " } else {\n"; - code += " VELOCITY = normalize(VELOCITY) * v;\n"; - code += " }\n"; - } else { - code += " if (length(VELOCITY) > 0.01){\n"; - code += " VELOCITY -= normalize(VELOCITY) * length(VELOCITY) * (physics_params.damping) * DELTA;\n"; - code += " }\n"; + code += " }\n"; } + + code += " if (v < 0.0) {\n"; + code += " VELOCITY = vec3(0.0);\n"; + code += " } else {\n"; + code += " VELOCITY = normalize(VELOCITY) * v;\n"; + code += " }\n"; code += " }\n"; code += " \n"; code += " }\n";