Skip to content

Commit

Permalink
Add new blenders to support Indirect Lighting, and later to support B…
Browse files Browse the repository at this point in the history
…eef's NVG shaders
  • Loading branch information
yohjimane committed Jul 23, 2023
1 parent 06c3f2d commit 187827e
Show file tree
Hide file tree
Showing 18 changed files with 627 additions and 5 deletions.
16 changes: 16 additions & 0 deletions res/gamedata/shaders/r3/stub_screen_space.vs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include "common.h"

//////////////////////////////////////////////////////////////////////////////////////////
// Vertex
p_screen main(v2p_screen I)
{
p_screen O;
// Transform to screen space (in d3d9 it was done automatically)
O.hpos.x = (I.HPos.x * screen_res.z * 2 - 1);
O.hpos.y = -(I.HPos.y * screen_res.w * 2 - 1);
O.hpos.zw = I.HPos.zw;

O.tc0 = I.tc0;

return O;
}
75 changes: 71 additions & 4 deletions src/Layers/xrRender/blenders/Blender_Blur.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
* Consider removing.
*/

#if RENDER != R_R1
#error "The blender can't be used in this renderer generation"
#endif

CBlender_Blur::CBlender_Blur()
{
description.CLS = B_BLUR;
Expand All @@ -22,6 +18,7 @@ LPCSTR CBlender_Blur::getComment()
return "INTERNAL: blur";
}

#if RENDER != R_R4
void CBlender_Blur::Compile(CBlender_Compile& C)
{
IBlender::Compile(C);
Expand Down Expand Up @@ -54,3 +51,73 @@ void CBlender_Blur::Compile(CBlender_Compile& C)
}
C.PassEnd();
}
#else
void CBlender_Blur::Compile(CBlender_Compile& C)
{
IBlender::Compile(C);

switch (C.iElement)
{
case 0: //Fullres Horizontal
C.r_Pass("stub_screen_space", "pp_blur", FALSE, FALSE, FALSE);
C.r_dx11Texture("s_image", r2_RT_generic0);
C.r_dx11Texture("s_position", r2_RT_P);
C.r_dx11Texture("s_lut_atlas", "shaders\\lut_atlas");

C.r_dx11Sampler("smp_nofilter");
C.r_dx11Sampler("smp_rtlinear");
C.r_End();
break;
case 1: //Fullres Vertical
C.r_Pass("stub_screen_space", "pp_blur", FALSE, FALSE, FALSE);
C.r_dx11Texture("s_image", r2_RT_blur_h_2);
C.r_dx11Texture("s_position", r2_RT_P);
C.r_dx11Texture("s_lut_atlas", "shaders\\lut_atlas");

C.r_dx11Sampler("smp_nofilter");
C.r_dx11Sampler("smp_rtlinear");
C.r_End();
break;
case 2: //Halfres Horizontal
C.r_Pass("stub_screen_space", "pp_blur", FALSE, FALSE, FALSE);
C.r_dx11Texture("s_image", r2_RT_generic0);
C.r_dx11Texture("s_position", r2_RT_P);
C.r_dx11Texture("s_lut_atlas", "shaders\\lut_atlas");

C.r_dx11Sampler("smp_nofilter");
C.r_dx11Sampler("smp_rtlinear");
C.r_End();
break;
case 3: //Halfres Vertical
C.r_Pass("stub_screen_space", "pp_blur", FALSE, FALSE, FALSE);
C.r_dx11Texture("s_image", r2_RT_blur_h_4);
C.r_dx11Texture("s_position", r2_RT_P);
C.r_dx11Texture("s_lut_atlas", "shaders\\lut_atlas");

C.r_dx11Sampler("smp_nofilter");
C.r_dx11Sampler("smp_rtlinear");
C.r_End();
break;
case 4: //Quarterres Horizontal
C.r_Pass("stub_screen_space", "pp_blur", FALSE, FALSE, FALSE);
C.r_dx11Texture("s_image", r2_RT_generic0);
C.r_dx11Texture("s_position", r2_RT_P);
C.r_dx11Texture("s_lut_atlas", "shaders\\lut_atlas");

C.r_dx11Sampler("smp_nofilter");
C.r_dx11Sampler("smp_rtlinear");
C.r_End();
break;
case 5: //Quarterres Vertical
C.r_Pass("stub_screen_space", "pp_blur", FALSE, FALSE, FALSE);
C.r_dx11Texture("s_image", r2_RT_blur_h_8);
C.r_dx11Texture("s_position", r2_RT_P);
C.r_dx11Texture("s_lut_atlas", "shaders\\lut_atlas");

C.r_dx11Sampler("smp_nofilter");
C.r_dx11Sampler("smp_rtlinear");
C.r_End();
break;
}
}
#endif
24 changes: 24 additions & 0 deletions src/Layers/xrRender/blenders/blender_combine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ void CBlender_combine::Compile(CBlender_Compile& C)
C.r_dx11Texture("s_image", r2_RT_generic0);
C.r_dx11Texture("s_bloom", r2_RT_bloom1);
C.r_dx11Texture("s_distort", r2_RT_generic1);
C.r_dx11Texture("s_blur_2", r2_RT_blur_2);
C.r_dx11Texture("s_blur_4", r2_RT_blur_4);
C.r_dx11Texture("s_blur_8", r2_RT_blur_8);

C.r_dx11Sampler("smp_nofilter");
C.r_dx11Sampler("smp_rtlinear");
Expand All @@ -211,6 +214,9 @@ void CBlender_combine::Compile(CBlender_Compile& C)
C.r_dx11Texture("s_image", r2_RT_generic0);
C.r_dx11Texture("s_bloom", r2_RT_bloom1);
C.r_dx11Texture("s_distort", r2_RT_generic1);
C.r_dx11Texture("s_blur_2", r2_RT_blur_2);
C.r_dx11Texture("s_blur_4", r2_RT_blur_4);
C.r_dx11Texture("s_blur_8", r2_RT_blur_8);

C.r_dx11Sampler("smp_nofilter");
C.r_dx11Sampler("smp_rtlinear");
Expand All @@ -229,6 +235,9 @@ void CBlender_combine::Compile(CBlender_Compile& C)
C.r_dx11Texture("s_image", r2_RT_generic0);
C.r_dx11Texture("s_bloom", r2_RT_bloom1);
C.r_dx11Texture("s_distort", r2_RT_generic1);
C.r_dx11Texture("s_blur_2", r2_RT_blur_2);
C.r_dx11Texture("s_blur_4", r2_RT_blur_4);
C.r_dx11Texture("s_blur_8", r2_RT_blur_8);

C.r_dx11Sampler("smp_nofilter");
C.r_dx11Sampler("smp_rtlinear");
Expand All @@ -248,6 +257,9 @@ void CBlender_combine::Compile(CBlender_Compile& C)
C.r_dx11Texture("s_image", r2_RT_generic0);
C.r_dx11Texture("s_bloom", r2_RT_bloom1);
C.r_dx11Texture("s_distort", r2_RT_generic1);
C.r_dx11Texture("s_blur_2", r2_RT_blur_2);
C.r_dx11Texture("s_blur_4", r2_RT_blur_4);
C.r_dx11Texture("s_blur_8", r2_RT_blur_8);

C.r_dx11Sampler("smp_nofilter");
C.r_dx11Sampler("smp_rtlinear");
Expand Down Expand Up @@ -390,6 +402,9 @@ void CBlender_combine_msaa::Compile(CBlender_Compile& C)
C.r_dx11Texture("s_image", r2_RT_generic0);
C.r_dx11Texture("s_bloom", r2_RT_bloom1);
C.r_dx11Texture("s_distort", r2_RT_generic1_r);
C.r_dx11Texture("s_blur_2", r2_RT_blur_2);
C.r_dx11Texture("s_blur_4", r2_RT_blur_4);
C.r_dx11Texture("s_blur_8", r2_RT_blur_8);

C.r_dx11Sampler("smp_nofilter");
C.r_dx11Sampler("smp_rtlinear");
Expand All @@ -409,6 +424,9 @@ void CBlender_combine_msaa::Compile(CBlender_Compile& C)
C.r_dx11Texture("s_image", r2_RT_generic0);
C.r_dx11Texture("s_bloom", r2_RT_bloom1);
C.r_dx11Texture("s_distort", r2_RT_generic1_r);
C.r_dx11Texture("s_blur_2", r2_RT_blur_2);
C.r_dx11Texture("s_blur_4", r2_RT_blur_4);
C.r_dx11Texture("s_blur_8", r2_RT_blur_8);

C.r_dx11Sampler("smp_nofilter");
C.r_dx11Sampler("smp_rtlinear");
Expand All @@ -427,6 +445,9 @@ void CBlender_combine_msaa::Compile(CBlender_Compile& C)
C.r_dx11Texture("s_image", r2_RT_generic0);
C.r_dx11Texture("s_bloom", r2_RT_bloom1);
C.r_dx11Texture("s_distort", r2_RT_generic1_r);
C.r_dx11Texture("s_blur_2", r2_RT_blur_2);
C.r_dx11Texture("s_blur_4", r2_RT_blur_4);
C.r_dx11Texture("s_blur_8", r2_RT_blur_8);

C.r_dx11Sampler("smp_nofilter");
C.r_dx11Sampler("smp_rtlinear");
Expand All @@ -446,6 +467,9 @@ void CBlender_combine_msaa::Compile(CBlender_Compile& C)
C.r_dx11Texture("s_image", r2_RT_generic0);
C.r_dx11Texture("s_bloom", r2_RT_bloom1);
C.r_dx11Texture("s_distort", r2_RT_generic1_r);
C.r_dx11Texture("s_blur_2", r2_RT_blur_2);
C.r_dx11Texture("s_blur_4", r2_RT_blur_4);
C.r_dx11Texture("s_blur_8", r2_RT_blur_8);

C.r_dx11Sampler("smp_nofilter");
C.r_dx11Sampler("smp_rtlinear");
Expand Down
43 changes: 43 additions & 0 deletions src/Layers/xrRender/blenders/blender_dof.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include "stdafx.h"

#include "blender_dof.h"

CBlender_dof::CBlender_dof()
{
description.CLS = B_BLUR;
}

LPCSTR CBlender_dof::getComment()
{
return "INTERNAL: dof";
}

void CBlender_dof::Compile(CBlender_Compile& C)
{
IBlender::Compile(C);
#if RENDER == R_R4
switch (C.iElement)
{
case 0:
C.r_Pass("stub_screen_space", "depth_of_field", FALSE, FALSE, FALSE);
C.r_dx11Texture("s_position", r2_RT_P);
C.r_dx11Texture("s_image", r2_RT_generic0);
C.r_dx11Texture("s_blur_2", r2_RT_blur_2);

C.r_dx11Sampler("smp_base");
C.r_dx11Sampler("smp_nofilter");
C.r_dx11Sampler("smp_rtlinear");
C.r_End();
break;
case 1:
C.r_Pass("stub_screen_space", "post_processing", FALSE, FALSE, FALSE);
C.r_dx11Texture("samplero_pepero", r2_RT_dof);

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

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

LPCSTR getComment() override;
void Compile(CBlender_Compile& C) override;
};
75 changes: 75 additions & 0 deletions src/Layers/xrRender/blenders/blender_nightvision.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#include "stdafx.h"

#include "blender_nightvision.h"


CBlender_nightvision::CBlender_nightvision()
{
description.CLS = B_BLUR;
}

LPCSTR CBlender_nightvision::getComment()
{
return "INTERNAL: beef's nightvision";
}

void CBlender_nightvision::Compile(CBlender_Compile& C)
{
IBlender::Compile(C);
#if RENDER == R_R4
switch (C.iElement)
{
case 0: //Dummy shader - because IDK what gonna happen when r2_nightvision will be 0
C.r_Pass("stub_screen_space", "copy_nomsaa", FALSE, FALSE, FALSE);
C.r_dx11Texture("s_generic", r2_RT_generic0);

C.r_dx11Sampler("smp_base");
C.r_dx11Sampler("smp_nofilter");
C.r_dx11Sampler("smp_rtlinear");
C.r_End();
break;
case 1:
C.r_Pass("stub_screen_space", "nightvision_gen_1", FALSE, FALSE, FALSE);
C.r_dx11Texture("s_position", r2_RT_P);
C.r_dx11Texture("s_image", r2_RT_generic0);
//C.r_dx11Texture("s_bloom_new", r2_RT_pp_bloom);
C.r_dx11Texture("s_blur_2", r2_RT_blur_2);
C.r_dx11Texture("s_blur_4", r2_RT_blur_4);
C.r_dx11Texture("s_blur_8", r2_RT_blur_8);

C.r_dx11Sampler("smp_base");
C.r_dx11Sampler("smp_nofilter");
C.r_dx11Sampler("smp_rtlinear");
C.r_End();
break;
case 2:
C.r_Pass("stub_screen_space", "nightvision_gen_2", FALSE, FALSE, FALSE);
C.r_dx11Texture("s_position", r2_RT_P);
C.r_dx11Texture("s_image", r2_RT_generic0);
//C.r_dx11Texture("s_bloom_new", r2_RT_pp_bloom);
C.r_dx11Texture("s_blur_2", r2_RT_blur_2);
C.r_dx11Texture("s_blur_4", r2_RT_blur_4);
C.r_dx11Texture("s_blur_8", r2_RT_blur_8);

C.r_dx11Sampler("smp_base");
C.r_dx11Sampler("smp_nofilter");
C.r_dx11Sampler("smp_rtlinear");
C.r_End();
break;
case 3:
C.r_Pass("stub_screen_space", "nightvision_gen_3", FALSE, FALSE, FALSE);
C.r_dx11Texture("s_position", r2_RT_P);
C.r_dx11Texture("s_image", r2_RT_generic0);
//C.r_dx11Texture("s_bloom_new", r2_RT_pp_bloom);
C.r_dx11Texture("s_blur_2", r2_RT_blur_2);
C.r_dx11Texture("s_blur_4", r2_RT_blur_4);
C.r_dx11Texture("s_blur_8", r2_RT_blur_8);

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

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

LPCSTR getComment() override;
void Compile(CBlender_Compile& C) override;
};
3 changes: 3 additions & 0 deletions src/Layers/xrRender/xrRender_console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ extern ENGINE_API float ps_r2_img_exposure; // r2-only
extern ENGINE_API float ps_r2_img_gamma; // r2-only
extern ENGINE_API float ps_r2_img_saturation; // r2-only
extern ENGINE_API Fvector ps_r2_img_cg; // r2-only
int ps_r2_nightvision = 0;

// Ascii1457's Screen Space Shaders
extern ENGINE_API Fvector3 ps_ssfx_shadow_cascades;
Expand Down Expand Up @@ -1032,6 +1033,8 @@ void xrRender_initconsole()
CMD4(CCC_Integer, "r2_mt_render", &ps_r2_mt_render, 0, 1);
#endif

CMD4(CCC_Integer, "r__nightvision", &ps_r2_nightvision, 0, 3); //For beef's nightvision shader or other stuff

// Screen Space Shaders
Fvector4 tw2_min = { -100.f, -100.f, -100.f, -100.f };
Fvector4 tw2_max = { 100.f, 100.f, 100.f, 100.f };
Expand Down
2 changes: 2 additions & 0 deletions src/Layers/xrRender/xrRender_console.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ extern ECORE_API float ps_r2_slight_fade; // 1.f
extern ECORE_API int ps_r2_wait_sleep;
extern ECORE_API int ps_r2_wait_timeout;

extern ECORE_API int ps_r2_nightvision;

// x - min (0), y - focus (1.4), z - max (100)
extern ECORE_API Fvector3 ps_r2_dof;
extern ECORE_API float ps_r2_dof_sky; // distance to sky
Expand Down
Loading

0 comments on commit 187827e

Please sign in to comment.