Skip to content

Commit

Permalink
Engine, shaders: add lut phase
Browse files Browse the repository at this point in the history
  • Loading branch information
yohjimane committed Nov 11, 2024
1 parent 106d56d commit 14cd244
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 0 deletions.
Binary file modified res/gamedata/shaders/r5/combine_2_naa.ps
Binary file not shown.
Binary file added res/gamedata/shaders/r5/pp_lut.ps
Binary file not shown.
25 changes: 25 additions & 0 deletions src/Layers/xrRender/blenders/blender_lut.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#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);
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;
};
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
};
2 changes: 2 additions & 0 deletions src/Layers/xrRenderPC_R4/r4_rendertarget_phase_combine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,8 @@ void CRenderTarget::phase_combine()
if (ps_r2_ls_flags.test(R2FLAG_DOF))
phase_dof();

phase_lut();

//(Anomaly) Compute night vision effect
if (ps_r2_nightvision > 0)
phase_nightvision();
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

0 comments on commit 14cd244

Please sign in to comment.