From d6780cc2bc0c0fe385d78c151118f49bd207cff9 Mon Sep 17 00:00:00 2001 From: Xottab-DUTY Date: Tue, 17 Mar 2020 22:10:25 +0500 Subject: [PATCH] Dynamic support for old/new shadow cascades for R2/R3/R4 (#382) --- src/Layers/xrRender/ResourceManager.cpp | 46 +++++++++++++++++++ src/Layers/xrRenderPC_GL/gl_R_render.cpp | 2 +- .../gl_rendertarget_accum_direct.cpp | 20 ++++++-- src/Layers/xrRenderPC_GL/rgl.cpp | 1 + src/Layers/xrRenderPC_GL/rgl.h | 1 + src/Layers/xrRenderPC_R2/r2.cpp | 1 + src/Layers/xrRenderPC_R2/r2.h | 1 + src/Layers/xrRenderPC_R2/r2_R_render.cpp | 2 +- src/Layers/xrRenderPC_R2/r2_rendertarget.cpp | 36 ++++++++------- src/Layers/xrRenderPC_R2/r2_rendertarget.h | 5 +- .../r2_rendertarget_accum_direct.cpp | 19 +++----- src/Layers/xrRenderPC_R3/r3.cpp | 1 + src/Layers/xrRenderPC_R3/r3.h | 1 + src/Layers/xrRenderPC_R3/r3_R_render.cpp | 2 +- .../r3_rendertarget_accum_direct.cpp | 20 ++++++-- src/Layers/xrRenderPC_R4/r4.cpp | 1 + src/Layers/xrRenderPC_R4/r4.h | 1 + src/Layers/xrRenderPC_R4/r4_R_render.cpp | 2 +- .../r4_rendertarget_accum_direct.cpp | 20 ++++++-- 19 files changed, 133 insertions(+), 49 deletions(-) diff --git a/src/Layers/xrRender/ResourceManager.cpp b/src/Layers/xrRender/ResourceManager.cpp index 27b335e2f20..9be767f5831 100644 --- a/src/Layers/xrRender/ResourceManager.cpp +++ b/src/Layers/xrRender/ResourceManager.cpp @@ -308,6 +308,52 @@ void CResourceManager::CompatibilityCheck() RImplementation.m_hq_skinning = hq_skinning; FS.r_close(skinh); } +#if RENDER != R_R1 + // Check shadow cascades type (old SOC/CS or new COP) + if (psDeviceFlags.test(rsR2)) + { + // Check for new cascades support on R2 + IReader* accumSunNearCascade = open_shader("accum_sun_near_cascade.ps"); + RImplementation.o.oldshadowcascades = !accumSunNearCascade; + ps_r2_ls_flags_ext.set(R2FLAGEXT_SUN_OLD, !accumSunNearCascade); + FS.r_close(accumSunNearCascade); + } + else if (!psDeviceFlags.test(rsR1)) + { + IReader* accumSunNear = open_shader("accum_sun_near.ps"); + R_ASSERT3(accumSunNear, "Can't open shader", "accum_sun_near.ps"); + bool oldCascades = false; + do + { + pcstr begin = strstr((cpcstr)accumSunNear->pointer(), "float4"); + if (!begin) + break; + + begin = strstr(begin, "main"); + if (!begin) + break; + + cpcstr end = strstr(begin, "SV_Target"); + if (!end) + break; + + xr_string str(begin, end); + pcstr ptr = str.data(); + + if (strstr(ptr, "v2p_TL2uv")) + { + oldCascades = true; + } + else if (strstr(ptr, "v2p_volume")) + { + oldCascades = false; + } + } while (false); + RImplementation.o.oldshadowcascades = oldCascades; + ps_r2_ls_flags_ext.set(R2FLAGEXT_SUN_OLD, oldCascades); + FS.r_close(accumSunNear); + } +#endif } Shader* CResourceManager::Create(IBlender* B, LPCSTR s_shader, LPCSTR s_textures, LPCSTR s_constants, LPCSTR s_matrices) diff --git a/src/Layers/xrRenderPC_GL/gl_R_render.cpp b/src/Layers/xrRenderPC_GL/gl_R_render.cpp index b6a3e0cfe1b..33dcd95fc39 100644 --- a/src/Layers/xrRenderPC_GL/gl_R_render.cpp +++ b/src/Layers/xrRenderPC_GL/gl_R_render.cpp @@ -473,7 +473,7 @@ void CRender::Render() { PIX_EVENT(DEFER_SUN); RImplementation.Stats.l_visible ++; - if (!ps_r2_ls_flags_ext.is(R2FLAGEXT_SUN_OLD)) + if (!RImplementation.o.oldshadowcascades) render_sun_cascades(); else { diff --git a/src/Layers/xrRenderPC_GL/gl_rendertarget_accum_direct.cpp b/src/Layers/xrRenderPC_GL/gl_rendertarget_accum_direct.cpp index 5d8b37eb776..9f12b671ec7 100644 --- a/src/Layers/xrRenderPC_GL/gl_rendertarget_accum_direct.cpp +++ b/src/Layers/xrRenderPC_GL/gl_rendertarget_accum_direct.cpp @@ -1140,8 +1140,9 @@ void CRenderTarget::accum_direct_volumetric(u32 sub_phase, const u32 Offset, con ref_selement Element = s_accum_direct_volumetric->E[0]; + const bool useMinMaxSMThisFrame = use_minmax_sm_this_frame(); //if ( (sub_phase==SE_SUN_NEAR) && use_minmax_sm_this_frame()) - if (use_minmax_sm_this_frame()) + if (useMinMaxSMThisFrame) Element = s_accum_direct_volumetric_minmax->E[0]; // Assume everything was recalculated before this call by accum_direct @@ -1162,7 +1163,10 @@ void CRenderTarget::accum_direct_volumetric(u32 sub_phase, const u32 Offset, con // setup //RCache.set_Element (s_accum_direct_volumetric->E[sub_phase]); RCache.set_Element(Element); - RCache.set_CullMode(CULL_CCW); + if (useMinMaxSMThisFrame || !RImplementation.o.oldshadowcascades) + { + RCache.set_CullMode(CULL_CCW); + } RCache.set_c("Ldynamic_dir", L_dir.x, L_dir.y, L_dir.z, 0); RCache.set_c("Ldynamic_color", L_clr.x, L_clr.y, L_clr.z, 0); RCache.set_c("m_shadow", mShadow); @@ -1199,7 +1203,10 @@ void CRenderTarget::accum_direct_volumetric(u32 sub_phase, const u32 Offset, con else { extern float OLES_SUN_LIMIT_27_01_07; - zMin = 0; /////***************************************************************************************** + if (RImplementation.o.oldshadowcascades) + zMin = ps_r2_sun_near; + else + zMin = 0; /////***************************************************************************************** zMax = OLES_SUN_LIMIT_27_01_07; } @@ -1241,7 +1248,12 @@ void CRenderTarget::accum_direct_volumetric(u32 sub_phase, const u32 Offset, con // setup stencil: we have to draw to both lit and unlit pixels //RCache.set_Stencil (TRUE,D3DCMP_LESSEQUAL,dwLightMarkerID,0xff,0x00); //if( ! RImplementation.o.dx10_msaa ) - RCache.Render(D3DPT_TRIANGLELIST, Offset, 0, 8, 0, 16); + { + if (RImplementation.o.oldshadowcascades) + RCache.Render(D3DPT_TRIANGLELIST, Offset, 0, 4, 0, 2); + else + RCache.Render(D3DPT_TRIANGLELIST, Offset, 0, 8, 0, 16); + } /* else { diff --git a/src/Layers/xrRenderPC_GL/rgl.cpp b/src/Layers/xrRenderPC_GL/rgl.cpp index 97dac95eb8a..fc1f76de980 100644 --- a/src/Layers/xrRenderPC_GL/rgl.cpp +++ b/src/Layers/xrRenderPC_GL/rgl.cpp @@ -250,6 +250,7 @@ void CRender::create() o.depth16 = strstr(Core.Params, "-depth16") ? TRUE : FALSE; o.noshadows = strstr(Core.Params, "-noshadows") ? TRUE : FALSE; o.Tshadows = strstr(Core.Params, "-tsh") ? TRUE : FALSE; + o.oldshadowcascades = ps_r2_ls_flags_ext.test(R2FLAGEXT_SUN_OLD); o.mblur = strstr(Core.Params, "-mblur") ? TRUE : FALSE; o.distortion_enabled = strstr(Core.Params, "-nodistort") ? FALSE : TRUE; o.distortion = o.distortion_enabled; diff --git a/src/Layers/xrRenderPC_GL/rgl.h b/src/Layers/xrRenderPC_GL/rgl.h index e94f7a0e16f..6614478a7d1 100644 --- a/src/Layers/xrRenderPC_GL/rgl.h +++ b/src/Layers/xrRenderPC_GL/rgl.h @@ -84,6 +84,7 @@ class CRender : public D3DXRenderBase u32 sjitter : 1; u32 noshadows : 1; u32 Tshadows : 1; // transluent shadows + u32 oldshadowcascades : 1; u32 disasm : 1; u32 advancedpp : 1; // advanced post process (DOF, SSAO, volumetrics, etc.) u32 volumetricfog : 1; diff --git a/src/Layers/xrRenderPC_R2/r2.cpp b/src/Layers/xrRenderPC_R2/r2.cpp index 366da41cf7e..d588deb5fc9 100644 --- a/src/Layers/xrRenderPC_R2/r2.cpp +++ b/src/Layers/xrRenderPC_R2/r2.cpp @@ -287,6 +287,7 @@ void CRender::create() o.depth16 = (strstr(Core.Params, "-depth16")) ? TRUE : FALSE; o.noshadows = (strstr(Core.Params, "-noshadows")) ? TRUE : FALSE; o.Tshadows = (strstr(Core.Params, "-tsh")) ? TRUE : FALSE; + o.oldshadowcascades = ps_r2_ls_flags_ext.test(R2FLAGEXT_SUN_OLD); o.mblur = (strstr(Core.Params, "-mblur")) ? TRUE : FALSE; o.distortion_enabled = (strstr(Core.Params, "-nodistort")) ? FALSE : TRUE; o.distortion = o.distortion_enabled; diff --git a/src/Layers/xrRenderPC_R2/r2.h b/src/Layers/xrRenderPC_R2/r2.h index ca612eced28..eb402c244a0 100644 --- a/src/Layers/xrRenderPC_R2/r2.h +++ b/src/Layers/xrRenderPC_R2/r2.h @@ -64,6 +64,7 @@ class CRender : public D3DXRenderBase u32 sjitter : 1; u32 noshadows : 1; u32 Tshadows : 1; // transluent shadows + u32 oldshadowcascades : 1; u32 disasm : 1; u32 advancedpp : 1; // advanced post process (DOF, SSAO, volumetrics, etc.) diff --git a/src/Layers/xrRenderPC_R2/r2_R_render.cpp b/src/Layers/xrRenderPC_R2/r2_R_render.cpp index efc05e0e918..3688dda79c8 100644 --- a/src/Layers/xrRenderPC_R2/r2_R_render.cpp +++ b/src/Layers/xrRenderPC_R2/r2_R_render.cpp @@ -447,7 +447,7 @@ void CRender::Render() if (bSUN) { RImplementation.Stats.l_visible++; - if (!ps_r2_ls_flags_ext.is(R2FLAGEXT_SUN_OLD)) + if (!RImplementation.o.oldshadowcascades) render_sun_cascades(); else { diff --git a/src/Layers/xrRenderPC_R2/r2_rendertarget.cpp b/src/Layers/xrRenderPC_R2/r2_rendertarget.cpp index 9d23db5dd25..23982a0199b 100644 --- a/src/Layers/xrRenderPC_R2/r2_rendertarget.cpp +++ b/src/Layers/xrRenderPC_R2/r2_rendertarget.cpp @@ -185,6 +185,24 @@ void generate_jitter(DWORD* dest, u32 elem_count) *dest = color_rgba(samples[2 * it].x, samples[2 * it].y, samples[2 * it + 1].y, samples[2 * it + 1].x); } +void CRenderTarget::reinit_cascades() +{ + if (RImplementation.o.oldshadowcascades) + { + b_accum_direct = new CBlender_accum_direct(); + s_accum_direct.create(b_accum_direct, "r2" DELIMITER "accum_direct"); + if (RImplementation.o.advancedpp) + s_accum_direct_volumetric.create("accum_volumetric_sun"); + } + else + { + b_accum_direct = new CBlender_accum_direct_cascade(); + s_accum_direct.create(b_accum_direct, "r2" DELIMITER "accum_direct_cascade"); + if (RImplementation.o.advancedpp) + s_accum_direct_volumetric.create("accum_volumetric_sun_cascade"); + } +} + CRenderTarget::CRenderTarget() { param_blur = 0.f; @@ -209,8 +227,6 @@ CRenderTarget::CRenderTarget() // Blenders b_occq = new CBlender_light_occq(); b_accum_mask = new CBlender_accum_direct_mask(); - b_accum_direct = new CBlender_accum_direct(); - b_accum_direct_cascade = new CBlender_accum_direct_cascade(); b_accum_point = new CBlender_accum_point(); b_accum_spot = new CBlender_accum_spot(); b_accum_reflected = new CBlender_accum_reflected(); @@ -278,13 +294,6 @@ CRenderTarget::CRenderTarget() rt_smap_surf.create(r2_RT_smap_surf, size, size, nullrt); rt_smap_ZB = NULL; s_accum_mask.create(b_accum_mask, "r2" DELIMITER "accum_mask"); - s_accum_direct.create(b_accum_direct, "r2" DELIMITER "accum_direct"); - s_accum_direct_cascade.create(b_accum_direct_cascade, "r2" DELIMITER "accum_direct_cascade"); - if (RImplementation.o.advancedpp) - { - s_accum_direct_volumetric.create("accum_volumetric_sun"); - s_accum_direct_volumetric_cascade.create("accum_volumetric_sun_cascade"); - } } else { @@ -294,14 +303,8 @@ CRenderTarget::CRenderTarget() R_CHK(HW.pDevice->CreateDepthStencilSurface( size, size, D3DFMT_D24X8, D3DMULTISAMPLE_NONE, 0, TRUE, &rt_smap_ZB, NULL)); s_accum_mask.create(b_accum_mask, "r2" DELIMITER "accum_mask"); - s_accum_direct.create(b_accum_direct, "r2" DELIMITER "accum_direct"); - s_accum_direct_cascade.create(b_accum_direct_cascade, "r2" DELIMITER "accum_direct_cascade"); - if (RImplementation.o.advancedpp) - { - s_accum_direct_volumetric.create("accum_volumetric_sun"); - s_accum_direct_volumetric_cascade.create("accum_volumetric_sun_cascade"); - } } + reinit_cascades(); // POINT { @@ -664,7 +667,6 @@ CRenderTarget::~CRenderTarget() xr_delete(b_accum_spot); xr_delete(b_accum_point); xr_delete(b_accum_direct); - xr_delete(b_accum_direct_cascade); xr_delete(b_accum_mask); xr_delete(b_occq); } diff --git a/src/Layers/xrRenderPC_R2/r2_rendertarget.h b/src/Layers/xrRenderPC_R2/r2_rendertarget.h index 3d66d25d268..81f4596f71d 100644 --- a/src/Layers/xrRenderPC_R2/r2_rendertarget.h +++ b/src/Layers/xrRenderPC_R2/r2_rendertarget.h @@ -23,7 +23,6 @@ class CRenderTarget : public IRender_Target IBlender* b_occq; IBlender* b_accum_mask; IBlender* b_accum_direct; - IBlender* b_accum_direct_cascade; IBlender* b_accum_point; IBlender* b_accum_spot; IBlender* b_accum_reflected; @@ -91,9 +90,7 @@ class CRenderTarget : public IRender_Target // Accum ref_shader s_accum_mask; ref_shader s_accum_direct; - ref_shader s_accum_direct_cascade; ref_shader s_accum_direct_volumetric; - ref_shader s_accum_direct_volumetric_cascade; ref_shader s_accum_point; ref_shader s_accum_spot; ref_shader s_accum_reflected; @@ -179,6 +176,8 @@ class CRenderTarget : public IRender_Target public: CRenderTarget(); ~CRenderTarget(); + void reinit_cascades(); + void accum_point_geom_create(); void accum_point_geom_destroy(); void accum_omnip_geom_create(); diff --git a/src/Layers/xrRenderPC_R2/r2_rendertarget_accum_direct.cpp b/src/Layers/xrRenderPC_R2/r2_rendertarget_accum_direct.cpp index 5ebbe598797..d5f7b764d15 100644 --- a/src/Layers/xrRenderPC_R2/r2_rendertarget_accum_direct.cpp +++ b/src/Layers/xrRenderPC_R2/r2_rendertarget_accum_direct.cpp @@ -414,7 +414,7 @@ void CRenderTarget::accum_direct_cascade(u32 sub_phase, Fmatrix& xform, Fmatrix& RCache.set_Geometry(g_combine_cuboid); // setup - RCache.set_Element(s_accum_direct_cascade->E[sub_phase]); + RCache.set_Element(s_accum_direct->E[sub_phase]); RCache.set_c("m_texgen", m_Texgen); RCache.set_c("Ldynamic_dir", L_dir.x, L_dir.y, L_dir.z, 0); @@ -851,10 +851,7 @@ void CRenderTarget::accum_direct_volumetric(u32 sub_phase, const u32 Offset, con pszSMapName = r2_RT_smap_surf; // s_smap - STextureList* _T = &*s_accum_direct_volumetric_cascade->E[0]->passes[0]->T; - - if (ps_r2_ls_flags_ext.is(R2FLAGEXT_SUN_OLD)) - _T = &*s_accum_direct_volumetric->E[0]->passes[0]->T; + STextureList* _T = &*s_accum_direct_volumetric->E[0]->passes[0]->T; STextureList::iterator _it = _T->begin(); STextureList::iterator _end = _T->end(); @@ -884,12 +881,9 @@ void CRenderTarget::accum_direct_volumetric(u32 sub_phase, const u32 Offset, con // RCache.set_Geometry (g_combine_2UV); // setup - - if (ps_r2_ls_flags_ext.is(R2FLAGEXT_SUN_OLD)) - RCache.set_Element(s_accum_direct_volumetric->E[0]); - else + RCache.set_Element(s_accum_direct_volumetric->E[0]); + if (!RImplementation.o.oldshadowcascades) { - RCache.set_Element(s_accum_direct_volumetric_cascade->E[0]); RCache.set_CullMode(CULL_CCW); } @@ -916,11 +910,10 @@ void CRenderTarget::accum_direct_volumetric(u32 sub_phase, const u32 Offset, con else { extern float OLES_SUN_LIMIT_27_01_07; - if (ps_r2_ls_flags_ext.is(R2FLAGEXT_SUN_OLD)) + if (RImplementation.o.oldshadowcascades) zMin = ps_r2_sun_near; else zMin = 0; /////***************************************************************************************** - zMax = OLES_SUN_LIMIT_27_01_07; } @@ -960,7 +953,7 @@ void CRenderTarget::accum_direct_volumetric(u32 sub_phase, const u32 Offset, con // setup stencil: we have to draw to both lit and unlit pixels // RCache.set_Stencil (TRUE,D3DCMP_LESSEQUAL,dwLightMarkerID,0xff,0x00); - if (ps_r2_ls_flags_ext.is(R2FLAGEXT_SUN_OLD)) + if (RImplementation.o.oldshadowcascades) RCache.Render(D3DPT_TRIANGLELIST, Offset, 0, 4, 0, 2); else RCache.Render(D3DPT_TRIANGLELIST, Offset, 0, 8, 0, 16); diff --git a/src/Layers/xrRenderPC_R3/r3.cpp b/src/Layers/xrRenderPC_R3/r3.cpp index 0c48d4042fd..3982494b703 100644 --- a/src/Layers/xrRenderPC_R3/r3.cpp +++ b/src/Layers/xrRenderPC_R3/r3.cpp @@ -295,6 +295,7 @@ void CRender::create() o.depth16 = (strstr(Core.Params, "-depth16")) ? TRUE : FALSE; o.noshadows = (strstr(Core.Params, "-noshadows")) ? TRUE : FALSE; o.Tshadows = (strstr(Core.Params, "-tsh")) ? TRUE : FALSE; + o.oldshadowcascades = ps_r2_ls_flags_ext.test(R2FLAGEXT_SUN_OLD); o.mblur = (strstr(Core.Params, "-mblur")) ? TRUE : FALSE; o.distortion_enabled = (strstr(Core.Params, "-nodistort")) ? FALSE : TRUE; o.distortion = o.distortion_enabled; diff --git a/src/Layers/xrRenderPC_R3/r3.h b/src/Layers/xrRenderPC_R3/r3.h index 85b7e6fceee..f65798565eb 100644 --- a/src/Layers/xrRenderPC_R3/r3.h +++ b/src/Layers/xrRenderPC_R3/r3.h @@ -82,6 +82,7 @@ class CRender : public D3DXRenderBase u32 sjitter : 1; u32 noshadows : 1; u32 Tshadows : 1; // transluent shadows + u32 oldshadowcascades : 1; u32 disasm : 1; u32 advancedpp : 1; // advanced post process (DOF, SSAO, volumetrics, etc.) u32 volumetricfog : 1; diff --git a/src/Layers/xrRenderPC_R3/r3_R_render.cpp b/src/Layers/xrRenderPC_R3/r3_R_render.cpp index a357ef1bfb7..5eaf42fcd24 100644 --- a/src/Layers/xrRenderPC_R3/r3_R_render.cpp +++ b/src/Layers/xrRenderPC_R3/r3_R_render.cpp @@ -491,7 +491,7 @@ void CRender::Render() { PIX_EVENT(DEFER_SUN); RImplementation.Stats.l_visible++; - if (!ps_r2_ls_flags_ext.is(R2FLAGEXT_SUN_OLD)) + if (!RImplementation.o.oldshadowcascades) render_sun_cascades(); else { diff --git a/src/Layers/xrRenderPC_R3/r3_rendertarget_accum_direct.cpp b/src/Layers/xrRenderPC_R3/r3_rendertarget_accum_direct.cpp index da48a9064bb..e7363100a6b 100644 --- a/src/Layers/xrRenderPC_R3/r3_rendertarget_accum_direct.cpp +++ b/src/Layers/xrRenderPC_R3/r3_rendertarget_accum_direct.cpp @@ -1204,8 +1204,9 @@ void CRenderTarget::accum_direct_volumetric(u32 sub_phase, const u32 Offset, con ref_selement Element = s_accum_direct_volumetric->E[0]; + const bool useMinMaxSMThisFrame = use_minmax_sm_this_frame(); // if ( (sub_phase==SE_SUN_NEAR) && use_minmax_sm_this_frame()) - if (use_minmax_sm_this_frame()) + if (useMinMaxSMThisFrame) Element = s_accum_direct_volumetric_minmax->E[0]; // Assume everything was recalculated before this call by accum_direct @@ -1258,7 +1259,10 @@ void CRenderTarget::accum_direct_volumetric(u32 sub_phase, const u32 Offset, con // setup // RCache.set_Element (s_accum_direct_volumetric->E[sub_phase]); RCache.set_Element(Element); - RCache.set_CullMode(CULL_CCW); + if (useMinMaxSMThisFrame || !RImplementation.o.oldshadowcascades) + { + RCache.set_CullMode(CULL_CCW); + } // RCache.set_c ("Ldynamic_dir", L_dir.x,L_dir.y,L_dir.z,0.f ); RCache.set_c("Ldynamic_color", L_clr.x, L_clr.y, L_clr.z, 0.f); RCache.set_c("m_shadow", mShadow); @@ -1282,7 +1286,10 @@ void CRenderTarget::accum_direct_volumetric(u32 sub_phase, const u32 Offset, con else { extern float OLES_SUN_LIMIT_27_01_07; - zMin = 0; /////***************************************************************************************** + if (RImplementation.o.oldshadowcascades) + zMin = ps_r2_sun_near; + else + zMin = 0; /////***************************************************************************************** zMax = OLES_SUN_LIMIT_27_01_07; } @@ -1324,7 +1331,12 @@ void CRenderTarget::accum_direct_volumetric(u32 sub_phase, const u32 Offset, con // setup stencil: we have to draw to both lit and unlit pixels // RCache.set_Stencil (TRUE,D3DCMP_LESSEQUAL,dwLightMarkerID,0xff,0x00); // if( ! RImplementation.o.dx10_msaa ) - RCache.Render(D3DPT_TRIANGLELIST, Offset, 0, 8, 0, 16); + { + if (RImplementation.o.oldshadowcascades) + RCache.Render(D3DPT_TRIANGLELIST, Offset, 0, 4, 0, 2); + else + RCache.Render(D3DPT_TRIANGLELIST, Offset, 0, 8, 0, 16); + } /* else { diff --git a/src/Layers/xrRenderPC_R4/r4.cpp b/src/Layers/xrRenderPC_R4/r4.cpp index 5beb4c282d7..0a45b750e81 100644 --- a/src/Layers/xrRenderPC_R4/r4.cpp +++ b/src/Layers/xrRenderPC_R4/r4.cpp @@ -300,6 +300,7 @@ void CRender::create() o.depth16 = (strstr(Core.Params, "-depth16")) ? TRUE : FALSE; o.noshadows = (strstr(Core.Params, "-noshadows")) ? TRUE : FALSE; o.Tshadows = (strstr(Core.Params, "-tsh")) ? TRUE : FALSE; + o.oldshadowcascades = ps_r2_ls_flags_ext.test(R2FLAGEXT_SUN_OLD); o.mblur = (strstr(Core.Params, "-mblur")) ? TRUE : FALSE; o.distortion_enabled = (strstr(Core.Params, "-nodistort")) ? FALSE : TRUE; o.distortion = o.distortion_enabled; diff --git a/src/Layers/xrRenderPC_R4/r4.h b/src/Layers/xrRenderPC_R4/r4.h index e47e4e5986a..b326c6341ac 100644 --- a/src/Layers/xrRenderPC_R4/r4.h +++ b/src/Layers/xrRenderPC_R4/r4.h @@ -90,6 +90,7 @@ class CRender : public D3DXRenderBase u32 sjitter : 1; u32 noshadows : 1; u32 Tshadows : 1; // transluent shadows + u32 oldshadowcascades : 1; u32 disasm : 1; u32 advancedpp : 1; // advanced post process (DOF, SSAO, volumetrics, etc.) u32 volumetricfog : 1; diff --git a/src/Layers/xrRenderPC_R4/r4_R_render.cpp b/src/Layers/xrRenderPC_R4/r4_R_render.cpp index cef50c6715e..cd6253daaef 100644 --- a/src/Layers/xrRenderPC_R4/r4_R_render.cpp +++ b/src/Layers/xrRenderPC_R4/r4_R_render.cpp @@ -492,7 +492,7 @@ void CRender::Render() { PIX_EVENT(DEFER_SUN); Stats.l_visible++; - if (!ps_r2_ls_flags_ext.is(R2FLAGEXT_SUN_OLD)) + if (!RImplementation.o.oldshadowcascades) render_sun_cascades(); else { diff --git a/src/Layers/xrRenderPC_R4/r4_rendertarget_accum_direct.cpp b/src/Layers/xrRenderPC_R4/r4_rendertarget_accum_direct.cpp index 98e19a7dcbc..3ca94ad727e 100644 --- a/src/Layers/xrRenderPC_R4/r4_rendertarget_accum_direct.cpp +++ b/src/Layers/xrRenderPC_R4/r4_rendertarget_accum_direct.cpp @@ -1204,8 +1204,9 @@ void CRenderTarget::accum_direct_volumetric(u32 sub_phase, const u32 Offset, con ref_selement Element = s_accum_direct_volumetric->E[0]; + const bool useMinMaxSMThisFrame = use_minmax_sm_this_frame(); // if ( (sub_phase==SE_SUN_NEAR) && use_minmax_sm_this_frame()) - if (use_minmax_sm_this_frame()) + if (useMinMaxSMThisFrame) Element = s_accum_direct_volumetric_minmax->E[0]; // Assume everything was recalculated before this call by accum_direct @@ -1258,7 +1259,10 @@ void CRenderTarget::accum_direct_volumetric(u32 sub_phase, const u32 Offset, con // setup // RCache.set_Element (s_accum_direct_volumetric->E[sub_phase]); RCache.set_Element(Element); - RCache.set_CullMode(CULL_CCW); + if (useMinMaxSMThisFrame || !RImplementation.o.oldshadowcascades) + { + RCache.set_CullMode(CULL_CCW); + } // RCache.set_c ("Ldynamic_dir", L_dir.x,L_dir.y,L_dir.z,0 ); RCache.set_c("Ldynamic_color", L_clr.x, L_clr.y, L_clr.z, 0.f); RCache.set_c("m_shadow", mShadow); @@ -1282,7 +1286,10 @@ void CRenderTarget::accum_direct_volumetric(u32 sub_phase, const u32 Offset, con else { extern float OLES_SUN_LIMIT_27_01_07; - zMin = 0; /////***************************************************************************************** + if (RImplementation.o.oldshadowcascades) + zMin = ps_r2_sun_near; + else + zMin = 0; /////***************************************************************************************** zMax = OLES_SUN_LIMIT_27_01_07; } @@ -1324,7 +1331,12 @@ void CRenderTarget::accum_direct_volumetric(u32 sub_phase, const u32 Offset, con // setup stencil: we have to draw to both lit and unlit pixels // RCache.set_Stencil (TRUE,D3DCMP_LESSEQUAL,dwLightMarkerID,0xff,0x00); // if( ! RImplementation.o.dx10_msaa ) - RCache.Render(D3DPT_TRIANGLELIST, Offset, 0, 8, 0, 16); + { + if (RImplementation.o.oldshadowcascades) + RCache.Render(D3DPT_TRIANGLELIST, Offset, 0, 4, 0, 2); + else + RCache.Render(D3DPT_TRIANGLELIST, Offset, 0, 8, 0, 16); + } /* else {