Skip to content

Commit

Permalink
Merge pull request #70457 from clayjohn/RD-particles-update
Browse files Browse the repository at this point in the history
Avoid updating particles during 2D rendering
  • Loading branch information
akien-mga committed Dec 23, 2022
2 parents 13850d7 + 41021b0 commit 56b828e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3598,6 +3598,10 @@ void RenderForwardClustered::_geometry_instance_update(RenderGeometryInstance *p
}
ginstance->transforms_uniform_set = particles_storage->particles_get_instance_buffer_uniform_set(ginstance->data->base, scene_shader.default_shader_rd, TRANSFORMS_UNIFORM_SET);

if (particles_storage->particles_get_frame_counter(ginstance->data->base) == 0) {
// Particles haven't been cleared or updated, update once now to ensure they are ready to render.
particles_storage->update_particles();
}
} else if (ginstance->data->base_type == RS::INSTANCE_MESH) {
if (mesh_storage->skeleton_is_valid(ginstance->data->skeleton)) {
ginstance->transforms_uniform_set = mesh_storage->skeleton_get_3d_uniform_set(ginstance->data->skeleton, scene_shader.default_shader_rd, TRANSFORMS_UNIFORM_SET);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2626,6 +2626,10 @@ void RenderForwardMobile::_geometry_instance_update(RenderGeometryInstance *p_ge
}
ginstance->transforms_uniform_set = particles_storage->particles_get_instance_buffer_uniform_set(ginstance->data->base, scene_shader.default_shader_rd, TRANSFORMS_UNIFORM_SET);

if (particles_storage->particles_get_frame_counter(ginstance->data->base) == 0) {
// Particles haven't been cleared or updated, update once now to ensure they are ready to render.
particles_storage->update_particles();
}
} else if (ginstance->data->base_type == RS::INSTANCE_MESH) {
if (mesh_storage->skeleton_is_valid(ginstance->data->skeleton)) {
ginstance->transforms_uniform_set = mesh_storage->skeleton_get_3d_uniform_set(ginstance->data->skeleton, scene_shader.default_shader_rd, TRANSFORMS_UNIFORM_SET);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ void RendererCanvasRenderRD::_render_item(RD::DrawListID p_draw_list, RID p_rend
ERR_BREAK(particles_storage->particles_get_mode(pt->particles) != RS::PARTICLES_MODE_2D);
particles_storage->particles_request_process(pt->particles);

if (particles_storage->particles_is_inactive(pt->particles)) {
if (particles_storage->particles_is_inactive(pt->particles) || particles_storage->particles_get_frame_counter(pt->particles) == 0) {
break;
}

Expand Down
7 changes: 6 additions & 1 deletion servers/rendering/renderer_rd/storage_rd/particles_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,12 @@ class ParticlesStorage : public RendererParticlesStorage {
return particles->mode;
}

_FORCE_INLINE_ uint32_t particles_get_frame_counter(RID p_particles) {
Particles *particles = particles_owner.get_or_null(p_particles);
ERR_FAIL_COND_V(!particles, false);
return particles->frame_counter;
}

_FORCE_INLINE_ uint32_t particles_get_amount(RID p_particles, uint32_t &r_trail_divisor) {
Particles *particles = particles_owner.get_or_null(p_particles);
ERR_FAIL_COND_V(!particles, 0);
Expand Down Expand Up @@ -487,7 +493,6 @@ class ParticlesStorage : public RendererParticlesStorage {
ERR_FAIL_COND_V(!particles, RID());
if (particles->particles_transforms_buffer_uniform_set.is_null() || !RD::get_singleton()->uniform_set_is_valid(particles->particles_transforms_buffer_uniform_set)) {
_particles_update_buffers(particles);
update_particles();
Vector<RD::Uniform> uniforms;

{
Expand Down

0 comments on commit 56b828e

Please sign in to comment.