From 36370cc85fa5835a9b85549cdfa953d8a9b30231 Mon Sep 17 00:00:00 2001 From: vTurbine Date: Thu, 1 Jun 2023 22:53:22 +0200 Subject: [PATCH] xrRender: Rain: Skip rain smap resolve if no rain is rendered + Minor refactoring --- src/Layers/xrRenderPC_GL/CMakeLists.txt | 1 - src/Layers/xrRenderPC_GL/xrRender_GL.vcxproj | 1 - .../xrRenderPC_GL/xrRender_GL.vcxproj.filters | 3 -- src/Layers/xrRenderPC_R4/xrRender_R4.vcxproj | 1 - .../xrRenderPC_R4/xrRender_R4.vcxproj.filters | 3 -- src/Layers/xrRender_R2/r2.h | 1 + src/Layers/xrRender_R2/r3_R_rain.cpp | 32 +++++++++++-------- .../r3_rendertarget_phase_rain.cpp | 8 ----- 8 files changed, 19 insertions(+), 31 deletions(-) delete mode 100644 src/Layers/xrRender_R2/r3_rendertarget_phase_rain.cpp diff --git a/src/Layers/xrRenderPC_GL/CMakeLists.txt b/src/Layers/xrRenderPC_GL/CMakeLists.txt index ad10f86bcc2..80fa61183e0 100644 --- a/src/Layers/xrRenderPC_GL/CMakeLists.txt +++ b/src/Layers/xrRenderPC_GL/CMakeLists.txt @@ -332,7 +332,6 @@ set(SRC_FILES "../xrRender_R2/r3_rendertarget_mark_msaa_edges.cpp" "../xrRender_R2/r3_rendertarget_phase_ssao.cpp" "../xrRender_R2/r3_rendertarget_phase_smap_D.cpp" - "../xrRender_R2/r3_rendertarget_phase_rain.cpp" "../xrRender_R2/r3_rendertarget_phase_occq.cpp" "../xrRender_R2/r3_rendertarget_phase_scene.cpp" "../xrRender_R2/render_phase_sun.cpp" diff --git a/src/Layers/xrRenderPC_GL/xrRender_GL.vcxproj b/src/Layers/xrRenderPC_GL/xrRender_GL.vcxproj index 916679108f5..28ebe1d7d82 100644 --- a/src/Layers/xrRenderPC_GL/xrRender_GL.vcxproj +++ b/src/Layers/xrRenderPC_GL/xrRender_GL.vcxproj @@ -137,7 +137,6 @@ - diff --git a/src/Layers/xrRenderPC_GL/xrRender_GL.vcxproj.filters b/src/Layers/xrRenderPC_GL/xrRender_GL.vcxproj.filters index d998a699c7b..ed3707ff0fb 100644 --- a/src/Layers/xrRenderPC_GL/xrRender_GL.vcxproj.filters +++ b/src/Layers/xrRenderPC_GL/xrRender_GL.vcxproj.filters @@ -645,9 +645,6 @@ Core_Target - - Core_Target - Core_Target diff --git a/src/Layers/xrRenderPC_R4/xrRender_R4.vcxproj b/src/Layers/xrRenderPC_R4/xrRender_R4.vcxproj index 574aa303b31..81735173a88 100644 --- a/src/Layers/xrRenderPC_R4/xrRender_R4.vcxproj +++ b/src/Layers/xrRenderPC_R4/xrRender_R4.vcxproj @@ -398,7 +398,6 @@ - diff --git a/src/Layers/xrRenderPC_R4/xrRender_R4.vcxproj.filters b/src/Layers/xrRenderPC_R4/xrRender_R4.vcxproj.filters index 86a63ef9a21..affa59df135 100644 --- a/src/Layers/xrRenderPC_R4/xrRender_R4.vcxproj.filters +++ b/src/Layers/xrRenderPC_R4/xrRender_R4.vcxproj.filters @@ -1286,9 +1286,6 @@ Core_Target - - Core_Target - Core_Target diff --git a/src/Layers/xrRender_R2/r2.h b/src/Layers/xrRender_R2/r2.h index d66b02b94c5..94c31107ef7 100644 --- a/src/Layers/xrRender_R2/r2.h +++ b/src/Layers/xrRender_R2/r2.h @@ -127,6 +127,7 @@ struct render_rain : public i_render_phase light RainLight; u32 context_id{ R_dsgraph_structure::INVALID_CONTEXT_ID }; + float rain_factor{ 0.0f }; }; struct render_sun : public i_render_phase diff --git a/src/Layers/xrRender_R2/r3_R_rain.cpp b/src/Layers/xrRender_R2/r3_R_rain.cpp index 31ed75a7979..c3df3c66226 100644 --- a/src/Layers/xrRender_R2/r3_R_rain.cpp +++ b/src/Layers/xrRender_R2/r3_R_rain.cpp @@ -44,10 +44,12 @@ static int facetable[6][4] = void render_rain::init() { - o.active = ps_r2_ls_flags.test(R3FLAG_DYN_WET_SURF); - o.active &= (!Device.vCameraPositionSaved.similar(Device.vCameraPosition, EPS_L) || - !Device.vCameraDirectionSaved.similar(Device.vCameraDirection, EPS_L) || - RainLight.frame_render == 0); + rain_factor = g_pGamePersistent->Environment().CurrentEnv.rain_density; + + o.active = ps_r2_ls_flags.test(R3FLAG_DYN_WET_SURF); + o.active &= rain_factor >= EPS_L; + o.active &= !Device.vCameraPositionSaved.similar(Device.vCameraPosition, EPS_L) || + !Device.vCameraDirectionSaved.similar(Device.vCameraDirection, EPS_L); if (!o.active) return; @@ -63,13 +65,6 @@ void render_rain::init() ////////////////////////////////////////////////////////////////////////// void render_rain::calculate() { - float fRainFactor = g_pGamePersistent->Environment().CurrentEnv.rain_density; - if (fRainFactor < EPS_L) - { - RainLight.frame_render = 0; - return; - } - // static const float source_offset = 40.f; static const float source_offset = 10000.f; @@ -332,8 +327,17 @@ void render_rain::flush() cmd_list_imm.set_xform_project(Device.mProject); // Accumulate - RImplementation.Target->phase_rain(cmd_list_imm); // TODO: move into this class as well - RImplementation.Target->draw_rain(cmd_list_imm, RainLight); + if (rain_factor >= EPS_L) + { + PIX_EVENT_CTX(cmd_list_imm, RainApply); - RainLight.frame_render = Device.dwFrame; + cmd_list_imm.set_pass_targets( + RImplementation.Target->rt_Color, /*rt_Normal*/ + nullptr, + nullptr, + RImplementation.Target->rt_MSAADepth + ); + RImplementation.Target->draw_rain(cmd_list_imm, RainLight); + RainLight.frame_render = Device.dwFrame; + } } diff --git a/src/Layers/xrRender_R2/r3_rendertarget_phase_rain.cpp b/src/Layers/xrRender_R2/r3_rendertarget_phase_rain.cpp deleted file mode 100644 index 91ad502366e..00000000000 --- a/src/Layers/xrRender_R2/r3_rendertarget_phase_rain.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include "stdafx.h" - -void CRenderTarget::phase_rain(CBackend& cmd_list) -{ - // TODO: move into rain render - u_setrt(cmd_list, rt_Color /*rt_Normal*/, nullptr, nullptr, rt_MSAADepth); - RImplementation.rmNormal(cmd_list); -}