Skip to content

Commit

Permalink
Dynamic support for old/new shadow cascades for R2/R3/R4 (#382)
Browse files Browse the repository at this point in the history
  • Loading branch information
Xottab-DUTY committed Mar 17, 2020
1 parent 44a38b0 commit d6780cc
Show file tree
Hide file tree
Showing 19 changed files with 133 additions and 49 deletions.
46 changes: 46 additions & 0 deletions src/Layers/xrRender/ResourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/Layers/xrRenderPC_GL/gl_R_render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
20 changes: 16 additions & 4 deletions src/Layers/xrRenderPC_GL/gl_rendertarget_accum_direct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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
{
Expand Down
1 change: 1 addition & 0 deletions src/Layers/xrRenderPC_GL/rgl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/Layers/xrRenderPC_GL/rgl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/Layers/xrRenderPC_R2/r2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/Layers/xrRenderPC_R2/r2.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.)

Expand Down
2 changes: 1 addition & 1 deletion src/Layers/xrRenderPC_R2/r2_R_render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
36 changes: 19 additions & 17 deletions src/Layers/xrRenderPC_R2/r2_rendertarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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
{
Expand All @@ -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
{
Expand Down Expand Up @@ -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);
}
Expand Down
5 changes: 2 additions & 3 deletions src/Layers/xrRenderPC_R2/r2_rendertarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
19 changes: 6 additions & 13 deletions src/Layers/xrRenderPC_R2/r2_rendertarget_accum_direct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/Layers/xrRenderPC_R3/r3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/Layers/xrRenderPC_R3/r3.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Layers/xrRenderPC_R3/r3_R_render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
20 changes: 16 additions & 4 deletions src/Layers/xrRenderPC_R3/r3_rendertarget_accum_direct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}

Expand Down Expand Up @@ -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
{
Expand Down
1 change: 1 addition & 0 deletions src/Layers/xrRenderPC_R4/r4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/Layers/xrRenderPC_R4/r4.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

1 comment on commit d6780cc

@Xottab-DUTY
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applies to #392 too.

Please sign in to comment.