diff --git a/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp b/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp index 0f5af964173a..948bd303d067 100644 --- a/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp +++ b/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp @@ -30,6 +30,7 @@ #include "render_forward_clustered.h" #include "core/config/project_settings.h" +#include "servers/rendering/renderer_rd/renderer_compositor_rd.h" #include "servers/rendering/rendering_device.h" #include "servers/rendering/rendering_server_default.h" @@ -2644,6 +2645,13 @@ void RenderForwardClustered::_geometry_instance_add_surface(GeometryInstanceForw material = (SceneShaderForwardClustered::MaterialData *)storage->material_get_data(m_src, RendererStorageRD::SHADER_TYPE_3D); if (!material || !material->shader_data->valid) { material = nullptr; + } else if (material->last_frame != RendererCompositorRD::singleton->get_frame_number()) { + material->last_frame = RendererCompositorRD::singleton->get_frame_number(); + if (!RD::get_singleton()->uniform_set_is_valid(material->uniform_set)) { + // Uniform set may be gone because a dependency was erased. In this case, it will happen + // if a texture is deleted, so just re-create it. + storage->material_force_update_textures(m_src, RendererStorageRD::SHADER_TYPE_3D); + } } } @@ -2665,6 +2673,11 @@ void RenderForwardClustered::_geometry_instance_add_surface(GeometryInstanceForw material = (SceneShaderForwardClustered::MaterialData *)storage->material_get_data(next_pass, RendererStorageRD::SHADER_TYPE_3D); if (!material || !material->shader_data->valid) { break; + } else if (material->last_frame != RendererCompositorRD::singleton->get_frame_number()) { + material->last_frame = RendererCompositorRD::singleton->get_frame_number(); + if (!RD::get_singleton()->uniform_set_is_valid(material->uniform_set)) { + storage->material_force_update_textures(m_src, RendererStorageRD::SHADER_TYPE_3D); + } } if (ginstance->data->dirty_dependencies) { storage->material_update_dependency(next_pass, &ginstance->data->dependency_tracker); diff --git a/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp b/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp index 95f5b4683172..bd8c55ce00cb 100644 --- a/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp +++ b/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp @@ -30,6 +30,7 @@ #include "render_forward_mobile.h" #include "core/config/project_settings.h" +#include "servers/rendering/renderer_rd/renderer_compositor_rd.h" #include "servers/rendering/rendering_device.h" #include "servers/rendering/rendering_server_default.h" @@ -2362,6 +2363,11 @@ void RenderForwardMobile::_geometry_instance_add_surface(GeometryInstanceForward material = (SceneShaderForwardMobile::MaterialData *)storage->material_get_data(m_src, RendererStorageRD::SHADER_TYPE_3D); if (!material || !material->shader_data->valid) { material = nullptr; + } else if (material->last_frame != RendererCompositorRD::singleton->get_frame_number()) { + material->last_frame = RendererCompositorRD::singleton->get_frame_number(); + if (!RD::get_singleton()->uniform_set_is_valid(material->uniform_set)) { + storage->material_force_update_textures(m_src, RendererStorageRD::SHADER_TYPE_3D); + } } } @@ -2383,6 +2389,11 @@ void RenderForwardMobile::_geometry_instance_add_surface(GeometryInstanceForward material = (SceneShaderForwardMobile::MaterialData *)storage->material_get_data(next_pass, RendererStorageRD::SHADER_TYPE_3D); if (!material || !material->shader_data->valid) { break; + } else if (material->last_frame != RendererCompositorRD::singleton->get_frame_number()) { + material->last_frame = RendererCompositorRD::singleton->get_frame_number(); + if (!RD::get_singleton()->uniform_set_is_valid(material->uniform_set)) { + storage->material_force_update_textures(m_src, RendererStorageRD::SHADER_TYPE_3D); + } } if (ginstance->data->dirty_dependencies) { storage->material_update_dependency(next_pass, &ginstance->data->dependency_tracker); diff --git a/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp b/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp index 3d8ae4c944b5..060021e7ae12 100644 --- a/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp +++ b/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp @@ -3903,6 +3903,11 @@ void RendererSceneRenderRD::_update_volumetric_fog(RID p_render_buffers, RID p_e material = (FogMaterialData *)storage->material_get_data(fog_material, RendererStorageRD::SHADER_TYPE_FOG); if (!material || !material->shader_data->valid) { material = nullptr; + } else if (material->last_frame != RendererCompositorRD::singleton->get_frame_number()) { + material->last_frame = RendererCompositorRD::singleton->get_frame_number(); + if (!RD::get_singleton()->uniform_set_is_valid(material->uniform_set)) { + storage->material_force_update_textures(fog_material, RendererStorageRD::SHADER_TYPE_FOG); + } } } diff --git a/servers/rendering/renderer_rd/renderer_scene_sky_rd.cpp b/servers/rendering/renderer_rd/renderer_scene_sky_rd.cpp index ce41e191e20f..af5a521277b9 100644 --- a/servers/rendering/renderer_rd/renderer_scene_sky_rd.cpp +++ b/servers/rendering/renderer_rd/renderer_scene_sky_rd.cpp @@ -1048,6 +1048,11 @@ void RendererSceneSkyRD::setup(RendererSceneEnvironmentRD *p_env, RID p_render_b material = (SkyMaterialData *)storage->material_get_data(sky_material, RendererStorageRD::SHADER_TYPE_SKY); if (!material || !material->shader_data->valid) { material = nullptr; + } else if (material->last_frame != RendererCompositorRD::singleton->get_frame_number()) { + material->last_frame = RendererCompositorRD::singleton->get_frame_number(); + if (!RD::get_singleton()->uniform_set_is_valid(material->uniform_set)) { + storage->material_force_update_textures(sky_material, RendererStorageRD::SHADER_TYPE_SKY); + } } } @@ -1203,6 +1208,11 @@ void RendererSceneSkyRD::update(RendererSceneEnvironmentRD *p_env, const CameraM material = (SkyMaterialData *)storage->material_get_data(sky_material, RendererStorageRD::SHADER_TYPE_SKY); if (!material || !material->shader_data->valid) { material = nullptr; + } else if (material->last_frame != RendererCompositorRD::singleton->get_frame_number()) { + material->last_frame = RendererCompositorRD::singleton->get_frame_number(); + if (!RD::get_singleton()->uniform_set_is_valid(material->uniform_set)) { + storage->material_force_update_textures(sky_material, RendererStorageRD::SHADER_TYPE_SKY); + } } } @@ -1378,6 +1388,11 @@ void RendererSceneSkyRD::draw(RendererSceneEnvironmentRD *p_env, bool p_can_cont material = (SkyMaterialData *)storage->material_get_data(sky_material, RendererStorageRD::SHADER_TYPE_SKY); if (!material || !material->shader_data->valid) { material = nullptr; + } else if (material->last_frame != RendererCompositorRD::singleton->get_frame_number()) { + material->last_frame = RendererCompositorRD::singleton->get_frame_number(); + if (!RD::get_singleton()->uniform_set_is_valid(material->uniform_set)) { + storage->material_force_update_textures(sky_material, RendererStorageRD::SHADER_TYPE_SKY); + } } } @@ -1481,6 +1496,11 @@ void RendererSceneSkyRD::update_res_buffers(RendererSceneEnvironmentRD *p_env, u material = (SkyMaterialData *)storage->material_get_data(sky_material, RendererStorageRD::SHADER_TYPE_SKY); if (!material || !material->shader_data->valid) { material = nullptr; + } else if (material->last_frame != RendererCompositorRD::singleton->get_frame_number()) { + material->last_frame = RendererCompositorRD::singleton->get_frame_number(); + if (!RD::get_singleton()->uniform_set_is_valid(material->uniform_set)) { + storage->material_force_update_textures(sky_material, RendererStorageRD::SHADER_TYPE_SKY); + } } } @@ -1568,6 +1588,11 @@ void RendererSceneSkyRD::draw(RD::DrawListID p_draw_list, RendererSceneEnvironme material = (SkyMaterialData *)storage->material_get_data(sky_material, RendererStorageRD::SHADER_TYPE_SKY); if (!material || !material->shader_data->valid) { material = nullptr; + } else if (material->last_frame != RendererCompositorRD::singleton->get_frame_number()) { + material->last_frame = RendererCompositorRD::singleton->get_frame_number(); + if (!RD::get_singleton()->uniform_set_is_valid(material->uniform_set)) { + storage->material_force_update_textures(sky_material, RendererStorageRD::SHADER_TYPE_SKY); + } } } diff --git a/servers/rendering/renderer_rd/renderer_storage_rd.cpp b/servers/rendering/renderer_rd/renderer_storage_rd.cpp index d2c8d0e47c4c..c53deeae75e9 100644 --- a/servers/rendering/renderer_rd/renderer_storage_rd.cpp +++ b/servers/rendering/renderer_rd/renderer_storage_rd.cpp @@ -5291,7 +5291,19 @@ void RendererStorageRD::_particles_process(Particles *p_particles, double p_delt RD::get_singleton()->buffer_update(p_particles->frame_params_buffer, 0, sizeof(ParticlesFrameParams) * p_particles->trail_params.size(), p_particles->trail_params.ptr()); - ParticlesMaterialData *m = (ParticlesMaterialData *)material_get_data(p_particles->process_material, SHADER_TYPE_PARTICLES); + ParticlesMaterialData *m = nullptr; + if (p_particles->process_material.is_valid()) { + m = (ParticlesMaterialData *)material_get_data(p_particles->process_material, SHADER_TYPE_PARTICLES); + if (!m || !m->shader_data) { + m = nullptr; + } else if (m->last_frame != RendererCompositorRD::singleton->get_frame_number()) { + m->last_frame = RendererCompositorRD::singleton->get_frame_number(); + if (!RD::get_singleton()->uniform_set_is_valid(m->uniform_set)) { + material_force_update_textures(p_particles->process_material, RendererStorageRD::SHADER_TYPE_PARTICLES); + } + } + } + if (!m) { m = (ParticlesMaterialData *)material_get_data(particles_shader.default_material, SHADER_TYPE_PARTICLES); }