summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorclayjohn <claynjohn@gmail.com>2023-02-14 14:37:47 -0800
committerYuri Sizov <yuris@humnom.net>2023-04-24 16:28:28 +0200
commit27df8b93aa3055d707421222eb9176964e294096 (patch)
treeb6a541c2a1ee3dc211a7fc12c91b21d3e65e516b
parent95f50274534563dbcb27e6ed3fcfa25a77f366e9 (diff)
Properly calculate lifetime_split for particles
(cherry picked from commit f35ca4a9c735e49d496c4e733e7dc9a072841f92)
-rw-r--r--drivers/gles3/storage/particles_storage.cpp9
-rw-r--r--servers/rendering/renderer_rd/storage_rd/particles_storage.cpp4
2 files changed, 6 insertions, 7 deletions
diff --git a/drivers/gles3/storage/particles_storage.cpp b/drivers/gles3/storage/particles_storage.cpp
index 2b47271408..4b64e2aec1 100644
--- a/drivers/gles3/storage/particles_storage.cpp
+++ b/drivers/gles3/storage/particles_storage.cpp
@@ -919,7 +919,7 @@ void ParticlesStorage::_particles_update_instance_buffer(Particles *particles, c
glBeginTransformFeedback(GL_POINTS);
if (particles->draw_order == RS::PARTICLES_DRAW_ORDER_LIFETIME) {
- uint32_t lifetime_split = MIN(particles->amount * particles->phase, particles->amount - 1);
+ uint32_t lifetime_split = (MIN(int(particles->amount * particles->phase), particles->amount - 1) + 1) % particles->amount;
uint32_t stride = particles->process_buffer_stride_cache;
glBindBuffer(GL_ARRAY_BUFFER, particles->back_process_buffer);
@@ -1135,14 +1135,13 @@ void ParticlesStorage::_particles_reverse_lifetime_sort(Particles *particles) {
glGetBufferSubData(GL_ARRAY_BUFFER, 0, buffer_size, particle_array);
#endif
- uint32_t lifetime_split = MIN(particles->amount * particles->sort_buffer_phase, particles->amount - 1);
-
+ uint32_t lifetime_split = (MIN(int(particles->amount * particles->sort_buffer_phase), particles->amount - 1) + 1) % particles->amount;
for (uint32_t i = 0; i < lifetime_split / 2; i++) {
- SWAP(particle_array[i], particle_array[lifetime_split - i]);
+ SWAP(particle_array[i], particle_array[lifetime_split - i - 1]);
}
for (uint32_t i = 0; i < (particles->amount - lifetime_split) / 2; i++) {
- SWAP(particle_array[lifetime_split + i + 1], particle_array[particles->amount - 1 - i]);
+ SWAP(particle_array[lifetime_split + i], particle_array[particles->amount - 1 - i]);
}
#ifndef __EMSCRIPTEN__
diff --git a/servers/rendering/renderer_rd/storage_rd/particles_storage.cpp b/servers/rendering/renderer_rd/storage_rd/particles_storage.cpp
index 3ed5d7dda8..1f6ec75df1 100644
--- a/servers/rendering/renderer_rd/storage_rd/particles_storage.cpp
+++ b/servers/rendering/renderer_rd/storage_rd/particles_storage.cpp
@@ -1193,7 +1193,7 @@ void ParticlesStorage::particles_set_view_axis(RID p_particles, const Vector3 &p
}
copy_push_constant.order_by_lifetime = (particles->draw_order == RS::PARTICLES_DRAW_ORDER_LIFETIME || particles->draw_order == RS::PARTICLES_DRAW_ORDER_REVERSE_LIFETIME);
- copy_push_constant.lifetime_split = MIN(particles->amount * particles->phase, particles->amount - 1);
+ copy_push_constant.lifetime_split = (MIN(int(particles->amount * particles->phase), particles->amount - 1) + 1) % particles->amount;
copy_push_constant.lifetime_reverse = particles->draw_order == RS::PARTICLES_DRAW_ORDER_REVERSE_LIFETIME;
copy_push_constant.frame_remainder = particles->interpolate ? particles->frame_remainder : 0.0;
@@ -1511,7 +1511,7 @@ void ParticlesStorage::update_particles() {
}
copy_push_constant.order_by_lifetime = (particles->draw_order == RS::PARTICLES_DRAW_ORDER_LIFETIME || particles->draw_order == RS::PARTICLES_DRAW_ORDER_REVERSE_LIFETIME);
- copy_push_constant.lifetime_split = MIN(particles->amount * particles->phase, particles->amount - 1);
+ copy_push_constant.lifetime_split = (MIN(int(particles->amount * particles->phase), particles->amount - 1) + 1) % particles->amount;
copy_push_constant.lifetime_reverse = particles->draw_order == RS::PARTICLES_DRAW_ORDER_REVERSE_LIFETIME;
RD::ComputeListID compute_list = RD::get_singleton()->compute_list_begin();