Skip to content

Commit b337b1a

Browse files
committed
Added FXAA for xrRender_R2(DX9)
Renamed console command r3_fxaa to r2_fxaa Thanks @qweasdd136963 for shaders fix
1 parent 1bd9349 commit b337b1a

16 files changed

+136
-6
lines changed

res/gamedata/shaders/r2/fxaa.ps

42 KB
Binary file not shown.
1.39 KB
Binary file not shown.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include "common.h"
2+
3+
uniform float4 screen_res; // Screen resolution (x-Width,y-Height, zw - 1/resolution)
4+
5+
struct v
6+
{
7+
float3 P : POSITION;
8+
float2 tc0 : TEXCOORD0;
9+
};
10+
11+
struct v2p
12+
{
13+
float2 tc0 : TEXCOORD0;
14+
float4 HPos : POSITION;
15+
};
16+
17+
//////////////////////////////////////////////////////////////////////////////////////////
18+
// Vertex
19+
v2p main ( v I )
20+
{
21+
v2p O;
22+
O.HPos = float4 (I.P.x * screen_res.z * 2 - 1, (I.P.y * screen_res.w * 2 - 1)* -1, 0, 1);
23+
O.tc0 = I.tc0;
24+
25+
return O;
26+
}

src/Layers/xrRender/xrRender_console.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ xr_token qmsaa__atest_token[] = {
3838
u32 ps_r3_minmax_sm = 3; // = 0;
3939
xr_token qminmax_sm_token[] = {{"off", 0}, {"on", 1}, {"auto", 2}, {"autodetect", 3}, {nullptr, 0}};
4040

41-
int ps_r3_fxaa = 0;
41+
int ps_r2_fxaa = 0;
4242

4343
// “Off”
4444
// “DX10.0 style [Standard]”
@@ -877,7 +877,7 @@ void xrRender_initconsole()
877877
#ifdef DETAIL_RADIUS
878878
CMD4(CCC_detail_radius, "r__detail_radius", &ps_r__detail_radius, 49, 300);
879879
#endif
880-
CMD4(CCC_Integer, "r3_fxaa", &ps_r3_fxaa, 0, 1);
880+
CMD4(CCC_Integer, "r2_fxaa", &ps_r2_fxaa, 0, 1);
881881

882882
// Allow real-time fog config reload
883883
#if (RENDER == R_R3) || (RENDER == R_R4)

src/Layers/xrRender/xrRender_console.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ extern ECORE_API xr_token qmsaa__atest_token[];
2424
extern ECORE_API u32 ps_r3_minmax_sm; // = 0;
2525
extern ECORE_API xr_token qminmax_sm_token[];
2626

27-
extern ECORE_API int ps_r3_fxaa;
27+
extern ECORE_API int ps_r2_fxaa;
2828

2929
extern ENGINE_API int ps_r__Supersample;
3030
extern ECORE_API int ps_r__LightSleepFrames;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include "stdafx.h"
2+
#pragma hdrstop
3+
4+
#include "blender_fxaa.h"
5+
6+
CBlender_FXAA::CBlender_FXAA() { description.CLS = 0; }
7+
CBlender_FXAA::~CBlender_FXAA() { }
8+
9+
void CBlender_FXAA::Compile(CBlender_Compile& C)
10+
{
11+
IBlender::Compile(C);
12+
13+
switch (C.iElement)
14+
{
15+
case 0:
16+
C.r_Pass("fxaa_main", "fxaa_main", false, FALSE, FALSE);
17+
C.r_Sampler("s_base0", r2_RT_generic0);
18+
C.r_End();
19+
break;
20+
}
21+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#pragma once
2+
3+
class CBlender_FXAA : public IBlender
4+
{
5+
public:
6+
LPCSTR getComment() override { return "FXAA"; }
7+
BOOL canBeDetailed() override { return FALSE; }
8+
BOOL canBeLMAPped() override { return FALSE; }
9+
10+
void Compile(CBlender_Compile& C) override;
11+
12+
CBlender_FXAA();
13+
virtual ~CBlender_FXAA();
14+
};

src/Layers/xrRenderPC_R2/r2_rendertarget.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "blender_bloom_build.h"
1212
#include "blender_luminance.h"
1313
#include "blender_ssao.h"
14+
#include "blender_fxaa.h"
1415

1516
void CRenderTarget::u_setrt(const ref_rt& _1, const ref_rt& _2, const ref_rt& _3, IDirect3DSurface9* zb)
1617
{
@@ -219,6 +220,9 @@ CRenderTarget::CRenderTarget()
219220
b_luminance = new CBlender_luminance();
220221
b_combine = new CBlender_combine();
221222

223+
//FXAA
224+
b_fxaa = new CBlender_FXAA();
225+
222226
// NORMAL
223227
{
224228
u32 w = Device.dwWidth, h = Device.dwHeight;
@@ -370,6 +374,10 @@ CRenderTarget::CRenderTarget()
370374
s_ssao.create(b_ssao, "r2\\ssao");
371375
}
372376

377+
//FXAA
378+
s_fxaa.create(b_fxaa, "r3\\fxaa");
379+
g_fxaa.create(FVF::F_V, RCache.Vertex.Buffer(), RCache.QuadIB);
380+
373381
// SSAO
374382
if (RImplementation.o.ssao_blur_on)
375383
{
@@ -660,6 +668,7 @@ CRenderTarget::~CRenderTarget()
660668
xr_delete(b_luminance);
661669
xr_delete(b_bloom);
662670
xr_delete(b_ssao);
671+
xr_delete(b_fxaa); //FXAA
663672
xr_delete(b_accum_reflected);
664673
xr_delete(b_accum_spot);
665674
xr_delete(b_accum_point);

src/Layers/xrRenderPC_R2/r2_rendertarget.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ class CRenderTarget : public IRender_Target
2929
IBlender* b_accum_reflected;
3030
IBlender* b_bloom;
3131
IBlender* b_ssao;
32+
IBlender* b_fxaa;
3233
IBlender* b_luminance;
3334
IBlender* b_combine;
35+
3436
#ifdef DEBUG
3537
struct dbg_line_t
3638
{
@@ -120,6 +122,10 @@ class CRenderTarget : public IRender_Target
120122
ref_rt rt_ssao_temp;
121123
ref_rt rt_half_depth;
122124

125+
//FXAA
126+
ref_shader s_fxaa;
127+
ref_geom g_fxaa;
128+
123129
// Bloom
124130
ref_geom g_bloom_build;
125131
ref_geom g_bloom_filter;
@@ -203,6 +209,7 @@ class CRenderTarget : public IRender_Target
203209
void u_DBT_disable();
204210

205211
void phase_ssao();
212+
void phase_fxaa();
206213
void phase_downsamp();
207214
void phase_scene_prepare();
208215
void phase_scene_begin();
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include "stdafx.h"
2+
#include "r2_rendertarget.h"
3+
4+
void CRenderTarget::phase_fxaa()
5+
{
6+
u32 Offset = 0;
7+
const float _w = float(Device.dwWidth);
8+
const float _h = float(Device.dwHeight);
9+
const float du = ps_r1_pps_u, dv = ps_r1_pps_v;
10+
11+
u_setrt(rt_Generic_0, nullptr, nullptr, HW.pBaseZB);
12+
RCache.set_CullMode(CULL_NONE);
13+
RCache.set_Stencil(FALSE);
14+
15+
FVF::V* pv = (FVF::V*)RCache.Vertex.Lock(4, g_fxaa->vb_stride, Offset);
16+
pv->set(du - 0.5, dv + float(_h) - 0.5, 0, 0, 1);
17+
pv++;
18+
pv->set(du - 0.5, dv - 0.5, 0, 0, 0);
19+
pv++;
20+
pv->set(du + float(_w) - 0.5, dv + float(_h) - 0.5, 0, 1, 1);
21+
pv++;
22+
pv->set(du + float(_w) - 0.5, dv - 0.5, 0, 1, 0);
23+
pv++;
24+
RCache.Vertex.Unlock(4, g_fxaa->vb_stride);
25+
26+
27+
RCache.set_Element(s_fxaa->E[0]);
28+
RCache.set_Geometry(g_fxaa);
29+
RCache.Render(D3DPT_TRIANGLELIST, Offset, 0, 4, 0, 2);
30+
}

0 commit comments

Comments
 (0)