Merge pull request #81167 from bitsawer/fix_sdfgi_editor_change

Reset SDFGI when changing editor scene tabs
This commit is contained in:
Rémi Verschelde 2023-10-25 10:27:03 +02:00
commit f021d33940
No known key found for this signature in database
GPG key ID: C3336907360768E1
10 changed files with 32 additions and 2 deletions

View file

@ -137,4 +137,7 @@ uint32_t GI::voxel_gi_get_version(RID p_voxel_gi) const {
return 0;
}
void GI::sdfgi_reset() {
}
#endif // GLES3_ENABLED

View file

@ -85,6 +85,8 @@ public:
virtual bool voxel_gi_is_using_two_bounces(RID p_voxel_gi) const override;
virtual uint32_t voxel_gi_get_version(RID p_voxel_gi) const override;
virtual void sdfgi_reset() override;
};
}; // namespace GLES3

View file

@ -68,6 +68,7 @@
#include "servers/display_server.h"
#include "servers/navigation_server_3d.h"
#include "servers/physics_server_2d.h"
#include "servers/rendering_server.h"
#include "editor/audio_stream_preview.h"
#include "editor/debugger/editor_debugger_node.h"
@ -3577,6 +3578,9 @@ void EditorNode::_set_main_scene_state(Dictionary p_state, Node *p_for_scene) {
ScriptEditor::get_singleton()->set_scene_root_script(editor_data.get_scene_root_script(editor_data.get_edited_scene()));
editor_data.notify_edited_scene_changed();
emit_signal(SNAME("scene_changed"));
// Reset SDFGI after everything else so that any last-second scene modifications will be processed.
RenderingServer::get_singleton()->sdfgi_reset();
}
bool EditorNode::is_changing_scene() const {

View file

@ -78,6 +78,8 @@ public:
virtual bool voxel_gi_is_using_two_bounces(RID p_voxel_gi) const override { return false; }
virtual uint32_t voxel_gi_get_version(RID p_voxel_gi) const override { return 0; }
virtual void sdfgi_reset() override {}
};
} // namespace RendererDummy

View file

@ -79,6 +79,8 @@ public:
virtual bool voxel_gi_is_using_two_bounces(RID p_voxel_gi) const = 0;
virtual uint32_t voxel_gi_get_version(RID p_probe) const = 0;
virtual void sdfgi_reset() = 0;
};
#endif // RENDERER_GI_H

View file

@ -392,6 +392,10 @@ Dependency *GI::voxel_gi_get_dependency(RID p_voxel_gi) const {
return &voxel_gi->dependency;
}
void GI::sdfgi_reset() {
sdfgi_current_version++;
}
////////////////////////////////////////////////////////////////////////////////
// SDFGI
@ -416,6 +420,7 @@ void GI::SDFGI::create(RID p_env, const Vector3 &p_world_position, uint32_t p_re
y_scale_mode = RendererSceneRenderRD::get_singleton()->environment_get_sdfgi_y_scale(p_env);
static const float y_scale[3] = { 2.0, 1.5, 1.0 };
y_mult = y_scale[y_scale_mode];
version = gi->sdfgi_current_version;
cascades.resize(num_cascades);
probe_axis_count = SDFGI::PROBE_DIVISOR + 1;
solid_cell_ratio = gi->sdfgi_solid_cell_ratio;

View file

@ -667,6 +667,7 @@ public:
float y_mult = 1.0;
uint32_t version = 0;
uint32_t render_pass = 0;
int32_t cascade_dynamic_light_count[SDFGI::MAX_CASCADES]; //used dynamically
@ -701,11 +702,14 @@ public:
Vector3 sdfgi_debug_probe_dir;
bool sdfgi_debug_probe_enabled = false;
Vector3i sdfgi_debug_probe_index;
uint32_t sdfgi_current_version = 0;
/* SDFGI UPDATE */
int sdfgi_get_lightprobe_octahedron_size() const { return SDFGI::LIGHTPROBE_OCT_SIZE; }
virtual void sdfgi_reset() override;
struct SDFGIData {
float grid_size[3];
uint32_t max_cascades;

View file

@ -3486,14 +3486,18 @@ void RenderForwardClustered::sdfgi_update(const Ref<RenderSceneBuffers> &p_rende
}
bool needs_sdfgi = p_environment.is_valid() && environment_get_sdfgi_enabled(p_environment);
bool needs_reset = sdfgi.is_valid() ? sdfgi->version != gi.sdfgi_current_version : false;
if (!needs_sdfgi) {
if (!needs_sdfgi || needs_reset) {
if (sdfgi.is_valid()) {
// delete it
sdfgi.unref();
rb->set_custom_data(RB_SCOPE_SDFGI, sdfgi);
}
return;
if (!needs_sdfgi) {
return;
}
}
// Ensure advanced shaders are available if SDFGI is used.

View file

@ -476,6 +476,8 @@ public:
FUNC2(voxel_gi_set_interior, RID, bool)
FUNC2(voxel_gi_set_use_two_bounces, RID, bool)
FUNC0(sdfgi_reset)
/* PARTICLES */
#undef ServerName

View file

@ -633,6 +633,8 @@ public:
virtual void voxel_gi_set_quality(VoxelGIQuality) = 0;
virtual void sdfgi_reset() = 0;
/* LIGHTMAP */
virtual RID lightmap_create() = 0;