2023-07-20 13:23:09 +00:00
|
|
|
/* PCSX2 - PS2 Emulator for PCs
|
|
|
|
* Copyright (C) 2002-2023 PCSX2 Dev Team
|
|
|
|
*
|
|
|
|
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU Lesser General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with PCSX2.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2022-07-16 17:29:59 +00:00
|
|
|
#ifndef FXAA_HLSL_5
|
|
|
|
#define FXAA_HLSL_5 0
|
|
|
|
#endif
|
2014-11-09 16:23:17 +00:00
|
|
|
#ifndef FXAA_GLSL_130
|
|
|
|
#define FXAA_GLSL_130 0
|
|
|
|
#endif
|
2022-03-26 19:00:52 +00:00
|
|
|
#ifndef FXAA_GLSL_VK
|
|
|
|
#define FXAA_GLSL_VK 0
|
|
|
|
#endif
|
2014-01-05 11:24:43 +00:00
|
|
|
|
2021-05-12 08:01:46 +00:00
|
|
|
#define UHQ_FXAA 1 //High Quality Fast Approximate Anti Aliasing. Adapted for GS from Timothy Lottes FXAA 3.11.
|
2014-02-11 04:27:32 +00:00
|
|
|
#define FxaaSubpixMax 0.0 //[0.00 to 1.00] Amount of subpixel aliasing removal. 0.00: Edge only antialiasing (no blurring)
|
|
|
|
#define FxaaEarlyExit 1 //[0 or 1] Use Fxaa early exit pathing. When disabled, the entire scene is antialiased(FSAA). 0 is off, 1 is on.
|
2014-01-05 11:24:43 +00:00
|
|
|
|
|
|
|
/*------------------------------------------------------------------------------
|
2014-01-17 10:17:24 +00:00
|
|
|
[GLOBALS|FUNCTIONS]
|
2014-01-05 11:24:43 +00:00
|
|
|
------------------------------------------------------------------------------*/
|
2014-11-09 16:23:17 +00:00
|
|
|
#if (FXAA_GLSL_130 == 1)
|
|
|
|
|
2021-11-30 10:35:45 +00:00
|
|
|
in vec2 PSin_t;
|
2014-11-09 16:23:17 +00:00
|
|
|
|
2021-11-30 10:35:45 +00:00
|
|
|
layout(location = 0) out vec4 SV_Target0;
|
2023-03-31 08:28:23 +00:00
|
|
|
layout(binding = 0) uniform sampler2D TextureSampler;
|
2016-06-05 14:42:52 +00:00
|
|
|
|
2022-03-26 19:00:52 +00:00
|
|
|
#elif (FXAA_GLSL_VK == 1)
|
|
|
|
|
|
|
|
layout(location = 0) in vec2 PSin_t;
|
|
|
|
layout(location = 0) out vec4 SV_Target0;
|
|
|
|
layout(set = 0, binding = 0) uniform sampler2D TextureSampler;
|
|
|
|
|
2023-07-29 04:13:08 +00:00
|
|
|
#elif (FXAA_HLSL_5 == 1)
|
2014-01-17 10:17:24 +00:00
|
|
|
Texture2D Texture : register(t0);
|
2014-02-02 17:50:32 +00:00
|
|
|
SamplerState TextureSampler : register(s0);
|
2014-01-06 18:03:47 +00:00
|
|
|
|
2014-01-05 11:24:43 +00:00
|
|
|
struct VS_INPUT
|
|
|
|
{
|
|
|
|
float4 p : POSITION;
|
|
|
|
float2 t : TEXCOORD0;
|
2012-04-23 18:56:22 +00:00
|
|
|
};
|
|
|
|
|
2014-01-05 11:24:43 +00:00
|
|
|
struct VS_OUTPUT
|
2012-04-23 18:56:22 +00:00
|
|
|
{
|
|
|
|
float4 p : SV_Position;
|
2014-01-06 18:03:47 +00:00
|
|
|
float2 t : TEXCOORD0;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct PS_OUTPUT
|
|
|
|
{
|
2014-01-17 10:17:24 +00:00
|
|
|
float4 c : SV_Target0;
|
2014-01-06 18:03:47 +00:00
|
|
|
};
|
2014-01-05 11:24:43 +00:00
|
|
|
|
2021-11-16 11:17:30 +00:00
|
|
|
#elif defined(__METAL_VERSION__)
|
|
|
|
static constexpr sampler MAIN_SAMPLER(coord::normalized, address::clamp_to_edge, filter::linear);
|
2014-11-09 16:23:17 +00:00
|
|
|
#endif
|
2014-01-05 11:24:43 +00:00
|
|
|
|
|
|
|
/*------------------------------------------------------------------------------
|
2014-01-17 10:17:24 +00:00
|
|
|
[FXAA CODE SECTION]
|
2014-01-05 11:24:43 +00:00
|
|
|
------------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
#if (FXAA_HLSL_5 == 1)
|
2014-02-11 04:27:32 +00:00
|
|
|
struct FxaaTex { SamplerState smpl; Texture2D tex; };
|
|
|
|
#define FxaaTexTop(t, p) t.tex.SampleLevel(t.smpl, p, 0.0)
|
|
|
|
#define FxaaTexOff(t, p, o, r) t.tex.SampleLevel(t.smpl, p, 0.0, o)
|
|
|
|
#define FxaaTexAlpha4(t, p) t.tex.GatherAlpha(t.smpl, p)
|
|
|
|
#define FxaaTexOffAlpha4(t, p, o) t.tex.GatherAlpha(t.smpl, p, o)
|
|
|
|
#define FxaaDiscard clip(-1)
|
|
|
|
#define FxaaSat(x) saturate(x)
|
2014-01-05 11:24:43 +00:00
|
|
|
|
2022-03-26 19:00:52 +00:00
|
|
|
#elif (FXAA_GLSL_130 == 1 || FXAA_GLSL_VK == 1)
|
2014-11-09 16:23:17 +00:00
|
|
|
#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)
|
2019-02-19 10:07:37 +00:00
|
|
|
|
2021-11-16 11:17:30 +00:00
|
|
|
#elif defined(__METAL_VERSION__)
|
|
|
|
#define FxaaTex texture2d<float>
|
|
|
|
#define FxaaTexTop(t, p) t.sample(MAIN_SAMPLER, p)
|
|
|
|
#define FxaaTexOff(t, p, o, r) t.sample(MAIN_SAMPLER, p, o)
|
|
|
|
#define FxaaTexAlpha4(t, p) t.gather(MAIN_SAMPLER, p, 0, component::w)
|
|
|
|
#define FxaaTexOffAlpha4(t, p, o) t.gather(MAIN_SAMPLER, p, o, component::w)
|
|
|
|
#define FxaaDiscard discard_fragment()
|
|
|
|
#define FxaaSat(x) saturate(x)
|
2014-01-05 11:24:43 +00:00
|
|
|
#endif
|
|
|
|
|
2014-11-06 10:56:33 +00:00
|
|
|
#define FxaaEdgeThreshold 0.063
|
2014-02-02 17:50:32 +00:00
|
|
|
#define FxaaEdgeThresholdMin 0.00
|
2022-03-26 19:24:54 +00:00
|
|
|
#define FXAA_QUALITY_P0 1.0
|
|
|
|
#define FXAA_QUALITY_P1 1.5
|
|
|
|
#define FXAA_QUALITY_P2 2.0
|
|
|
|
#define FXAA_QUALITY_P3 2.0
|
|
|
|
#define FXAA_QUALITY_P4 2.0
|
|
|
|
#define FXAA_QUALITY_P5 2.0
|
|
|
|
#define FXAA_QUALITY_P6 2.0
|
|
|
|
#define FXAA_QUALITY_P7 2.0
|
|
|
|
#define FXAA_QUALITY_P8 2.0
|
|
|
|
#define FXAA_QUALITY_P9 2.0
|
|
|
|
#define FXAA_QUALITY_P10 4.0
|
|
|
|
#define FXAA_QUALITY_P11 8.0
|
|
|
|
#define FXAA_QUALITY_P12 8.0
|
2014-02-02 17:50:32 +00:00
|
|
|
|
2014-11-09 16:23:17 +00:00
|
|
|
/*------------------------------------------------------------------------------
|
|
|
|
[GAMMA PREPASS CODE SECTION]
|
|
|
|
------------------------------------------------------------------------------*/
|
|
|
|
float RGBLuminance(float3 color)
|
|
|
|
{
|
|
|
|
const float3 lumCoeff = float3(0.2126729, 0.7151522, 0.0721750);
|
|
|
|
return dot(color.rgb, lumCoeff);
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2021-11-16 11:17:30 +00:00
|
|
|
float4 PreGammaPass(float4 color)
|
2014-11-09 16:23:17 +00:00
|
|
|
{
|
|
|
|
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]
|
|
|
|
------------------------------------------------------------------------------*/
|
|
|
|
|
2014-01-05 11:24:43 +00:00
|
|
|
float FxaaLuma(float4 rgba)
|
2014-01-17 10:17:24 +00:00
|
|
|
{
|
2014-01-05 11:24:43 +00:00
|
|
|
rgba.w = RGBLuminance(rgba.xyz);
|
2014-01-17 10:17:24 +00:00
|
|
|
return rgba.w;
|
2014-01-05 11:24:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
float4 FxaaPixelShader(float2 pos, FxaaTex tex, float2 fxaaRcpFrame, float fxaaSubpix, float fxaaEdgeThreshold, float fxaaEdgeThresholdMin)
|
|
|
|
{
|
2014-02-11 04:27:32 +00:00
|
|
|
float2 posM;
|
|
|
|
posM.x = pos.x;
|
|
|
|
posM.y = pos.y;
|
2014-01-05 11:24:43 +00:00
|
|
|
|
|
|
|
float4 rgbyM = FxaaTexTop(tex, posM);
|
2014-01-17 10:17:24 +00:00
|
|
|
rgbyM.w = RGBLuminance(rgbyM.xyz);
|
|
|
|
#define lumaM rgbyM.w
|
2014-01-05 11:24:43 +00:00
|
|
|
|
2014-01-17 10:17:24 +00:00
|
|
|
float lumaS = FxaaLuma(FxaaTexOff(tex, posM, int2( 0, 1), fxaaRcpFrame.xy));
|
|
|
|
float lumaE = FxaaLuma(FxaaTexOff(tex, posM, int2( 1, 0), fxaaRcpFrame.xy));
|
|
|
|
float lumaN = FxaaLuma(FxaaTexOff(tex, posM, int2( 0,-1), fxaaRcpFrame.xy));
|
2014-01-05 11:24:43 +00:00
|
|
|
float lumaW = FxaaLuma(FxaaTexOff(tex, posM, int2(-1, 0), fxaaRcpFrame.xy));
|
2012-04-23 18:56:22 +00:00
|
|
|
|
2014-02-11 04:27:32 +00:00
|
|
|
float maxSM = max(lumaS, lumaM);
|
|
|
|
float minSM = min(lumaS, lumaM);
|
|
|
|
float maxESM = max(lumaE, maxSM);
|
|
|
|
float minESM = min(lumaE, minSM);
|
|
|
|
float maxWN = max(lumaN, lumaW);
|
|
|
|
float minWN = min(lumaN, lumaW);
|
2014-01-05 11:24:43 +00:00
|
|
|
|
2014-02-11 04:27:32 +00:00
|
|
|
float rangeMax = max(maxWN, maxESM);
|
|
|
|
float rangeMin = min(minWN, minESM);
|
2014-01-17 10:17:24 +00:00
|
|
|
float range = rangeMax - rangeMin;
|
2014-02-11 04:27:32 +00:00
|
|
|
float rangeMaxScaled = rangeMax * fxaaEdgeThreshold;
|
|
|
|
float rangeMaxClamped = max(fxaaEdgeThresholdMin, rangeMaxScaled);
|
2014-01-17 10:17:24 +00:00
|
|
|
|
2014-02-11 04:27:32 +00:00
|
|
|
bool earlyExit = range < rangeMaxClamped;
|
|
|
|
#if (FxaaEarlyExit == 1)
|
2014-01-17 10:17:24 +00:00
|
|
|
if(earlyExit) { return rgbyM; }
|
|
|
|
#endif
|
|
|
|
|
|
|
|
float lumaNW = FxaaLuma(FxaaTexOff(tex, posM, int2(-1,-1), fxaaRcpFrame.xy));
|
|
|
|
float lumaSE = FxaaLuma(FxaaTexOff(tex, posM, int2( 1, 1), fxaaRcpFrame.xy));
|
|
|
|
float lumaNE = FxaaLuma(FxaaTexOff(tex, posM, int2( 1,-1), fxaaRcpFrame.xy));
|
2014-01-05 11:24:43 +00:00
|
|
|
float lumaSW = FxaaLuma(FxaaTexOff(tex, posM, int2(-1, 1), fxaaRcpFrame.xy));
|
2014-01-17 10:17:24 +00:00
|
|
|
|
2014-02-11 04:27:32 +00:00
|
|
|
float lumaNS = lumaN + lumaS;
|
|
|
|
float lumaWE = lumaW + lumaE;
|
|
|
|
float subpixRcpRange = 1.0/range;
|
|
|
|
float subpixNSWE = lumaNS + lumaWE;
|
|
|
|
float edgeHorz1 = (-2.0 * lumaM) + lumaNS;
|
|
|
|
float edgeVert1 = (-2.0 * lumaM) + lumaWE;
|
|
|
|
float lumaNESE = lumaNE + lumaSE;
|
|
|
|
float lumaNWNE = lumaNW + lumaNE;
|
|
|
|
float edgeHorz2 = (-2.0 * lumaE) + lumaNESE;
|
|
|
|
float edgeVert2 = (-2.0 * lumaN) + lumaNWNE;
|
|
|
|
|
|
|
|
float lumaNWSW = lumaNW + lumaSW;
|
|
|
|
float lumaSWSE = lumaSW + lumaSE;
|
|
|
|
float edgeHorz4 = (abs(edgeHorz1) * 2.0) + abs(edgeHorz2);
|
|
|
|
float edgeVert4 = (abs(edgeVert1) * 2.0) + abs(edgeVert2);
|
|
|
|
float edgeHorz3 = (-2.0 * lumaW) + lumaNWSW;
|
|
|
|
float edgeVert3 = (-2.0 * lumaS) + lumaSWSE;
|
|
|
|
float edgeHorz = abs(edgeHorz3) + edgeHorz4;
|
|
|
|
float edgeVert = abs(edgeVert3) + edgeVert4;
|
|
|
|
|
|
|
|
float subpixNWSWNESE = lumaNWSW + lumaNESE;
|
|
|
|
float lengthSign = fxaaRcpFrame.x;
|
|
|
|
bool horzSpan = edgeHorz >= edgeVert;
|
|
|
|
float subpixA = subpixNSWE * 2.0 + subpixNWSWNESE;
|
|
|
|
if(!horzSpan) lumaN = lumaW;
|
|
|
|
if(!horzSpan) lumaS = lumaE;
|
|
|
|
if(horzSpan) lengthSign = fxaaRcpFrame.y;
|
|
|
|
float subpixB = (subpixA * (1.0/12.0)) - lumaM;
|
|
|
|
|
|
|
|
float gradientN = lumaN - lumaM;
|
|
|
|
float gradientS = lumaS - lumaM;
|
|
|
|
float lumaNN = lumaN + lumaM;
|
|
|
|
float lumaSS = lumaS + lumaM;
|
|
|
|
bool pairN = abs(gradientN) >= abs(gradientS);
|
|
|
|
float gradient = max(abs(gradientN), abs(gradientS));
|
|
|
|
if(pairN) lengthSign = -lengthSign;
|
|
|
|
float subpixC = FxaaSat(abs(subpixB) * subpixRcpRange);
|
|
|
|
|
|
|
|
float2 posB;
|
|
|
|
posB.x = posM.x;
|
|
|
|
posB.y = posM.y;
|
|
|
|
float2 offNP;
|
|
|
|
offNP.x = (!horzSpan) ? 0.0 : fxaaRcpFrame.x;
|
|
|
|
offNP.y = ( horzSpan) ? 0.0 : fxaaRcpFrame.y;
|
|
|
|
if(!horzSpan) posB.x += lengthSign * 0.5;
|
|
|
|
if( horzSpan) posB.y += lengthSign * 0.5;
|
|
|
|
|
|
|
|
float2 posN;
|
2022-03-26 19:24:54 +00:00
|
|
|
posN.x = posB.x - offNP.x * FXAA_QUALITY_P0;
|
|
|
|
posN.y = posB.y - offNP.y * FXAA_QUALITY_P0;
|
2014-02-11 04:27:32 +00:00
|
|
|
float2 posP;
|
2022-03-26 19:24:54 +00:00
|
|
|
posP.x = posB.x + offNP.x * FXAA_QUALITY_P0;
|
|
|
|
posP.y = posB.y + offNP.y * FXAA_QUALITY_P0;
|
2014-02-11 04:27:32 +00:00
|
|
|
float subpixD = ((-2.0)*subpixC) + 3.0;
|
|
|
|
float lumaEndN = FxaaLuma(FxaaTexTop(tex, posN));
|
|
|
|
float subpixE = subpixC * subpixC;
|
|
|
|
float lumaEndP = FxaaLuma(FxaaTexTop(tex, posP));
|
|
|
|
|
|
|
|
if(!pairN) lumaNN = lumaSS;
|
|
|
|
float gradientScaled = gradient * 1.0/4.0;
|
|
|
|
float lumaMM = lumaM - lumaNN * 0.5;
|
|
|
|
float subpixF = subpixD * subpixE;
|
|
|
|
bool lumaMLTZero = lumaMM < 0.0;
|
|
|
|
lumaEndN -= lumaNN * 0.5;
|
|
|
|
lumaEndP -= lumaNN * 0.5;
|
|
|
|
bool doneN = abs(lumaEndN) >= gradientScaled;
|
|
|
|
bool doneP = abs(lumaEndP) >= gradientScaled;
|
2022-03-26 19:24:54 +00:00
|
|
|
if(!doneN) posN.x -= offNP.x * FXAA_QUALITY_P1;
|
|
|
|
if(!doneN) posN.y -= offNP.y * FXAA_QUALITY_P1;
|
2014-02-11 04:27:32 +00:00
|
|
|
bool doneNP = (!doneN) || (!doneP);
|
2022-03-26 19:24:54 +00:00
|
|
|
if(!doneP) posP.x += offNP.x * FXAA_QUALITY_P1;
|
|
|
|
if(!doneP) posP.y += offNP.y * FXAA_QUALITY_P1;
|
2014-01-17 10:17:24 +00:00
|
|
|
|
|
|
|
if(doneNP) {
|
|
|
|
if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));
|
|
|
|
if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));
|
|
|
|
if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;
|
|
|
|
if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;
|
|
|
|
doneN = abs(lumaEndN) >= gradientScaled;
|
|
|
|
doneP = abs(lumaEndP) >= gradientScaled;
|
2022-03-26 19:24:54 +00:00
|
|
|
if(!doneN) posN.x -= offNP.x * FXAA_QUALITY_P2;
|
|
|
|
if(!doneN) posN.y -= offNP.y * FXAA_QUALITY_P2;
|
2014-01-17 10:17:24 +00:00
|
|
|
doneNP = (!doneN) || (!doneP);
|
2022-03-26 19:24:54 +00:00
|
|
|
if(!doneP) posP.x += offNP.x * FXAA_QUALITY_P2;
|
|
|
|
if(!doneP) posP.y += offNP.y * FXAA_QUALITY_P2;
|
2014-01-17 10:17:24 +00:00
|
|
|
|
|
|
|
if(doneNP) {
|
|
|
|
if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));
|
|
|
|
if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));
|
|
|
|
if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;
|
|
|
|
if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;
|
|
|
|
doneN = abs(lumaEndN) >= gradientScaled;
|
|
|
|
doneP = abs(lumaEndP) >= gradientScaled;
|
2022-03-26 19:24:54 +00:00
|
|
|
if(!doneN) posN.x -= offNP.x * FXAA_QUALITY_P3;
|
|
|
|
if(!doneN) posN.y -= offNP.y * FXAA_QUALITY_P3;
|
2014-01-17 10:17:24 +00:00
|
|
|
doneNP = (!doneN) || (!doneP);
|
2022-03-26 19:24:54 +00:00
|
|
|
if(!doneP) posP.x += offNP.x * FXAA_QUALITY_P3;
|
|
|
|
if(!doneP) posP.y += offNP.y * FXAA_QUALITY_P3;
|
2014-01-17 10:17:24 +00:00
|
|
|
|
|
|
|
if(doneNP) {
|
|
|
|
if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));
|
|
|
|
if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));
|
|
|
|
if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;
|
|
|
|
if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;
|
|
|
|
doneN = abs(lumaEndN) >= gradientScaled;
|
|
|
|
doneP = abs(lumaEndP) >= gradientScaled;
|
2022-03-26 19:24:54 +00:00
|
|
|
if(!doneN) posN.x -= offNP.x * FXAA_QUALITY_P4;
|
|
|
|
if(!doneN) posN.y -= offNP.y * FXAA_QUALITY_P4;
|
2014-01-17 10:17:24 +00:00
|
|
|
doneNP = (!doneN) || (!doneP);
|
2022-03-26 19:24:54 +00:00
|
|
|
if(!doneP) posP.x += offNP.x * FXAA_QUALITY_P4;
|
|
|
|
if(!doneP) posP.y += offNP.y * FXAA_QUALITY_P4;
|
2014-01-17 10:17:24 +00:00
|
|
|
|
|
|
|
if(doneNP) {
|
|
|
|
if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));
|
|
|
|
if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));
|
|
|
|
if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;
|
|
|
|
if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;
|
|
|
|
doneN = abs(lumaEndN) >= gradientScaled;
|
|
|
|
doneP = abs(lumaEndP) >= gradientScaled;
|
2022-03-26 19:24:54 +00:00
|
|
|
if(!doneN) posN.x -= offNP.x * FXAA_QUALITY_P5;
|
|
|
|
if(!doneN) posN.y -= offNP.y * FXAA_QUALITY_P5;
|
2014-01-17 10:17:24 +00:00
|
|
|
doneNP = (!doneN) || (!doneP);
|
2022-03-26 19:24:54 +00:00
|
|
|
if(!doneP) posP.x += offNP.x * FXAA_QUALITY_P5;
|
|
|
|
if(!doneP) posP.y += offNP.y * FXAA_QUALITY_P5;
|
2014-01-17 10:17:24 +00:00
|
|
|
|
|
|
|
if(doneNP) {
|
|
|
|
if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));
|
|
|
|
if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));
|
|
|
|
if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;
|
|
|
|
if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;
|
|
|
|
doneN = abs(lumaEndN) >= gradientScaled;
|
|
|
|
doneP = abs(lumaEndP) >= gradientScaled;
|
2022-03-26 19:24:54 +00:00
|
|
|
if(!doneN) posN.x -= offNP.x * FXAA_QUALITY_P6;
|
|
|
|
if(!doneN) posN.y -= offNP.y * FXAA_QUALITY_P6;
|
2014-01-17 10:17:24 +00:00
|
|
|
doneNP = (!doneN) || (!doneP);
|
2022-03-26 19:24:54 +00:00
|
|
|
if(!doneP) posP.x += offNP.x * FXAA_QUALITY_P6;
|
|
|
|
if(!doneP) posP.y += offNP.y * FXAA_QUALITY_P6;
|
2014-01-17 10:17:24 +00:00
|
|
|
|
|
|
|
if(doneNP) {
|
|
|
|
if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));
|
|
|
|
if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));
|
|
|
|
if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;
|
|
|
|
if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;
|
|
|
|
doneN = abs(lumaEndN) >= gradientScaled;
|
|
|
|
doneP = abs(lumaEndP) >= gradientScaled;
|
2022-03-26 19:24:54 +00:00
|
|
|
if(!doneN) posN.x -= offNP.x * FXAA_QUALITY_P7;
|
|
|
|
if(!doneN) posN.y -= offNP.y * FXAA_QUALITY_P7;
|
2014-01-17 10:17:24 +00:00
|
|
|
doneNP = (!doneN) || (!doneP);
|
2022-03-26 19:24:54 +00:00
|
|
|
if(!doneP) posP.x += offNP.x * FXAA_QUALITY_P7;
|
|
|
|
if(!doneP) posP.y += offNP.y * FXAA_QUALITY_P7;
|
2014-01-17 10:17:24 +00:00
|
|
|
|
|
|
|
if(doneNP) {
|
|
|
|
if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));
|
|
|
|
if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));
|
|
|
|
if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;
|
|
|
|
if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;
|
|
|
|
doneN = abs(lumaEndN) >= gradientScaled;
|
|
|
|
doneP = abs(lumaEndP) >= gradientScaled;
|
2022-03-26 19:24:54 +00:00
|
|
|
if(!doneN) posN.x -= offNP.x * FXAA_QUALITY_P8;
|
|
|
|
if(!doneN) posN.y -= offNP.y * FXAA_QUALITY_P8;
|
2014-01-17 10:17:24 +00:00
|
|
|
doneNP = (!doneN) || (!doneP);
|
2022-03-26 19:24:54 +00:00
|
|
|
if(!doneP) posP.x += offNP.x * FXAA_QUALITY_P8;
|
|
|
|
if(!doneP) posP.y += offNP.y * FXAA_QUALITY_P8;
|
2014-01-17 10:17:24 +00:00
|
|
|
|
|
|
|
if(doneNP) {
|
|
|
|
if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));
|
|
|
|
if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));
|
|
|
|
if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;
|
|
|
|
if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;
|
|
|
|
doneN = abs(lumaEndN) >= gradientScaled;
|
|
|
|
doneP = abs(lumaEndP) >= gradientScaled;
|
2022-03-26 19:24:54 +00:00
|
|
|
if(!doneN) posN.x -= offNP.x * FXAA_QUALITY_P9;
|
|
|
|
if(!doneN) posN.y -= offNP.y * FXAA_QUALITY_P9;
|
2014-01-17 10:17:24 +00:00
|
|
|
doneNP = (!doneN) || (!doneP);
|
2022-03-26 19:24:54 +00:00
|
|
|
if(!doneP) posP.x += offNP.x * FXAA_QUALITY_P9;
|
|
|
|
if(!doneP) posP.y += offNP.y * FXAA_QUALITY_P9;
|
2014-01-17 10:17:24 +00:00
|
|
|
|
|
|
|
if(doneNP) {
|
|
|
|
if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));
|
|
|
|
if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));
|
|
|
|
if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;
|
|
|
|
if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;
|
|
|
|
doneN = abs(lumaEndN) >= gradientScaled;
|
|
|
|
doneP = abs(lumaEndP) >= gradientScaled;
|
2022-03-26 19:24:54 +00:00
|
|
|
if(!doneN) posN.x -= offNP.x * FXAA_QUALITY_P10;
|
|
|
|
if(!doneN) posN.y -= offNP.y * FXAA_QUALITY_P10;
|
2014-01-17 10:17:24 +00:00
|
|
|
doneNP = (!doneN) || (!doneP);
|
2022-03-26 19:24:54 +00:00
|
|
|
if(!doneP) posP.x += offNP.x * FXAA_QUALITY_P10;
|
|
|
|
if(!doneP) posP.y += offNP.y * FXAA_QUALITY_P10;
|
2014-01-17 10:17:24 +00:00
|
|
|
|
|
|
|
if(doneNP) {
|
|
|
|
if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));
|
|
|
|
if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));
|
|
|
|
if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;
|
|
|
|
if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;
|
|
|
|
doneN = abs(lumaEndN) >= gradientScaled;
|
|
|
|
doneP = abs(lumaEndP) >= gradientScaled;
|
2022-03-26 19:24:54 +00:00
|
|
|
if(!doneN) posN.x -= offNP.x * FXAA_QUALITY_P11;
|
|
|
|
if(!doneN) posN.y -= offNP.y * FXAA_QUALITY_P11;
|
2014-01-17 10:17:24 +00:00
|
|
|
doneNP = (!doneN) || (!doneP);
|
2022-03-26 19:24:54 +00:00
|
|
|
if(!doneP) posP.x += offNP.x * FXAA_QUALITY_P11;
|
|
|
|
if(!doneP) posP.y += offNP.y * FXAA_QUALITY_P11;
|
2014-01-17 10:17:24 +00:00
|
|
|
|
|
|
|
if(doneNP) {
|
|
|
|
if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));
|
|
|
|
if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));
|
|
|
|
if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;
|
|
|
|
if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;
|
|
|
|
doneN = abs(lumaEndN) >= gradientScaled;
|
|
|
|
doneP = abs(lumaEndP) >= gradientScaled;
|
2022-03-26 19:24:54 +00:00
|
|
|
if(!doneN) posN.x -= offNP.x * FXAA_QUALITY_P12;
|
|
|
|
if(!doneN) posN.y -= offNP.y * FXAA_QUALITY_P12;
|
2014-01-17 10:17:24 +00:00
|
|
|
doneNP = (!doneN) || (!doneP);
|
2022-03-26 19:24:54 +00:00
|
|
|
if(!doneP) posP.x += offNP.x * FXAA_QUALITY_P12;
|
|
|
|
if(!doneP) posP.y += offNP.y * FXAA_QUALITY_P12;
|
2014-02-02 17:50:32 +00:00
|
|
|
}}}}}}}}}}}
|
|
|
|
|
2014-02-11 04:27:32 +00:00
|
|
|
float dstN = posM.x - posN.x;
|
|
|
|
float dstP = posP.x - posM.x;
|
|
|
|
if(!horzSpan) dstN = posM.y - posN.y;
|
|
|
|
if(!horzSpan) dstP = posP.y - posM.y;
|
|
|
|
|
|
|
|
bool goodSpanN = (lumaEndN < 0.0) != lumaMLTZero;
|
|
|
|
float spanLength = (dstP + dstN);
|
|
|
|
bool goodSpanP = (lumaEndP < 0.0) != lumaMLTZero;
|
|
|
|
float spanLengthRcp = 1.0/spanLength;
|
|
|
|
|
|
|
|
bool directionN = dstN < dstP;
|
|
|
|
float dst = min(dstN, dstP);
|
|
|
|
bool goodSpan = directionN ? goodSpanN : goodSpanP;
|
|
|
|
float subpixG = subpixF * subpixF;
|
|
|
|
float pixelOffset = (dst * (-spanLengthRcp)) + 0.5;
|
|
|
|
float subpixH = subpixG * fxaaSubpix;
|
|
|
|
|
|
|
|
float pixelOffsetGood = goodSpan ? pixelOffset : 0.0;
|
|
|
|
float pixelOffsetSubpix = max(pixelOffsetGood, subpixH);
|
|
|
|
if(!horzSpan) posM.x += pixelOffsetSubpix * lengthSign;
|
|
|
|
if( horzSpan) posM.y += pixelOffsetSubpix * lengthSign;
|
2014-01-05 11:24:43 +00:00
|
|
|
|
2014-01-17 10:17:24 +00:00
|
|
|
return float4(FxaaTexTop(tex, posM).xyz, lumaM);
|
2014-01-05 11:24:43 +00:00
|
|
|
}
|
|
|
|
|
2022-03-26 19:00:52 +00:00
|
|
|
#if (FXAA_GLSL_130 == 1 || FXAA_GLSL_VK == 1)
|
2014-11-09 16:23:17 +00:00
|
|
|
float4 FxaaPass(float4 FxaaColor, float2 uv0)
|
2023-07-29 04:13:08 +00:00
|
|
|
#elif (FXAA_HLSL_5 == 1)
|
2014-01-17 10:17:24 +00:00
|
|
|
float4 FxaaPass(float4 FxaaColor : COLOR0, float2 uv0 : TEXCOORD0)
|
2021-11-16 11:17:30 +00:00
|
|
|
#elif defined(__METAL_VERSION__)
|
|
|
|
float4 FxaaPass(float4 FxaaColor, float2 uv0, texture2d<float> tex)
|
2014-11-09 16:23:17 +00:00
|
|
|
#endif
|
2014-01-05 11:24:43 +00:00
|
|
|
{
|
|
|
|
|
2023-07-29 04:13:08 +00:00
|
|
|
#if (FXAA_HLSL_5 == 1)
|
2014-11-20 21:07:44 +00:00
|
|
|
FxaaTex tex;
|
2014-01-17 10:17:24 +00:00
|
|
|
tex.tex = Texture;
|
|
|
|
tex.smpl = TextureSampler;
|
2014-02-02 17:50:32 +00:00
|
|
|
|
2021-10-20 07:52:05 +00:00
|
|
|
float2 PixelSize;
|
2014-01-05 11:24:43 +00:00
|
|
|
Texture.GetDimensions(PixelSize.x, PixelSize.y);
|
2014-01-17 10:17:24 +00:00
|
|
|
FxaaColor = FxaaPixelShader(uv0, tex, 1.0/PixelSize.xy, FxaaSubpixMax, FxaaEdgeThreshold, FxaaEdgeThresholdMin);
|
2014-11-09 16:23:17 +00:00
|
|
|
|
2022-03-26 19:00:52 +00:00
|
|
|
#elif (FXAA_GLSL_130 == 1 || FXAA_GLSL_VK == 1)
|
2022-07-16 17:29:59 +00:00
|
|
|
vec2 PixelSize = vec2(textureSize(TextureSampler, 0));
|
2014-11-20 21:07:44 +00:00
|
|
|
FxaaColor = FxaaPixelShader(uv0, TextureSampler, 1.0/PixelSize.xy, FxaaSubpixMax, FxaaEdgeThreshold, FxaaEdgeThresholdMin);
|
2021-11-16 11:17:30 +00:00
|
|
|
#elif defined(__METAL_VERSION__)
|
|
|
|
float2 PixelSize = float2(tex.get_width(), tex.get_height());
|
|
|
|
FxaaColor = FxaaPixelShader(uv0, tex, 1.f/PixelSize, FxaaSubpixMax, FxaaEdgeThreshold, FxaaEdgeThresholdMin);
|
2014-01-17 10:17:24 +00:00
|
|
|
#endif
|
2014-01-05 11:24:43 +00:00
|
|
|
|
2014-01-17 10:17:24 +00:00
|
|
|
return FxaaColor;
|
2014-01-05 11:24:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*------------------------------------------------------------------------------
|
2014-01-17 10:17:24 +00:00
|
|
|
[MAIN() & COMBINE PASS CODE SECTION]
|
2014-01-05 11:24:43 +00:00
|
|
|
------------------------------------------------------------------------------*/
|
2022-03-26 19:00:52 +00:00
|
|
|
#if (FXAA_GLSL_130 == 1 || FXAA_GLSL_VK == 1)
|
2014-11-09 16:23:17 +00:00
|
|
|
|
2022-03-26 19:00:52 +00:00
|
|
|
void main()
|
2014-11-09 16:23:17 +00:00
|
|
|
{
|
2021-11-30 10:35:45 +00:00
|
|
|
vec4 color = texture(TextureSampler, PSin_t);
|
2021-11-16 11:17:30 +00:00
|
|
|
color = PreGammaPass(color);
|
2021-11-30 10:35:45 +00:00
|
|
|
color = FxaaPass(color, PSin_t);
|
2014-11-09 16:23:17 +00:00
|
|
|
|
2022-12-12 03:10:02 +00:00
|
|
|
SV_Target0 = float4(color.rgb, 1.0);
|
2014-11-09 16:23:17 +00:00
|
|
|
}
|
|
|
|
|
2023-07-29 04:13:08 +00:00
|
|
|
#elif (FXAA_HLSL_5 == 1)
|
|
|
|
PS_OUTPUT main(VS_OUTPUT input)
|
2014-01-05 11:24:43 +00:00
|
|
|
{
|
2014-01-17 10:17:24 +00:00
|
|
|
PS_OUTPUT output;
|
2014-01-05 11:24:43 +00:00
|
|
|
|
2019-02-19 10:07:37 +00:00
|
|
|
float4 color = Texture.Sample(TextureSampler, input.t);
|
2014-02-02 17:50:32 +00:00
|
|
|
|
2021-11-16 11:17:30 +00:00
|
|
|
color = PreGammaPass(color);
|
2019-02-19 10:07:37 +00:00
|
|
|
color = FxaaPass(color, input.t);
|
2014-01-05 11:24:43 +00:00
|
|
|
|
2022-12-12 03:10:02 +00:00
|
|
|
output.c = float4(color.rgb, 1.0);
|
2014-01-17 10:17:24 +00:00
|
|
|
|
|
|
|
return output;
|
2014-01-05 11:24:43 +00:00
|
|
|
}
|
2014-11-09 16:23:17 +00:00
|
|
|
|
2021-11-16 11:17:30 +00:00
|
|
|
// Metal main function in in fxaa.metal
|
2014-11-09 16:23:17 +00:00
|
|
|
#endif
|