Skip to content

Commit 7c68926

Browse files
committed
Merge pull request godotengine#90095 from QbieShay/qbe/fix-cpuparticle-instancew
Fix `INSTANCE_CUSTOM.w` not being assigned correctly in CPUParticles 2D and 3D
2 parents 72e9e57 + 1d81068 commit 7c68926

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

scene/2d/cpu_particles_2d.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -753,10 +753,10 @@ void CPUParticles2D::_particles_process(double p_delta) {
753753
p.custom[0] = 0.0; // unused
754754
p.custom[1] = 0.0; // phase [0..1]
755755
p.custom[2] = tex_anim_offset * Math::lerp(parameters_min[PARAM_ANIM_OFFSET], parameters_max[PARAM_ANIM_OFFSET], p.anim_offset_rand);
756-
p.custom[3] = 0.0;
756+
p.custom[3] = (1.0 - Math::randf() * lifetime_randomness);
757757
p.transform = Transform2D();
758758
p.time = 0;
759-
p.lifetime = lifetime * (1.0 - Math::randf() * lifetime_randomness);
759+
p.lifetime = lifetime * p.custom[3];
760760
p.base_color = Color(1, 1, 1, 1);
761761

762762
switch (emission_shape) {

scene/3d/cpu_particles_3d.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ void CPUParticles3D::set_amount(int p_amount) {
6969

7070
for (int i = 0; i < p_amount; i++) {
7171
w[i].active = false;
72-
w[i].custom[3] = 0.0; // Make sure w component isn't garbage data
72+
w[i].custom[3] = 1.0; // Make sure w component isn't garbage data and doesn't break shaders with CUSTOM.y/Custom.w
7373
}
7474
}
7575

@@ -813,9 +813,10 @@ void CPUParticles3D::_particles_process(double p_delta) {
813813
p.custom[0] = Math::deg_to_rad(base_angle); //angle
814814
p.custom[1] = 0.0; //phase
815815
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)
816+
p.custom[3] = (1.0 - Math::randf() * lifetime_randomness);
816817
p.transform = Transform3D();
817818
p.time = 0;
818-
p.lifetime = lifetime * (1.0 - Math::randf() * lifetime_randomness);
819+
p.lifetime = lifetime * p.custom[3];
819820
p.base_color = Color(1, 1, 1, 1);
820821

821822
switch (emission_shape) {

0 commit comments

Comments
 (0)