diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2022-12-23 23:44:02 +0100 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2022-12-23 23:44:02 +0100 |
commit | f064898956786e587c1757b642140b14115fe307 (patch) | |
tree | fbb729be9ec995045b3efe31327bb2860ff09d75 /servers/rendering/renderer_rd/storage_rd | |
parent | d8a0382e3f0d835db8d2ddedd0bca8ff70abae4c (diff) | |
parent | e886a7af818be3287deefab9b18f87014ee60182 (diff) |
Merge pull request #70253 from BastiaanOlij/cleanup_sky_render
Cleanup and improve sky render
Diffstat (limited to 'servers/rendering/renderer_rd/storage_rd')
4 files changed, 45 insertions, 0 deletions
diff --git a/servers/rendering/renderer_rd/storage_rd/light_storage.cpp b/servers/rendering/renderer_rd/storage_rd/light_storage.cpp index ff882c1992..637aff9aac 100644 --- a/servers/rendering/renderer_rd/storage_rd/light_storage.cpp +++ b/servers/rendering/renderer_rd/storage_rd/light_storage.cpp @@ -1315,6 +1315,10 @@ void LightStorage::reflection_atlas_set_size(RID p_ref_atlas, int p_reflection_s ra->reflections.clear(); } + + if (ra->render_buffers.is_valid()) { + ra->render_buffers->cleanup(); + } } int LightStorage::reflection_atlas_get_size(RID p_ref_atlas) const { @@ -1360,6 +1364,9 @@ void LightStorage::reflection_probe_release_atlas_index(RID p_instance) { ERR_FAIL_COND(!atlas); ERR_FAIL_INDEX(rpi->atlas_index, atlas->reflections.size()); atlas->reflections.write[rpi->atlas_index].owner = RID(); + + // TODO investigate if this is enough? shouldn't we be freeing our textures and framebuffers? + rpi->atlas_index = -1; rpi->atlas = RID(); } @@ -1398,6 +1405,10 @@ bool LightStorage::reflection_probe_instance_begin_render(RID p_instance, RID p_ ReflectionProbeInstance *rpi = reflection_probe_instance_owner.get_or_null(p_instance); ERR_FAIL_COND_V(!rpi, false); + if (atlas->render_buffers.is_null()) { + atlas->render_buffers.instantiate(); + } + RD::get_singleton()->draw_command_begin_label("Reflection probe render"); if (LightStorage::get_singleton()->reflection_probe_get_update_mode(rpi->probe) == RS::REFLECTION_PROBE_UPDATE_ALWAYS && atlas->reflection.is_valid() && atlas->size != 256) { @@ -1455,6 +1466,9 @@ bool LightStorage::reflection_probe_instance_begin_render(RID p_instance, RID p_ Vector<RID> fb; fb.push_back(atlas->depth_buffer); atlas->depth_fb = RD::get_singleton()->framebuffer_create(fb); + + atlas->render_buffers->cleanup(); + atlas->render_buffers->configure_for_reflections(Size2i(atlas->size, atlas->size)); } if (rpi->atlas_index == -1) { @@ -1494,6 +1508,13 @@ bool LightStorage::reflection_probe_instance_begin_render(RID p_instance, RID p_ return true; } +Ref<RenderSceneBuffers> LightStorage::reflection_probe_atlas_get_render_buffers(RID p_reflection_atlas) { + ReflectionAtlas *atlas = reflection_atlas_owner.get_or_null(p_reflection_atlas); + ERR_FAIL_COND_V(!atlas, Ref<RenderSceneBuffersRD>()); + + return atlas->render_buffers; +} + bool LightStorage::reflection_probe_instance_postprocess_step(RID p_instance) { ReflectionProbeInstance *rpi = reflection_probe_instance_owner.get_or_null(p_instance); ERR_FAIL_COND_V(!rpi, false); diff --git a/servers/rendering/renderer_rd/storage_rd/light_storage.h b/servers/rendering/renderer_rd/storage_rd/light_storage.h index 79006ad982..d31924eeb0 100644 --- a/servers/rendering/renderer_rd/storage_rd/light_storage.h +++ b/servers/rendering/renderer_rd/storage_rd/light_storage.h @@ -38,6 +38,7 @@ #include "servers/rendering/renderer_rd/cluster_builder_rd.h" #include "servers/rendering/renderer_rd/environment/sky.h" #include "servers/rendering/renderer_rd/storage_rd/forward_id_storage.h" +#include "servers/rendering/renderer_rd/storage_rd/render_scene_buffers_rd.h" #include "servers/rendering/renderer_rd/storage_rd/texture_storage.h" #include "servers/rendering/storage/light_storage.h" #include "servers/rendering/storage/utilities.h" @@ -256,6 +257,8 @@ private: Vector<Reflection> reflections; + Ref<RenderSceneBuffersRD> render_buffers; // Further render buffers used. + ClusterBuilderRD *cluster_builder = nullptr; // only used if cluster builder is supported by the renderer. }; @@ -846,6 +849,7 @@ public: virtual bool reflection_probe_instance_needs_redraw(RID p_instance) override; virtual bool reflection_probe_instance_has_reflection(RID p_instance) override; virtual bool reflection_probe_instance_begin_render(RID p_instance, RID p_reflection_atlas) override; + virtual Ref<RenderSceneBuffers> reflection_probe_atlas_get_render_buffers(RID p_reflection_atlas) override; virtual bool reflection_probe_instance_postprocess_step(RID p_instance) override; uint32_t reflection_probe_instance_get_resolution(RID p_instance); diff --git a/servers/rendering/renderer_rd/storage_rd/render_scene_buffers_rd.cpp b/servers/rendering/renderer_rd/storage_rd/render_scene_buffers_rd.cpp index 0c2092f03e..fd7b62cd6c 100644 --- a/servers/rendering/renderer_rd/storage_rd/render_scene_buffers_rd.cpp +++ b/servers/rendering/renderer_rd/storage_rd/render_scene_buffers_rd.cpp @@ -207,6 +207,21 @@ void RenderSceneBuffersRD::configure(RID p_render_target, const Size2i p_interna } } +void RenderSceneBuffersRD::configure_for_reflections(const Size2i p_reflection_size) { + // For now our render buffers for reflections are only used for effects/environment (Sky/Fog/Etc) + // Possibly at some point move our entire reflection atlas buffer management into this class + + target_size = p_reflection_size; + internal_size = p_reflection_size; + render_target = RID(); + fsr_sharpness = 0.0; + msaa_3d = RS::VIEWPORT_MSAA_DISABLED; + screen_space_aa = RS::VIEWPORT_SCREEN_SPACE_AA_DISABLED; + use_taa = false; + use_debanding = false; + view_count = 1; +} + void RenderSceneBuffersRD::set_fsr_sharpness(float p_fsr_sharpness) { fsr_sharpness = p_fsr_sharpness; } @@ -483,6 +498,10 @@ void RenderSceneBuffersRD::set_custom_data(const StringName &p_name, Ref<RenderB } Ref<RenderBufferCustomDataRD> RenderSceneBuffersRD::get_custom_data(const StringName &p_name) const { + if (!data_buffers.has(p_name)) { + print_line("test"); + } + ERR_FAIL_COND_V(!data_buffers.has(p_name), Ref<RenderBufferCustomDataRD>()); Ref<RenderBufferCustomDataRD> ret = data_buffers[p_name]; diff --git a/servers/rendering/renderer_rd/storage_rd/render_scene_buffers_rd.h b/servers/rendering/renderer_rd/storage_rd/render_scene_buffers_rd.h index 6907f69b93..4b82f70e1a 100644 --- a/servers/rendering/renderer_rd/storage_rd/render_scene_buffers_rd.h +++ b/servers/rendering/renderer_rd/storage_rd/render_scene_buffers_rd.h @@ -140,6 +140,7 @@ public: void cleanup(); virtual void configure(RID p_render_target, const Size2i p_internal_size, const Size2i p_target_size, float p_fsr_sharpness, float p_texture_mipmap_bias, RS::ViewportMSAA p_msaa_3d, RenderingServer::ViewportScreenSpaceAA p_screen_space_aa, bool p_use_taa, bool p_use_debanding, uint32_t p_view_count) override; + void configure_for_reflections(const Size2i p_reflection_size); virtual void set_fsr_sharpness(float p_fsr_sharpness) override; virtual void set_texture_mipmap_bias(float p_texture_mipmap_bias) override; virtual void set_use_debanding(bool p_use_debanding) override; |