mirror of https://github.com/PCSX2/pcsx2.git
gsdx-ogl: support latest fxaa version
Only tested on Nvidia, please report any issue with your driver Note: requires GL4 GPU
This commit is contained in:
parent
ff39dffe23
commit
8c90e7cafc
|
@ -34,8 +34,7 @@ eval {
|
||||||
print "Disable MD5\n";
|
print "Disable MD5\n";
|
||||||
};
|
};
|
||||||
|
|
||||||
# Keep the old FXAA for now
|
my @gsdx_res = qw/convert.glsl interlace.glsl merge.glsl shadeboost.glsl tfx.glsl fxaa.fx/;
|
||||||
my @gsdx_res = qw/convert.glsl interlace.glsl merge.glsl shadeboost.glsl tfx.glsl old_fxaa.fx/;
|
|
||||||
my $gsdx_path = File::Spec->catdir(dirname(abs_path($0)), "..", "plugins", "GSdx", "res");
|
my $gsdx_path = File::Spec->catdir(dirname(abs_path($0)), "..", "plugins", "GSdx", "res");
|
||||||
my $gsdx_out = File::Spec->catdir($gsdx_path, "glsl_source.h");
|
my $gsdx_out = File::Spec->catdir($gsdx_path, "glsl_source.h");
|
||||||
glsl2h($gsdx_path, $gsdx_out, \@gsdx_res);
|
glsl2h($gsdx_path, $gsdx_out, \@gsdx_res);
|
||||||
|
|
|
@ -40,7 +40,6 @@ uint32 g_vertex_upload_byte = 0;
|
||||||
static const uint32 g_merge_cb_index = 10;
|
static const uint32 g_merge_cb_index = 10;
|
||||||
static const uint32 g_interlace_cb_index = 11;
|
static const uint32 g_interlace_cb_index = 11;
|
||||||
static const uint32 g_shadeboost_cb_index = 12;
|
static const uint32 g_shadeboost_cb_index = 12;
|
||||||
static const uint32 g_fxaa_cb_index = 13;
|
|
||||||
static const uint32 g_fx_cb_index = 14;
|
static const uint32 g_fx_cb_index = 14;
|
||||||
|
|
||||||
GSDeviceOGL::GSDeviceOGL()
|
GSDeviceOGL::GSDeviceOGL()
|
||||||
|
@ -919,13 +918,15 @@ void GSDeviceOGL::DoFXAA(GSTexture* st, GSTexture* dt)
|
||||||
// Lazy compile
|
// Lazy compile
|
||||||
if (!m_fxaa.ps) {
|
if (!m_fxaa.ps) {
|
||||||
std::string fxaa_macro = "#define FXAA_GLSL_130 1\n";
|
std::string fxaa_macro = "#define FXAA_GLSL_130 1\n";
|
||||||
if (GLLoader::found_GL_ARB_gpu_shader5) {
|
if (GLLoader::found_GL_ARB_gpu_shader5) { // GL4.0 extension
|
||||||
// This extension become core on openGL4
|
// Hardcoded in the new shader
|
||||||
|
//fxaa_macro += "#define FXAA_GATHER4_ALPHA 1\n";
|
||||||
fxaa_macro += "#extension GL_ARB_gpu_shader5 : enable\n";
|
fxaa_macro += "#extension GL_ARB_gpu_shader5 : enable\n";
|
||||||
fxaa_macro += "#define FXAA_GATHER4_ALPHA 1\n";
|
} else {
|
||||||
|
fprintf(stderr, "FXAA requires the GL_ARB_gpu_shader5 extension. Please either disable FXAA or upgrade your GPU/driver.\n");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
m_fxaa.cb = new GSUniformBufferOGL(g_fxaa_cb_index, sizeof(FXAAConstantBuffer));
|
m_fxaa.ps = m_shader->Compile("fxaa.fx", "ps_main", GL_FRAGMENT_SHADER, fxaa_fx, fxaa_macro);
|
||||||
m_fxaa.ps = m_shader->Compile("fxaa.fx", "ps_main", GL_FRAGMENT_SHADER, old_fxaa_fx, fxaa_macro);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GSVector2i s = dt->GetSize();
|
GSVector2i s = dt->GetSize();
|
||||||
|
@ -933,13 +934,6 @@ void GSDeviceOGL::DoFXAA(GSTexture* st, GSTexture* dt)
|
||||||
GSVector4 sr(0, 0, 1, 1);
|
GSVector4 sr(0, 0, 1, 1);
|
||||||
GSVector4 dr(0, 0, s.x, s.y);
|
GSVector4 dr(0, 0, s.x, s.y);
|
||||||
|
|
||||||
FXAAConstantBuffer cb;
|
|
||||||
|
|
||||||
cb.rcpFrame = GSVector4(1.0f / s.x, 1.0f / s.y, 0.0f, 0.0f);
|
|
||||||
cb.rcpFrameOpt = GSVector4::zero();
|
|
||||||
|
|
||||||
m_fxaa.cb->upload(&cb);
|
|
||||||
|
|
||||||
StretchRect(st, sr, dt, dr, m_fxaa.ps, true);
|
StretchRect(st, sr, dt, dr, m_fxaa.ps, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
#ifdef SHADER_MODEL
|
#if defined(SHADER_MODEL) || defined(FXAA_GLSL_130)
|
||||||
|
|
||||||
|
#ifndef FXAA_GLSL_130
|
||||||
|
#define FXAA_GLSL_130 0
|
||||||
|
#endif
|
||||||
|
|
||||||
#define UHQ_FXAA 1 //High Quality Fast Approximate Anti Aliasing. Adapted for GSdx from Timothy Lottes FXAA 3.11.
|
#define UHQ_FXAA 1 //High Quality Fast Approximate Anti Aliasing. Adapted for GSdx from Timothy Lottes FXAA 3.11.
|
||||||
#define FxaaSubpixMax 0.0 //[0.00 to 1.00] Amount of subpixel aliasing removal. 0.00: Edge only antialiasing (no blurring)
|
#define FxaaSubpixMax 0.0 //[0.00 to 1.00] Amount of subpixel aliasing removal. 0.00: Edge only antialiasing (no blurring)
|
||||||
|
@ -7,6 +11,29 @@
|
||||||
/*------------------------------------------------------------------------------
|
/*------------------------------------------------------------------------------
|
||||||
[GLOBALS|FUNCTIONS]
|
[GLOBALS|FUNCTIONS]
|
||||||
------------------------------------------------------------------------------*/
|
------------------------------------------------------------------------------*/
|
||||||
|
#if (FXAA_GLSL_130 == 1)
|
||||||
|
|
||||||
|
struct vertex_basic
|
||||||
|
{
|
||||||
|
vec4 p;
|
||||||
|
vec2 t;
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifdef ENABLE_BINDLESS_TEX
|
||||||
|
layout(bindless_sampler, location = 0) uniform sampler2D TextureSampler;
|
||||||
|
#else
|
||||||
|
layout(binding = 0) uniform sampler2D TextureSampler;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
in SHADER
|
||||||
|
{
|
||||||
|
vec4 p;
|
||||||
|
vec2 t;
|
||||||
|
} PSin;
|
||||||
|
|
||||||
|
layout(location = 0) out vec4 SV_Target0;
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
#if (SHADER_MODEL >= 0x400)
|
#if (SHADER_MODEL >= 0x400)
|
||||||
Texture2D Texture : register(t0);
|
Texture2D Texture : register(t0);
|
||||||
|
@ -47,60 +74,8 @@ struct PS_OUTPUT
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
float RGBLuminance(float3 color)
|
|
||||||
{
|
|
||||||
const float3 lumCoeff = float3(0.2126729, 0.7151522, 0.0721750);
|
|
||||||
return dot(color.rgb, lumCoeff);
|
|
||||||
}
|
|
||||||
|
|
||||||
#define PixelSize float2(_rcpFrame.x, _rcpFrame.y)
|
|
||||||
|
|
||||||
/*------------------------------------------------------------------------------
|
|
||||||
[GAMMA PREPASS CODE SECTION]
|
|
||||||
------------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
float3 RGBGammaToLinear(float3 color, float gamma)
|
|
||||||
{
|
|
||||||
color = saturate(color);
|
|
||||||
color.r = (color.r <= 0.0404482362771082) ?
|
|
||||||
color.r / 12.92 : pow((color.r + 0.055) / 1.055, gamma);
|
|
||||||
color.g = (color.g <= 0.0404482362771082) ?
|
|
||||||
color.g / 12.92 : pow((color.g + 0.055) / 1.055, gamma);
|
|
||||||
color.b = (color.b <= 0.0404482362771082) ?
|
|
||||||
color.b / 12.92 : pow((color.b + 0.055) / 1.055, gamma);
|
|
||||||
|
|
||||||
return color;
|
|
||||||
}
|
|
||||||
|
|
||||||
float3 LinearToRGBGamma(float3 color, float gamma)
|
|
||||||
{
|
|
||||||
color = saturate(color);
|
|
||||||
color.r = (color.r <= 0.00313066844250063) ?
|
|
||||||
color.r * 12.92 : 1.055 * pow(color.r, 1.0 / gamma) - 0.055;
|
|
||||||
color.g = (color.g <= 0.00313066844250063) ?
|
|
||||||
color.g * 12.92 : 1.055 * pow(color.g, 1.0 / gamma) - 0.055;
|
|
||||||
color.b = (color.b <= 0.00313066844250063) ?
|
|
||||||
color.b * 12.92 : 1.055 * pow(color.b, 1.0 / gamma) - 0.055;
|
|
||||||
|
|
||||||
return color;
|
|
||||||
}
|
|
||||||
|
|
||||||
float4 PreGammaPass(float4 color, float2 uv0)
|
|
||||||
{
|
|
||||||
#if (SHADER_MODEL >= 0x400)
|
|
||||||
color = Texture.Sample(TextureSampler, uv0);
|
|
||||||
#else
|
|
||||||
color = tex2D(TextureSampler, uv0);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const float GammaConst = 2.233;
|
|
||||||
color.rgb = RGBGammaToLinear(color.rgb, GammaConst);
|
|
||||||
color.rgb = LinearToRGBGamma(color.rgb, GammaConst);
|
|
||||||
color.a = RGBLuminance(color.rgb);
|
|
||||||
|
|
||||||
return color;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*------------------------------------------------------------------------------
|
/*------------------------------------------------------------------------------
|
||||||
[FXAA CODE SECTION]
|
[FXAA CODE SECTION]
|
||||||
------------------------------------------------------------------------------*/
|
------------------------------------------------------------------------------*/
|
||||||
|
@ -111,6 +86,8 @@ float4 PreGammaPass(float4 color, float2 uv0)
|
||||||
#elif (SHADER_MODEL >= 0x400)
|
#elif (SHADER_MODEL >= 0x400)
|
||||||
#define FXAA_HLSL_4 1
|
#define FXAA_HLSL_4 1
|
||||||
#define FXAA_GATHER4_ALPHA 0
|
#define FXAA_GATHER4_ALPHA 0
|
||||||
|
#elif (FXAA_GLSL_130 == 1)
|
||||||
|
#define FXAA_GATHER4_ALPHA 1
|
||||||
#else
|
#else
|
||||||
#define FXAA_HLSL_3 1
|
#define FXAA_HLSL_3 1
|
||||||
#define FXAA_GATHER4_ALPHA 0
|
#define FXAA_GATHER4_ALPHA 0
|
||||||
|
@ -138,6 +115,24 @@ struct FxaaTex { SamplerState smpl; Texture2D tex; };
|
||||||
#define FxaaSat(x) saturate(x)
|
#define FxaaSat(x) saturate(x)
|
||||||
#define FxaaTexTop(t, p) tex2Dlod(t, float4(p, 0.0, 0.0))
|
#define FxaaTexTop(t, p) tex2Dlod(t, float4(p, 0.0, 0.0))
|
||||||
#define FxaaTexOff(t, p, o, r) tex2Dlod(t, float4(p + (o * r), 0, 0))
|
#define FxaaTexOff(t, p, o, r) tex2Dlod(t, float4(p + (o * r), 0, 0))
|
||||||
|
|
||||||
|
#elif (FXAA_GLSL_130 == 1)
|
||||||
|
|
||||||
|
#define int2 ivec2
|
||||||
|
#define float2 vec2
|
||||||
|
#define float3 vec3
|
||||||
|
#define float4 vec4
|
||||||
|
#define FxaaDiscard discard
|
||||||
|
#define FxaaSat(x) clamp(x, 0.0, 1.0)
|
||||||
|
#define FxaaTex sampler2D
|
||||||
|
#define FxaaTexTop(t, p) textureLod(t, p, 0.0)
|
||||||
|
#define FxaaTexOff(t, p, o, r) textureLodOffset(t, p, 0.0, o)
|
||||||
|
#if (FXAA_GATHER4_ALPHA == 1)
|
||||||
|
// use #extension GL_ARB_gpu_shader5 : enable
|
||||||
|
#define FxaaTexAlpha4(t, p) textureGather(t, p, 3)
|
||||||
|
#define FxaaTexOffAlpha4(t, p, o) textureGatherOffset(t, p, o, 3)
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define FxaaEdgeThreshold 0.063
|
#define FxaaEdgeThreshold 0.063
|
||||||
|
@ -156,6 +151,69 @@ struct FxaaTex { SamplerState smpl; Texture2D tex; };
|
||||||
#define FXAA_QUALITY__P11 8.0
|
#define FXAA_QUALITY__P11 8.0
|
||||||
#define FXAA_QUALITY__P12 8.0
|
#define FXAA_QUALITY__P12 8.0
|
||||||
|
|
||||||
|
/*------------------------------------------------------------------------------
|
||||||
|
[GAMMA PREPASS CODE SECTION]
|
||||||
|
------------------------------------------------------------------------------*/
|
||||||
|
float RGBLuminance(float3 color)
|
||||||
|
{
|
||||||
|
const float3 lumCoeff = float3(0.2126729, 0.7151522, 0.0721750);
|
||||||
|
return dot(color.rgb, lumCoeff);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if (FXAA_GLSL_130 == 0)
|
||||||
|
#define PixelSize float2(_rcpFrame.x, _rcpFrame.y)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
float3 RGBGammaToLinear(float3 color, float gamma)
|
||||||
|
{
|
||||||
|
color = FxaaSat(color);
|
||||||
|
color.r = (color.r <= 0.0404482362771082) ?
|
||||||
|
color.r / 12.92 : pow((color.r + 0.055) / 1.055, gamma);
|
||||||
|
color.g = (color.g <= 0.0404482362771082) ?
|
||||||
|
color.g / 12.92 : pow((color.g + 0.055) / 1.055, gamma);
|
||||||
|
color.b = (color.b <= 0.0404482362771082) ?
|
||||||
|
color.b / 12.92 : pow((color.b + 0.055) / 1.055, gamma);
|
||||||
|
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
|
float3 LinearToRGBGamma(float3 color, float gamma)
|
||||||
|
{
|
||||||
|
color = FxaaSat(color);
|
||||||
|
color.r = (color.r <= 0.00313066844250063) ?
|
||||||
|
color.r * 12.92 : 1.055 * pow(color.r, 1.0 / gamma) - 0.055;
|
||||||
|
color.g = (color.g <= 0.00313066844250063) ?
|
||||||
|
color.g * 12.92 : 1.055 * pow(color.g, 1.0 / gamma) - 0.055;
|
||||||
|
color.b = (color.b <= 0.00313066844250063) ?
|
||||||
|
color.b * 12.92 : 1.055 * pow(color.b, 1.0 / gamma) - 0.055;
|
||||||
|
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
|
float4 PreGammaPass(float4 color, float2 uv0)
|
||||||
|
{
|
||||||
|
#if (SHADER_MODEL >= 0x400)
|
||||||
|
color = Texture.Sample(TextureSampler, uv0);
|
||||||
|
#elif (FXAA_GLSL_130 == 1)
|
||||||
|
color = texture(TextureSampler, uv0);
|
||||||
|
#else
|
||||||
|
color = tex2D(TextureSampler, uv0);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
const float GammaConst = 2.233;
|
||||||
|
color.rgb = RGBGammaToLinear(color.rgb, GammaConst);
|
||||||
|
color.rgb = LinearToRGBGamma(color.rgb, GammaConst);
|
||||||
|
color.a = RGBLuminance(color.rgb);
|
||||||
|
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*------------------------------------------------------------------------------
|
||||||
|
[FXAA CODE SECTION]
|
||||||
|
------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
float FxaaLuma(float4 rgba)
|
float FxaaLuma(float4 rgba)
|
||||||
{
|
{
|
||||||
rgba.w = RGBLuminance(rgba.xyz);
|
rgba.w = RGBLuminance(rgba.xyz);
|
||||||
|
@ -463,7 +521,11 @@ float4 FxaaPixelShader(float2 pos, FxaaTex tex, float2 fxaaRcpFrame, float fxaaS
|
||||||
return float4(FxaaTexTop(tex, posM).xyz, lumaM);
|
return float4(FxaaTexTop(tex, posM).xyz, lumaM);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if (FXAA_GLSL_130 == 1)
|
||||||
|
float4 FxaaPass(float4 FxaaColor, float2 uv0)
|
||||||
|
#else
|
||||||
float4 FxaaPass(float4 FxaaColor : COLOR0, float2 uv0 : TEXCOORD0)
|
float4 FxaaPass(float4 FxaaColor : COLOR0, float2 uv0 : TEXCOORD0)
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
FxaaTex tex;
|
FxaaTex tex;
|
||||||
|
|
||||||
|
@ -473,6 +535,13 @@ float4 FxaaPass(float4 FxaaColor : COLOR0, float2 uv0 : TEXCOORD0)
|
||||||
|
|
||||||
Texture.GetDimensions(PixelSize.x, PixelSize.y);
|
Texture.GetDimensions(PixelSize.x, PixelSize.y);
|
||||||
FxaaColor = FxaaPixelShader(uv0, tex, 1.0/PixelSize.xy, FxaaSubpixMax, FxaaEdgeThreshold, FxaaEdgeThresholdMin);
|
FxaaColor = FxaaPixelShader(uv0, tex, 1.0/PixelSize.xy, FxaaSubpixMax, FxaaEdgeThreshold, FxaaEdgeThresholdMin);
|
||||||
|
|
||||||
|
#elif (FXAA_GLSL_130 == 1)
|
||||||
|
|
||||||
|
tex = TextureSampler;
|
||||||
|
vec2 PixelSize = textureSize(tex, 0);
|
||||||
|
FxaaColor = FxaaPixelShader(uv0, tex, 1.0/PixelSize.xy, FxaaSubpixMax, FxaaEdgeThreshold, FxaaEdgeThresholdMin);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
tex = TextureSampler;
|
tex = TextureSampler;
|
||||||
|
@ -485,6 +554,18 @@ float4 FxaaPass(float4 FxaaColor : COLOR0, float2 uv0 : TEXCOORD0)
|
||||||
/*------------------------------------------------------------------------------
|
/*------------------------------------------------------------------------------
|
||||||
[MAIN() & COMBINE PASS CODE SECTION]
|
[MAIN() & COMBINE PASS CODE SECTION]
|
||||||
------------------------------------------------------------------------------*/
|
------------------------------------------------------------------------------*/
|
||||||
|
#if (FXAA_GLSL_130 == 1)
|
||||||
|
|
||||||
|
void ps_main()
|
||||||
|
{
|
||||||
|
vec4 color = texture(TextureSampler, PSin.t);
|
||||||
|
color = PreGammaPass(color, PSin.t);
|
||||||
|
color = FxaaPass(color, PSin.t);
|
||||||
|
|
||||||
|
SV_Target0 = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
PS_OUTPUT ps_main(VS_OUTPUT input)
|
PS_OUTPUT ps_main(VS_OUTPUT input)
|
||||||
{
|
{
|
||||||
|
@ -506,4 +587,7 @@ PS_OUTPUT ps_main(VS_OUTPUT input)
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue