Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 3D materials not updating on texture invalidation #54370

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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);
}
}
}

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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);
}
}
}

Expand All @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions servers/rendering/renderer_rd/renderer_scene_render_rd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down
25 changes: 25 additions & 0 deletions servers/rendering/renderer_rd/renderer_scene_sky_rd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down Expand Up @@ -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);
}
}
}

Expand Down Expand Up @@ -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);
}
}
}

Expand Down Expand Up @@ -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);
}
}
}

Expand Down Expand Up @@ -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);
}
}
}

Expand Down
14 changes: 13 additions & 1 deletion servers/rendering/renderer_rd/renderer_storage_rd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down