Skip to content

Commit

Permalink
Merge pull request #81902 from lawnjelly/fix_particle_zero_scale
Browse files Browse the repository at this point in the history
[3.x] Fix zero scale in particle shader
  • Loading branch information
akien-mga authored Sep 19, 2023
2 parents 501517a + 1f4a6e4 commit 1d7a417
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion scene/resources/particles_material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit 1d7a417

Please sign in to comment.