Reset SDFGI when changing editor scene tabs

This commit is contained in:
bitsawer 2023-08-30 16:25:27 +03:00
parent bc88dca176
commit 836705d7a9
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; return 0;
} }
void GI::sdfgi_reset() {
}
#endif // GLES3_ENABLED #endif // GLES3_ENABLED

View File

@ -90,6 +90,8 @@ public:
virtual bool voxel_gi_is_using_two_bounces(RID p_voxel_gi) const override; 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 uint32_t voxel_gi_get_version(RID p_voxel_gi) const override;
virtual void sdfgi_reset() override;
}; };
}; // namespace GLES3 }; // namespace GLES3

View File

@ -65,6 +65,7 @@
#include "servers/display_server.h" #include "servers/display_server.h"
#include "servers/navigation_server_3d.h" #include "servers/navigation_server_3d.h"
#include "servers/physics_server_2d.h" #include "servers/physics_server_2d.h"
#include "servers/rendering_server.h"
#include "editor/audio_stream_preview.h" #include "editor/audio_stream_preview.h"
#include "editor/debugger/editor_debugger_node.h" #include "editor/debugger/editor_debugger_node.h"
@ -3463,6 +3464,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())); ScriptEditor::get_singleton()->set_scene_root_script(editor_data.get_scene_root_script(editor_data.get_edited_scene()));
editor_data.notify_edited_scene_changed(); editor_data.notify_edited_scene_changed();
emit_signal(SNAME("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 { 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 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 uint32_t voxel_gi_get_version(RID p_voxel_gi) const override { return 0; }
virtual void sdfgi_reset() override {}
}; };
} // namespace RendererDummy } // namespace RendererDummy

View File

@ -79,6 +79,8 @@ public:
virtual bool voxel_gi_is_using_two_bounces(RID p_voxel_gi) const = 0; 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 uint32_t voxel_gi_get_version(RID p_probe) const = 0;
virtual void sdfgi_reset() = 0;
}; };
#endif // RENDERER_GI_H #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; return &voxel_gi->dependency;
} }
void GI::sdfgi_reset() {
sdfgi_current_version++;
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// SDFGI // 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); 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 }; static const float y_scale[3] = { 2.0, 1.5, 1.0 };
y_mult = y_scale[y_scale_mode]; y_mult = y_scale[y_scale_mode];
version = gi->sdfgi_current_version;
cascades.resize(num_cascades); cascades.resize(num_cascades);
probe_axis_count = SDFGI::PROBE_DIVISOR + 1; probe_axis_count = SDFGI::PROBE_DIVISOR + 1;
solid_cell_ratio = gi->sdfgi_solid_cell_ratio; solid_cell_ratio = gi->sdfgi_solid_cell_ratio;

View File

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

View File

@ -3323,14 +3323,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_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()) { if (sdfgi.is_valid()) {
// delete it // delete it
sdfgi.unref(); sdfgi.unref();
rb->set_custom_data(RB_SCOPE_SDFGI, sdfgi); rb->set_custom_data(RB_SCOPE_SDFGI, sdfgi);
} }
return;
if (!needs_sdfgi) {
return;
}
} }
// Ensure advanced shaders are available if SDFGI is used. // 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_interior, RID, bool)
FUNC2(voxel_gi_set_use_two_bounces, RID, bool) FUNC2(voxel_gi_set_use_two_bounces, RID, bool)
FUNC0(sdfgi_reset)
/* PARTICLES */ /* PARTICLES */
#undef ServerName #undef ServerName

View File

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