Fix friction being in the correct if/else branch

Co-authored-by: Rémi Verschelde <rverschelde@gmail.com>
This commit is contained in:
QbieShay 2023-10-27 00:57:25 +02:00
parent 09946f79bd
commit 8f2a2ece80

View file

@ -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";