diff options
author | PouleyKetchoupp <pouleyketchoup@gmail.com> | 2020-08-09 18:16:53 +0200 |
---|---|---|
committer | PouleyKetchoupp <pouleyketchoup@gmail.com> | 2020-08-09 18:16:53 +0200 |
commit | 1c231cacb30315c08238c2808b60f72eaa6ecd87 (patch) | |
tree | 66ff46d3dec1d227252a9e09a4dbeed2026e022b /scene/3d/cpu_particles_3d.cpp | |
parent | 241e709462cd90d3daade3c6a05ff130fe85b4c0 (diff) |
Fix 2D Particle velocity with directed emission mask
Changed CPU velocity calculation for EMISSION_SHAPE_DIRECTED_POINTS
to follow the same logic as in the GPU version:
mat2 rotm;
rotm[0] = texelFetch(emission_texture_normal, emission_tex_ofs, 0).xy;
rotm[1] = rotm[0].yx * vec2(1.0, -1.0);
VELOCITY.xy = rotm * VELOCITY.xy;
Now both CPUParticles2D & CPUParticles3D (z disabled) show the same results
as their GPU counterparts and take the initial velocity settings into account.
Diffstat (limited to 'scene/3d/cpu_particles_3d.cpp')
-rw-r--r-- | scene/3d/cpu_particles_3d.cpp | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/scene/3d/cpu_particles_3d.cpp b/scene/3d/cpu_particles_3d.cpp index 4244a11592..ad8760251f 100644 --- a/scene/3d/cpu_particles_3d.cpp +++ b/scene/3d/cpu_particles_3d.cpp @@ -726,13 +726,15 @@ void CPUParticles3D::_particles_process(float p_delta) { if (emission_shape == EMISSION_SHAPE_DIRECTED_POINTS && emission_normals.size() == pc) { if (flags[FLAG_DISABLE_Z]) { - /* - mat2 rotm; - "; - rotm[0] = texelFetch(emission_texture_normal, emission_tex_ofs, 0).xy; - rotm[1] = rotm[0].yx * vec2(1.0, -1.0); - VELOCITY.xy = rotm * VELOCITY.xy; - */ + Vector3 normal = emission_normals.get(random_idx); + Vector2 normal_2d(normal.x, normal.y); + Transform2D m2; + m2.set_axis(0, normal_2d); + m2.set_axis(1, normal_2d.tangent()); + Vector2 velocity_2d(p.velocity.x, p.velocity.y); + velocity_2d = m2.basis_xform(velocity_2d); + p.velocity.x = velocity_2d.x; + p.velocity.y = velocity_2d.y; } else { Vector3 normal = emission_normals.get(random_idx); Vector3 v0 = Math::abs(normal.z) < 0.999 ? Vector3(0.0, 0.0, 1.0) : Vector3(0, 1.0, 0.0); |