Skip to content

Commit

Permalink
* UPD: [xrRender] Various fixes, water SSR works again
Browse files Browse the repository at this point in the history
  • Loading branch information
yohjimane committed Nov 6, 2024
1 parent 5ae28ab commit 239e169
Show file tree
Hide file tree
Showing 15 changed files with 200 additions and 51 deletions.
1 change: 1 addition & 0 deletions src/Layers/xrRender/SkeletonX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ void CSkeletonX::_Render(CBackend& cmd_list, ref_geom& hGeom, u32 vCount, u32 iO
if (CalcVelocity)
{
// Previous WVP
auto tmp = RImplementation.Target->Matrix_HUD_previous;
RCache.set_c("m_WVP_prev", RImplementation.Target->Matrix_HUD_previous);

if (RenderMode > 1 && Device.dwFrame > Parent->CurrentFrame)
Expand Down
29 changes: 29 additions & 0 deletions src/Layers/xrRender/blenders/blender_lut.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include "stdafx.h"

#include "blender_lut.h"

CBlender_lut::CBlender_lut() { description.CLS = 0; }

LPCSTR CBlender_lut::getComment()
{
return "INTERNAL: LUT";
}

void CBlender_lut::Compile(CBlender_Compile& C)
{
IBlender::Compile(C);

C.r_Pass("stub_screen_space", "pp_lut", FALSE, FALSE, FALSE);

C.r_dx11Texture("s_image", r2_RT_generic0);// r2_RT_generic0
C.r_dx11Texture("debug_image", r2_RT_ssfx_hud);// r2_RT_generic0
C.r_dx11Texture("debug_noise", "fx\\blue_noise");// r2_RT_generic0

C.r_dx11Texture("s_lut_atlas", "shaders\\lut_atlas");

C.r_dx11Sampler("smp_base");
C.r_dx11Sampler("smp_nofilter");
C.r_dx11Sampler("smp_rtlinear");
C.r_dx11Sampler("smp_linear");
C.r_End();
}
11 changes: 11 additions & 0 deletions src/Layers/xrRender/blenders/blender_lut.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

class CBlender_lut : public IBlender
{
public:
CBlender_lut();
~CBlender_lut() override = default;

LPCSTR getComment() override;
void Compile(CBlender_Compile& C) override;
};
41 changes: 22 additions & 19 deletions src/Layers/xrRender/r__dsgraph_render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,19 +243,20 @@ void __fastcall water_node_ssr(u32 context_id, T& item)

dxRender_Visual* V = item.second.pVisual;
VERIFY(V && V->shader._get());
dsgraph.cmd_list.set_Element(item.second.se);

dsgraph.cmd_list.set_Shader(RImplementation.Target->s_ssfx_water_ssr);

dsgraph.cmd_list.set_xform_world(item.second.Matrix);
RImplementation.apply_object(dsgraph.cmd_list, item.second.pObject);
dsgraph.cmd_list.apply_lmaterial();
hud_transform_helper::apply_custom_state(dsgraph.cmd_list);

dsgraph.cmd_list.set_c("cam_pos", RImplementation.Target->Position_previous.x, RImplementation.Target->Position_previous.y, RImplementation.Target->Position_previous.z, 0.0f);

// Previous matrix data
dsgraph.cmd_list.set_c("m_previous", item.second.PrevMatrix);
item.second.PrevMatrix.set(dsgraph.cmd_list.xforms.m_wvp);

V->Render(dsgraph.cmd_list, calcLOD(item.first, V->vis.sphere.R), dsgraph.o.phase == CRender::PHASE_SMAP);
V->Render(dsgraph.cmd_list, calcLOD(item.first, V->vis.sphere.R), false);
#endif
}

Expand All @@ -267,24 +268,22 @@ void __fastcall water_node(u32 context_id, T& item)

dxRender_Visual* V = item.second.pVisual;
VERIFY(V && V->shader._get());
dsgraph.cmd_list.set_Element(item.second.se);

if (RImplementation.o.ssfx_water)
{
dsgraph.cmd_list.set_Shader(RImplementation.Target->s_ssfx_water);
}

dsgraph.cmd_list.set_xform_world(item.second.Matrix);
RImplementation.apply_object(dsgraph.cmd_list, item.second.pObject);
dsgraph.cmd_list.apply_lmaterial();
hud_transform_helper::apply_custom_state(dsgraph.cmd_list);

dsgraph.cmd_list.set_c("cam_pos", RImplementation.Target->Position_previous.x, RImplementation.Target->Position_previous.y, RImplementation.Target->Position_previous.z, 0.0f);

// Previous matrix data
dsgraph.cmd_list.set_c("m_previous", item.second.PrevMatrix);
item.second.PrevMatrix.set(dsgraph.cmd_list.xforms.m_wvp);

// Wind settings
float WindDir = g_pGamePersistent->Environment().CurrentEnv.wind_direction;
float WindVel = g_pGamePersistent->Environment().CurrentEnv.wind_velocity;
dsgraph.cmd_list.set_c("wind_setup", WindDir, WindVel, 0.f, 0.f);

V->Render(dsgraph.cmd_list, calcLOD(item.first, V->vis.sphere.R), dsgraph.o.phase == CRender::PHASE_SMAP);
V->Render(dsgraph.cmd_list, calcLOD(item.first, V->vis.sphere.R), false);
#endif
}

Expand Down Expand Up @@ -326,22 +325,27 @@ void R_dsgraph_structure::render_hud(bool NoPS)
ZoneScoped;
PIX_EVENT_CTX(cmd_list, dsgraph_render_hud);

if (mapHUD.empty())
{
#if RENDER == R_R1
if (g_pGameLevel->pHUD && g_pGameLevel->pHUD->RenderActiveItemUIQuery())
render_hud_ui(); // hud ui
#endif
return;
}

if (!NoPS)
{
hud_transform_helper helper{ cmd_list };
sort_front_to_back_render_and_clean(context_id, mapHUD);
}
else
{
hud_transform_helper helper{ cmd_list };
HUDMask.traverse_left_right(context_id, hud_node);
HUDMask.clear();
}

if (!mapHUD.empty())
{
hud_transform_helper helper{ cmd_list };
sort_front_to_back_render_and_clean(context_id, mapHUD);
}

#if RENDER == R_R1
if (g_pGameLevel->pHUD && g_pGameLevel->pHUD->RenderActiveItemUIQuery())
render_hud_ui(); // hud ui
Expand Down Expand Up @@ -512,7 +516,6 @@ void R_dsgraph_structure::render_R1_box(IRender_Sector::sector_id_t sector_id, F
void R_dsgraph_structure::r_dsgraph_render_water_ssr()
{
mapWater.traverse_left_right(context_id, water_node_ssr);
mapWater.clear();
}

void R_dsgraph_structure::r_dsgraph_render_water()
Expand Down
2 changes: 0 additions & 2 deletions src/Layers/xrRender/r__dsgraph_render_lods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,4 @@ void R_dsgraph_structure::render_lods(bool _setup_zb, bool _clear)

if (_clear)
mapLOD.clear();

mapWater.clear();
}
55 changes: 55 additions & 0 deletions src/Layers/xrRender/rendertarget_phase_lut.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include "stdafx.h"

void CRenderTarget::phase_lut()
{
PIX_EVENT(phase_LUT);

//Constants
u32 Offset = 0;
u32 C = color_rgba(0, 0, 0, 255);

float d_Z = EPS_S;
float d_W = 1.0f;
float w = float(Device.dwWidth);
float h = float(Device.dwHeight);

Fvector2 p0, p1;
#if defined(USE_DX10) || defined(USE_DX11)
p0.set(0.0f, 0.0f);
p1.set(1.0f, 1.0f);
#else
p0.set(0.5f / w, 0.5f / h);
p1.set((w + 0.5f) / w, (h + 0.5f) / h);
#endif

//////////////////////////////////////////////////////////////////////////
//Set MSAA/NonMSAA rendertarget
#if defined(USE_DX10) || defined(USE_DX11)
ref_rt& dest_rt = RImplementation.o.msaa ? rt_Generic : rt_Color;
u_setrt(RCache, dest_rt, 0, 0, NULL);
#else
u_setrt(rt_Generic_0, nullptr, nullptr, nullptr);
#endif

RCache.set_CullMode(CULL_NONE);
RCache.set_Stencil(FALSE);

//Fill vertex buffer
FVF::TL* pv = (FVF::TL*)RImplementation.Vertex.Lock(4, g_combine->vb_stride, Offset);
pv->set(0, float(h), d_Z, d_W, C, p0.x, p1.y); pv++;
pv->set(0, 0, d_Z, d_W, C, p0.x, p0.y); pv++;
pv->set(float(w), float(h), d_Z, d_W, C, p1.x, p1.y); pv++;
pv->set(float(w), 0, d_Z, d_W, C, p1.x, p0.y); pv++;
RImplementation.Vertex.Unlock(4, g_combine->vb_stride);

//Set pass
RCache.set_Element(s_lut->E[0]);

//Set geometry
RCache.set_Geometry(g_combine);
RCache.Render(D3DPT_TRIANGLELIST, Offset, 0, 4, 0, 2);

#if defined(USE_DX10) || defined(USE_DX11)
HW.get_context(CHW::IMM_CTX_ID)->CopyResource(rt_Generic_0->pTexture->surface_get(), dest_rt->pTexture->surface_get());
#endif
};
8 changes: 5 additions & 3 deletions src/Layers/xrRenderPC_R4/r4_rendertarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ class CRenderTarget : public IRender_Target
IBlender* b_accum_volumetric_msaa[8]{};

// [SSS Stuff]
IBlender* b_ssfx_ssr;
IBlender* b_ssfx_volumetric_blur;
IBlender* b_ssfx_ao;
IBlender* b_ssfx_ssr{};
IBlender* b_ssfx_volumetric_blur{};
IBlender* b_ssfx_ao{};

#ifdef DEBUG
struct dbg_line_t
Expand Down Expand Up @@ -158,6 +158,7 @@ class CRenderTarget : public IRender_Target
ref_shader s_gasmask_drops;
ref_shader s_gasmask_dudv;
ref_shader s_nightvision;
ref_shader s_lut;

// Screen Space Shaders Stuff
ref_shader s_ssfx_ssr;
Expand Down Expand Up @@ -338,6 +339,7 @@ class CRenderTarget : public IRender_Target
void phase_ssfx_ao(); // AO
void phase_ssfx_il(); // IL
void set_viewport_size(ID3DDeviceContext* dev, float w, float h);
void phase_lut();
#endif

// Generates min/max sm
Expand Down
13 changes: 9 additions & 4 deletions src/Layers/xrRenderPC_R4/r4_rendertarget_phase_combine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ void CRenderTarget::phase_combine()
if (!Device.m_SecondViewport.IsSVPFrame())
{
// Clear RT
RCache.ClearRT(rt_ssfx_temp->pRT, {});
RCache.ClearRT(rt_ssfx_temp2->pRT, {});
Fcolor ColorRGBA = { 0.0f, 0.0f, 0.0f, 1.0f };
RCache.ClearRT(rt_ssfx_temp->pRT, ColorRGBA);
RCache.ClearRT(rt_ssfx_temp2->pRT, ColorRGBA);

if (RImplementation.o.ssfx_ao && ps_ssfx_ao.y > 0)
{
Expand Down Expand Up @@ -289,8 +290,9 @@ void CRenderTarget::phase_combine()
// [SSFX] - Water SSR rendering
if (RImplementation.o.ssfx_water && !Device.m_SecondViewport.IsSVPFrame())
{
RCache.ClearRT(rt_ssfx_temp->pRT, {});
RCache.ClearRT(rt_ssfx_temp2->pRT, {});
Fcolor ColorRGBA = { 0.0f, 0.0f, 0.0f, 1.0f };
RCache.ClearRT(rt_ssfx_temp->pRT, ColorRGBA);
RCache.ClearRT(rt_ssfx_temp2->pRT, ColorRGBA);

if (!RImplementation.o.msaa)
u_setrt(RCache, rt_ssfx_temp, 0, 0, 0);
Expand Down Expand Up @@ -398,6 +400,9 @@ void CRenderTarget::phase_combine()
if (ps_r2_ls_flags.test(R2FLAG_DOF))
phase_dof();

// yohji: commented out for now, doesn't work correctly yet.
//phase_lut();

//(Anomaly) Compute night vision effect
if (ps_r2_nightvision > 0)
phase_nightvision();
Expand Down
34 changes: 34 additions & 0 deletions src/Layers/xrRenderPC_R4/r4_shaders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
#include "Layers/xrRender/ShaderResourceTraits.h"
#include "xrCore/FileCRC32.h"

extern ENGINE_API int ps_ssfx_ssr_quality;
extern ENGINE_API Fvector3 ps_ssfx_water_quality;
extern ENGINE_API int ps_ssfx_il_quality;
extern ENGINE_API int ps_ssfx_ao_quality;

void CRender::addShaderOption(const char* name, const char* value)
{
D3D_SHADER_MACRO macro = {name, value};
Expand Down Expand Up @@ -226,6 +231,13 @@ HRESULT CRender::shader_compile(pcstr name, IReader* fs, pcstr pFunctionName,
string32 c_sun_quality;
char c_msaa_samples[2];
char c_msaa_current_sample[2];

// SSS preprocessor stuff
char c_ssfx_il[32];
char c_ssfx_ao[32];
char c_ssfx_water[32];
char c_ssfx_water_parallax[32];
char c_ssr_quality[32];
char c_rain_quality[32];
char c_inter_grass[32];

Expand Down Expand Up @@ -437,6 +449,28 @@ HRESULT CRender::shader_compile(pcstr name, IReader* fs, pcstr pFunctionName,
else
sh_name.append(static_cast<u32>(0));

xr_sprintf(c_ssr_quality, "%d", u8(_min(_max(ps_ssfx_ssr_quality, 0), 5)));
options.add("SSFX_SSR_QUALITY", c_ssr_quality);
sh_name.append(c_ssr_quality);

xr_sprintf(c_ssfx_water, "%d", u8(_min(_max(ps_ssfx_water_quality.x, 0.0f), 4.0f)));
options.add("SSFX_WATER_QUALITY", c_ssfx_water);
sh_name.append(c_ssfx_water);


xr_sprintf(c_ssfx_water_parallax, "%d", u8(_min(_max(ps_ssfx_water_quality.y, 0.0f), 3.0f)));
options.add("SSFX_WATER_PARALLAX", c_ssfx_water_parallax);
sh_name.append(c_ssfx_water_parallax);


xr_sprintf(c_ssfx_il, "%d", u8(_min(_max(ps_ssfx_il_quality, 0), 64)));
options.add("SSFX_IL_QUALITY", c_ssfx_il);
sh_name.append(c_ssfx_il);

xr_sprintf(c_ssfx_ao, "%d", u8(_min(_max(ps_ssfx_ao_quality, 2), 8)));
options.add("SSFX_AO_QUALITY", c_ssfx_ao);
sh_name.append(c_ssfx_ao);

appendShaderOption(1, "SSFX_MODEXE", "1");

// Be carefull!!!!! this should be at the end to correctly generate
Expand Down
3 changes: 3 additions & 0 deletions src/Layers/xrRenderPC_R4/xrRender_R4.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
<ClInclude Include="..\xrRender\blenders\blender_dof.h" />
<ClInclude Include="..\xrRender\blenders\blender_gasmask_drops.h" />
<ClInclude Include="..\xrRender\blenders\blender_gasmask_dudv.h" />
<ClInclude Include="..\xrRender\blenders\blender_lut.h" />
<ClInclude Include="..\xrRender\blenders\blender_nightvision.h" />
<ClInclude Include="..\xrRender\blenders\dx11RainBlender.h" />
<ClInclude Include="..\xrRenderDX11\dx11ConstantBuffer.h" />
Expand Down Expand Up @@ -246,6 +247,7 @@
<ClCompile Include="..\xrRender\blenders\blender_dof.cpp" />
<ClCompile Include="..\xrRender\blenders\blender_gasmask_drops.cpp" />
<ClCompile Include="..\xrRender\blenders\blender_gasmask_dudv.cpp" />
<ClCompile Include="..\xrRender\blenders\blender_lut.cpp" />
<ClCompile Include="..\xrRender\blenders\Blender_Model_EbB_deferred.cpp" />
<ClCompile Include="..\xrRender\blenders\blender_nightvision.cpp" />
<ClCompile Include="..\xrRender\blenders\Blender_Particle_deferred.cpp" />
Expand Down Expand Up @@ -335,6 +337,7 @@
<ClCompile Include="..\xrRender\rendertarget_phase_dof.cpp" />
<ClCompile Include="..\xrRender\rendertarget_phase_gasmask_drops.cpp" />
<ClCompile Include="..\xrRender\rendertarget_phase_gasmask_dudv.cpp" />
<ClCompile Include="..\xrRender\rendertarget_phase_lut.cpp" />
<ClCompile Include="..\xrRender\rendertarget_phase_nightvision.cpp" />
<ClCompile Include="..\xrRender\ResourceManager.cpp" />
<ClCompile Include="..\xrRender\ResourceManager_Loader.cpp" />
Expand Down
9 changes: 9 additions & 0 deletions src/Layers/xrRenderPC_R4/xrRender_R4.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,9 @@
<ClInclude Include="..\..\utils\xrLC_Light\R_light.h">
<Filter>Lights</Filter>
</ClInclude>
<ClInclude Include="..\xrRender\blenders\blender_lut.h">
<Filter>Shading templates</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="stdafx.cpp">
Expand Down Expand Up @@ -1376,6 +1379,12 @@
<ClCompile Include="..\xrRender\rendertarget_phase_gasmask_dudv.cpp">
<Filter>Core_Target</Filter>
</ClCompile>
<ClCompile Include="..\xrRender\blenders\blender_lut.cpp">
<Filter>Shading templates</Filter>
</ClCompile>
<ClCompile Include="..\xrRender\rendertarget_phase_lut.cpp">
<Filter>Core_Target</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
Expand Down
6 changes: 0 additions & 6 deletions src/Layers/xrRender_R2/r2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -689,12 +689,6 @@ void CRender::OnFrame()
ZoneScoped;

Models->DeleteQueue();

if (g_pGamePersistent->MainMenuActiveOrLevelNotExist())
return;

if (Details)
g_pGamePersistent->GrassBendersUpdateAnimations();
}

#ifdef USE_OGL
Expand Down
Loading

0 comments on commit 239e169

Please sign in to comment.