diff options
author | Niko Abeler <me@h4kor.de> | 2017-08-12 21:33:20 +0200 |
---|---|---|
committer | Niko Abeler <me@h4kor.de> | 2017-08-16 08:09:45 +0200 |
commit | 6c398b583001ef110404a71689afa3b5b6c676ad (patch) | |
tree | 3cfe81d65d0481f4a6e33a80ef1fdf359c37d4c5 | |
parent | 5052cb2b9104f57d0ff38d80da50bbeceb926e6f (diff) |
Checking vecs before normalization. Fixes #10183
-rw-r--r-- | scene/3d/particles.cpp | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/scene/3d/particles.cpp b/scene/3d/particles.cpp index 081caf4419..d2535e0ed3 100644 --- a/scene/3d/particles.cpp +++ b/scene/3d/particles.cpp @@ -406,7 +406,7 @@ void ParticlesMaterial::init_shaders() { shader_names->anim_speed = "anim_speed"; shader_names->anim_offset = "anim_offset"; - shader_names->initial_linear_velocity = "initial_linear_velocity_random"; + shader_names->initial_linear_velocity_random = "initial_linear_velocity_random"; shader_names->initial_angle_random = "initial_angle_random"; shader_names->angular_velocity_random = "angular_velocity_random"; shader_names->orbit_velocity_random = "orbit_velocity_random"; @@ -753,18 +753,20 @@ void ParticlesMaterial::_update_shader() { code += " pos.z=0.0; \n"; } code += " //apply linear acceleration\n"; - code += " force+=normalize(VELOCITY) * (linear_accel+tex_linear_accel)*mix(1.0,rand_from_seed(alt_seed),linear_accel_random);\n"; + code += " force+= length(VELOCITY) > 0.0 ? normalize(VELOCITY) * (linear_accel+tex_linear_accel)*mix(1.0,rand_from_seed(alt_seed),linear_accel_random) : vec3(0.0);\n"; code += " //apply radial acceleration\n"; code += " vec3 org = vec3(0.0);\n"; - code += " // if (!p_system->local_coordinates)\n"; - code += " //org=p_transform.origin;\n"; - code += " force+=normalize(pos-org) * (radial_accel+tex_radial_accel)*mix(1.0,rand_from_seed(alt_seed),radial_accel_random);\n"; + code += " // if (!p_system->local_coordinates)\n"; + code += " //org=p_transform.origin;\n"; + code += " vec3 diff = pos-org;\n"; + code += " force+=length(diff) > 0.0 ? normalize(diff) * (radial_accel+tex_radial_accel)*mix(1.0,rand_from_seed(alt_seed),radial_accel_random) : vec3(0.0);\n"; code += " //apply tangential acceleration;\n"; if (flags[FLAG_DISABLE_Z]) { - code += " force+=vec3(normalize((pos-org).yx * vec2(-1.0,1.0)),0.0) * ((tangent_accel+tex_tangent_accel)*mix(1.0,rand_from_seed(alt_seed),radial_accel_random));\n"; + code += " force+=length(diff.yx) > 0.0 ? vec3(normalize(diff.yx * vec2(-1.0,1.0)),0.0) * ((tangent_accel+tex_tangent_accel)*mix(1.0,rand_from_seed(alt_seed),radial_accel_random)) : vec3(0.0);\n"; } else { - code += " force+=normalize(cross(normalize(pos-org),normalize(gravity))) * ((tangent_accel+tex_tangent_accel)*mix(1.0,rand_from_seed(alt_seed),radial_accel_random));\n"; + code += " vec3 crossDiff = cross(normalize(diff),normalize(gravity));\n"; + code += " force+=length(crossDiff) > 0.0 ? normalize(crossDiff) * ((tangent_accel+tex_tangent_accel)*mix(1.0,rand_from_seed(alt_seed),radial_accel_random)) : vec3(0.0);\n"; } code += " //apply attractor forces\n"; code += " VELOCITY+=force * DELTA;\n"; |