From af9d1743f38edf21ac9c4fce4bae109203038bc2 Mon Sep 17 00:00:00 2001 From: Arman Elgudzhyan <48544263+puchik@users.noreply.github.com> Date: Fri, 23 Jun 2023 12:16:52 -0700 Subject: [PATCH] Clear specular buffer if bg mode is canvas and ss effects are used Explicitly clear the separate specular buffer when the background mode is canvas and screen space effects (and thus a separate specular buffer) are used. --- .../forward_clustered/render_forward_clustered.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) 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 069b43203f2..ce0b4a9f9c4 100644 --- a/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp +++ b/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp @@ -2028,6 +2028,16 @@ void RenderForwardClustered::_render_scene(RenderDataRD *p_render_data, const Co } } + if (using_separate_specular && is_environment(p_render_data->environment) && (environment_get_background(p_render_data->environment) == RS::ENV_BG_CANVAS)) { + // Canvas background mode does not clear the color buffer, but copies over it. If screen-space specular effects are enabled and the background is blank, + // this results in ghosting due to the separate specular buffer copy. Need to explicitly clear the specular buffer once we're done with it to fix it. + RENDER_TIMESTAMP("Clear Separate Specular (Canvas Background Mode)"); + Vector blank_clear_color; + blank_clear_color.push_back(Color(0.0, 0.0, 0.0)); + RD::get_singleton()->draw_list_begin(rb_data->get_specular_only_fb(), RD::INITIAL_ACTION_CLEAR, RD::FINAL_ACTION_READ, RD::INITIAL_ACTION_DROP, RD::FINAL_ACTION_DISCARD, blank_clear_color); + RD::get_singleton()->draw_list_end(); + } + if (scene_state.used_screen_texture) { RENDER_TIMESTAMP("Copy Screen Texture");