From 1f4a6e43df774647e3d50adcc7b64d88b1ab987e Mon Sep 17 00:00:00 2001 From: lawnjelly Date: Tue, 19 Sep 2023 08:11:06 +0100 Subject: [PATCH] Fix zero scale in particle shader Fixes the lower bounding of scale when given zero input. The previous bug was due to `sign` returning 0 with 0.0 input, rather than 1. --- scene/resources/particles_material.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/scene/resources/particles_material.cpp b/scene/resources/particles_material.cpp index 3126a7b9f69..991a658a859 100644 --- a/scene/resources/particles_material.cpp +++ b/scene/resources/particles_material.cpp @@ -659,8 +659,14 @@ void ParticlesMaterial::_update_shader() { } //scale by scale code += " float base_scale = tex_scale * mix(scale, 1.0, scale_random * scale_rand);\n"; + // Prevent zero scale (which can cause rendering issues). - code += " base_scale = sign(base_scale) * max(abs(base_scale), 0.000001);\n"; + code += " if (base_scale >= 0.0) {\n"; + code += " base_scale = max(base_scale, 0.000001);\n"; + code += " } else {\n"; + code += " base_scale = min(base_scale, -0.000001);\n"; + code += " }\n"; + if (trail_size_modifier.is_valid()) { code += " if (trail_divisor > 1) {\n"; code += " base_scale *= textureLod(trail_size_modifier, vec2(float(int(NUMBER) % trail_divisor) / float(trail_divisor - 1), 0.0), 0.0).r;\n";