summaryrefslogtreecommitdiffstats
path: root/scene/3d/cpu_particles_3d.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/3d/cpu_particles_3d.cpp')
-rw-r--r--scene/3d/cpu_particles_3d.cpp16
1 files changed, 8 insertions, 8 deletions
diff --git a/scene/3d/cpu_particles_3d.cpp b/scene/3d/cpu_particles_3d.cpp
index 8725ff19c9..03fe5e1fad 100644
--- a/scene/3d/cpu_particles_3d.cpp
+++ b/scene/3d/cpu_particles_3d.cpp
@@ -37,7 +37,6 @@
#include "scene/resources/gradient_texture.h"
#include "scene/resources/image_texture.h"
#include "scene/resources/particle_process_material.h"
-#include "scene/scene_string_names.h"
AABB CPUParticles3D::get_aabb() const {
return AABB();
@@ -69,7 +68,7 @@ void CPUParticles3D::set_amount(int p_amount) {
for (int i = 0; i < p_amount; i++) {
w[i].active = false;
- w[i].custom[3] = 0.0; // Make sure w component isn't garbage data
+ w[i].custom[3] = 1.0; // Make sure w component isn't garbage data and doesn't break shaders with CUSTOM.y/Custom.w
}
}
@@ -813,9 +812,10 @@ void CPUParticles3D::_particles_process(double p_delta) {
p.custom[0] = Math::deg_to_rad(base_angle); //angle
p.custom[1] = 0.0; //phase
p.custom[2] = tex_anim_offset * Math::lerp(parameters_min[PARAM_ANIM_OFFSET], parameters_max[PARAM_ANIM_OFFSET], p.anim_offset_rand); //animation offset (0-1)
+ p.custom[3] = (1.0 - Math::randf() * lifetime_randomness);
p.transform = Transform3D();
p.time = 0;
- p.lifetime = lifetime * (1.0 - Math::randf() * lifetime_randomness);
+ p.lifetime = lifetime * p.custom[3];
p.base_color = Color(1, 1, 1, 1);
switch (emission_shape) {
@@ -879,10 +879,10 @@ void CPUParticles3D::_particles_process(double p_delta) {
} break;
case EMISSION_SHAPE_RING: {
real_t ring_random_angle = Math::randf() * Math_TAU;
- real_t ring_random_radius = Math::randf() * (emission_ring_radius - emission_ring_inner_radius) + emission_ring_inner_radius;
- Vector3 axis = emission_ring_axis.normalized();
+ real_t ring_random_radius = Math::sqrt(Math::randf() * (emission_ring_radius * emission_ring_radius - emission_ring_inner_radius * emission_ring_inner_radius) + emission_ring_inner_radius * emission_ring_inner_radius);
+ Vector3 axis = emission_ring_axis == Vector3(0.0, 0.0, 0.0) ? Vector3(0.0, 0.0, 1.0) : emission_ring_axis.normalized();
Vector3 ortho_axis;
- if (axis == Vector3(1.0, 0.0, 0.0)) {
+ if (axis.abs() == Vector3(1.0, 0.0, 0.0)) {
ortho_axis = Vector3(0.0, 1.0, 0.0).cross(axis);
} else {
ortho_axis = Vector3(1.0, 0.0, 0.0).cross(axis);
@@ -1124,7 +1124,7 @@ void CPUParticles3D::_particles_process(double p_delta) {
//turn particle by rotation in Y
if (particle_flags[PARTICLE_FLAG_ROTATE_Y]) {
Basis rot_y(Vector3(0, 1, 0), p.custom[0]);
- p.transform.basis = p.transform.basis * rot_y;
+ p.transform.basis = rot_y;
}
}
@@ -1155,7 +1155,7 @@ void CPUParticles3D::_particles_process(double p_delta) {
}
if (!Math::is_equal_approx(time, 0.0) && active && !should_be_active) {
active = false;
- emit_signal(SceneStringNames::get_singleton()->finished);
+ emit_signal(SceneStringName(finished));
}
}