diff --git a/Shaders/AdaptiveSharpen.fx b/Shaders/AdaptiveSharpen.fx index 3876d380..28b8b2b8 100644 --- a/Shaders/AdaptiveSharpen.fx +++ b/Shaders/AdaptiveSharpen.fx @@ -34,7 +34,7 @@ uniform float curve_height < > = 1.0; uniform float curveslope < - ui_min = 0.1; ui_max = 2.0; + ui_min = 0.01; ui_max = 2.0; ui_tooltip = "Sharpening curve slope, high edge values"; > = 0.4; @@ -91,12 +91,12 @@ uniform float pm_p < #include "ReShade.fxh" -texture Pass0Tex { Width = BUFFER_WIDTH; Height = BUFFER_HEIGHT; Format = RG16F; }; -sampler Pass0_Sampler { Texture = Pass0Tex; }; +texture AS_Pass0Tex { Width = BUFFER_WIDTH; Height = BUFFER_HEIGHT; Format = RG16F; }; +sampler AS_Pass0Sampler { Texture = AS_Pass0Tex; }; // Get destination pixel values -#define get1(x,y) ( saturate(tex2D(ReShade::BackBuffer, tex + ReShade::PixelSize*float2(x, y)).rgb) ) -#define get2(x,y) ( tex2D(Pass0_Sampler, tex + ReShade::PixelSize*float2(x, y)).xy ) +#define getB(x,y) ( saturate(tex2D(ReShade::BackBuffer, tex + ReShade::PixelSize*float2(x, y)).rgb) ) +#define getT(x,y) ( tex2D(AS_Pass0Sampler, tex + ReShade::PixelSize*float2(x, y)).xy ) // Soft if, fast approx #define soft_if(a,b,c) ( saturate((a + b + c + 0.06)*rcp(abs(maxedge) + 0.03) - 0.85) ) @@ -120,7 +120,7 @@ sampler Pass0_Sampler { Texture = Pass0Tex; }; // Fast-skip threshold, keep max possible error under 1/16-bit #if (fast_ops == 1) // Approx of x = tanh(x/y)*y + 1/2^16, y = min(L_overshoot, D_overshoot) - #define fskip_th ( 0.03523085*pow(min(L_overshoot, D_overshoot), 0.65884327) ) + #define fskip_th ( 0.03523085*pow(min(abs(L_overshoot), abs(D_overshoot)), 0.65884327) ) #else // x = tanh(x/y)*y + 1/2^16, y = 0.0001 #define fskip_th ( 0.0000836583 ) @@ -139,9 +139,9 @@ float2 AdaptiveSharpenP0(float4 vpos : SV_Position, float2 tex : TEXCOORD) : SV_ // [ c10, c4, c0, c5, c11 ] // [ c6, c7, c8, ] // [ c12, ] - float3 c[13] = { get1( 0, 0), get1(-1,-1), get1( 0,-1), get1( 1,-1), get1(-1, 0), - get1( 1, 0), get1(-1, 1), get1( 0, 1), get1( 1, 1), get1( 0,-2), - get1(-2, 0), get1( 2, 0), get1( 0, 2) }; + float3 c[13] = { getB( 0, 0), getB(-1,-1), getB( 0,-1), getB( 1,-1), getB(-1, 0), + getB( 1, 0), getB(-1, 1), getB( 0, 1), getB( 1, 1), getB( 0,-2), + getB(-2, 0), getB( 2, 0), getB( 0, 2) }; // Colour to luma, fast approx gamma, avg of rec. 709 & 601 luma coeffs float luma = sqrt(dot(float3(0.2558, 0.6511, 0.0931), c[0]*c[0])); @@ -170,9 +170,9 @@ float2 AdaptiveSharpenP0(float4 vpos : SV_Position, float2 tex : TEXCOORD) : SV_ float3 AdaptiveSharpenP1(float4 vpos : SV_Position, float2 tex : TEXCOORD) : SV_Target { - float3 origsat = saturate(tex2D(ReShade::BackBuffer, tex).rgb); + float3 origsat = getB(0, 0); - // Get points, .x = edge, .y = luma + // Get texture points, .x = edge, .y = luma // [ d22 ] // [ d24, d9, d23 ] // [ d21, d1, d2, d3, d18 ] @@ -180,11 +180,11 @@ float3 AdaptiveSharpenP1(float4 vpos : SV_Position, float2 tex : TEXCOORD) : SV_ // [ d20, d6, d7, d8, d17 ] // [ d15, d12, d14 ] // [ d13 ] - float2 d[25] = { get2( 0, 0), get2(-1,-1), get2( 0,-1), get2( 1,-1), get2(-1, 0), - get2( 1, 0), get2(-1, 1), get2( 0, 1), get2( 1, 1), get2( 0,-2), - get2(-2, 0), get2( 2, 0), get2( 0, 2), get2( 0, 3), get2( 1, 2), - get2(-1, 2), get2( 3, 0), get2( 2, 1), get2( 2,-1), get2(-3, 0), - get2(-2, 1), get2(-2,-1), get2( 0,-3), get2( 1,-2), get2(-1,-2) }; + float2 d[25] = { getT( 0, 0), getT(-1,-1), getT( 0,-1), getT( 1,-1), getT(-1, 0), + getT( 1, 0), getT(-1, 1), getT( 0, 1), getT( 1, 1), getT( 0,-2), + getT(-2, 0), getT( 2, 0), getT( 0, 2), getT( 0, 3), getT( 1, 2), + getT(-1, 2), getT( 3, 0), getT( 2, 1), getT( 2,-1), getT(-3, 0), + getT(-2, 1), getT(-2,-1), getT( 0,-3), getT( 1,-2), getT(-1,-2) }; // Allow for higher overshoot if the current edge pixel is surrounded by similar edge pixels float maxedge = max4( max4(d[1].x,d[2].x,d[3].x,d[4].x), max4(d[5].x,d[6].x,d[7].x,d[8].x), @@ -264,8 +264,8 @@ float3 AdaptiveSharpenP1(float4 vpos : SV_Position, float2 tex : TEXCOORD) : SV_ neg_laplace += (luma[pix + 1]*luma[pix + 1])*(weights[pix]*lowthr); #else - float x = saturate((d[pix + 1].x - 0.01)/0.10); - float lowthr = x*x*(2.97 - 1.98*x) + 0.01; // x*x((3.0-c*3) - (2.0-c*2)*x) + c + float t = saturate((d[pix + 1].x - 0.01)/0.10); + float lowthr = t*t*(2.97 - 1.98*t) + 0.01; // t*t((3 - a*3) - (2 - a*2)*t) + a neg_laplace += pow(abs(luma[pix + 1]) + 0.06, 2.4)*(weights[pix]*lowthr); #endif @@ -376,7 +376,7 @@ float3 AdaptiveSharpenP1(float4 vpos : SV_Position, float2 tex : TEXCOORD) : SV_ // Compensate for saturation loss/gain while making pixels brighter/darker float sharpdiff_lim = saturate(d[0].y + sharpdiff) - d[0].y; float satmul = (d[0].y + sharpdiff_lim + 0.03)/(d[0].y + 0.03); - float3 res = d[0].y + (sharpdiff_lim + sharpdiff)/2 + (origsat - d[0].y)*satmul; + float3 res = d[0].y + (sharpdiff_lim*3 + sharpdiff)/4 + (origsat - d[0].y)*satmul; return saturate(res); } @@ -387,7 +387,7 @@ technique AdaptiveSharpen { VertexShader = PostProcessVS; PixelShader = AdaptiveSharpenP0; - RenderTarget = Pass0Tex; + RenderTarget = AS_Pass0Tex; } pass AdaptiveSharpenPass2 diff --git a/Shaders/Colourfulness.fx b/Shaders/Colourfulness.fx index 6ebafa16..e152cbd0 100644 --- a/Shaders/Colourfulness.fx +++ b/Shaders/Colourfulness.fx @@ -54,8 +54,8 @@ uniform float lim_luma < #define wpmean(a,b,w) ( pow(abs(w)*sqrt(abs(a)) + abs(1-w)*sqrt(abs(b)), 2) ) // Max/Min RGB components -#define max3(RGB) ( max((RGB).r, max((RGB).g, (RGB).b)) ) -#define min3(RGB) ( min((RGB).r, min((RGB).g, (RGB).b)) ) +#define maxRGB(c) ( max((c).r, max((c).g, (c).b)) ) +#define minRGB(c) ( min((c).r, min((c).g, (c).b)) ) // Mean of Rec. 709 & 601 luma coefficients #define lumacoeff float3(0.2558, 0.6511, 0.0931) @@ -81,8 +81,8 @@ float3 Colourfulness(float4 vpos : SV_Position, float2 tex : TEXCOORD) : SV_Targ float3 rlc_diff = clamp((c_diff*1.2) + c0, -0.0001, 1.0001) - c0; // Calc max saturation-increase without altering RGB ratios - float poslim = (1.0002 - luma)/(abs(max3(diff_luma)) + 0.0001); - float neglim = (luma + 0.0002)/(abs(min3(diff_luma)) + 0.0001); + float poslim = (1.0002 - luma)/(abs(maxRGB(diff_luma)) + 0.0001); + float neglim = (luma + 0.0002)/(abs(minRGB(diff_luma)) + 0.0001); float3 diffmax = diff_luma*min(min(poslim, neglim), 32) - diff_luma; diff --git a/Shaders/FXAA.fx b/Shaders/FXAA.fx index 19ae0b1b..e4a415f2 100644 --- a/Shaders/FXAA.fx +++ b/Shaders/FXAA.fx @@ -1,14 +1,14 @@ /** - * FXAA 3.11 + * FXAA 3.11 * - * for ReShade 3.0 + * for ReShade 3.0 */ uniform float Subpix < ui_type = "drag"; ui_min = 0.0; ui_max = 1.0; ui_tooltip = "Amount of sub-pixel aliasing removal. Higher values makes the image softer/blurrier."; -> = 0.25; +> = 0.25; uniform float EdgeThreshold < ui_type = "drag"; @@ -23,10 +23,23 @@ uniform float EdgeThresholdMin < ui_tooltip = "Pixels darker than this are not processed in order to increase performance."; > = 0.0; -#define FXAA_PC 1 -#define FXAA_HLSL_3 1 -#define FXAA_QUALITY__PRESET 15 -#define FXAA_GREEN_AS_LUMA 0 +//-------------------------------------- Non-GUI-settings ----------------------------------------- +#ifndef FXAA_QUALITY__PRESET + // Valid Quality Presets + // 10 to 15 - default medium dither (10=fastest, 15=highest quality) + // 20 to 29 - less dither, more expensive (20=fastest, 29=highest quality) + // 39 - no dither, very expensive + #define FXAA_QUALITY__PRESET 15 +#endif + +#ifndef FXAA_GREEN_AS_LUMA + #define FXAA_GREEN_AS_LUMA 0 +#endif + +#ifndef FXAA_LINEAR_LIGHT + #define FXAA_LINEAR_LIGHT 1 +#endif +//------------------------------------------------------------------------------------------------- #if (__RENDERER__ == 0xb000 || __RENDERER__ == 0xb100) #define FXAA_GATHER4_ALPHA 1 @@ -36,6 +49,9 @@ uniform float EdgeThresholdMin < #define FxaaTexOffGreen4(t, p, o) tex2Dgatheroffset(t, p, o, 1) #endif +#define FXAA_PC 1 +#define FXAA_HLSL_3 1 + #include "FXAA.fxh" #include "ReShade.fxh" @@ -45,18 +61,20 @@ sampler FXAATexture { Texture = ReShade::BackBufferTex; MinFilter = Linear; MagFilter = Linear; - SRGBTexture = true; + #if FXAA_LINEAR_LIGHT + SRGBTexture = true; + #endif }; // Pixel shaders #if !FXAA_GREEN_AS_LUMA -float4 FXAALumaPass(float4 vpos : SV_Position, noperspective float2 texcoord : TEXCOORD) : SV_Target -{ - float4 color = tex2D(FXAATexture, texcoord.xy); - color.a = sqrt(dot(color.rgb, float3(0.299, 0.587, 0.114))); - return color; -} + float4 FXAALumaPass(float4 vpos : SV_Position, noperspective float2 texcoord : TEXCOORD) : SV_Target + { + float4 color = tex2D(ReShade::BackBuffer, texcoord.xy); + color.a = sqrt(dot(color.rgb*color.rgb, float3(0.299, 0.587, 0.114))); + return color; + } #endif float4 FXAAPixelShader(float4 vpos : SV_Position, noperspective float2 texcoord : TEXCOORD) : SV_Target @@ -82,21 +100,22 @@ float4 FXAAPixelShader(float4 vpos : SV_Position, noperspective float2 texcoord } // Rendering passes - + technique FXAA { -#if !FXAA_GREEN_AS_LUMA - pass - { - VertexShader = PostProcessVS; - PixelShader = FXAALumaPass; - SRGBWriteEnable = true; - } -#endif + #if !FXAA_GREEN_AS_LUMA + pass + { + VertexShader = PostProcessVS; + PixelShader = FXAALumaPass; + } + #endif pass { VertexShader = PostProcessVS; PixelShader = FXAAPixelShader; - SRGBWriteEnable = true; + #if FXAA_LINEAR_LIGHT + SRGBWriteEnable = true; + #endif } } diff --git a/Shaders/SMAA.fx b/Shaders/SMAA.fx index 648d56ba..dea3af88 100644 --- a/Shaders/SMAA.fx +++ b/Shaders/SMAA.fx @@ -19,20 +19,20 @@ uniform int EdgeDetectionType < > = 1; uniform float EdgeDetectionThreshold < ui_type = "drag"; - ui_min = 0.05; ui_max = 0.20; ui_step = 0.02; + ui_min = 0.05; ui_max = 0.20; ui_step = 0.01; ui_tooltip = "Edge detection threshold. If SMAA misses some edges try lowering this slightly."; ui_label = "Edge Detection Threshold"; > = 0.10; uniform int MaxSearchSteps < ui_type = "drag"; - ui_min = 0; ui_max = 98; + ui_min = 0; ui_max = 112; ui_label = "Max Search Steps"; ui_tooltip = "Determines the radius SMAA will search for aliased edges."; > = 98; uniform int MaxSearchStepsDiagonal < ui_type = "drag"; - ui_min = 0; ui_max = 16; + ui_min = 0; ui_max = 20; ui_label = "Max Search Steps Diagonal"; ui_tooltip = "Determines the radius SMAA will search for diagonal aliased edges"; > = 16; diff --git a/Shaders/SMAA.fxh b/Shaders/SMAA.fxh index a271b5b7..c76f45d6 100644 --- a/Shaders/SMAA.fxh +++ b/Shaders/SMAA.fxh @@ -792,11 +792,11 @@ float2 SMAAColorEdgeDetectionPS(float2 texcoord, // Calculate left-left and top-top deltas: float3 Cleftleft = SMAASamplePoint(colorTex, offset[2].xy).rgb; - t = abs(C - Cleftleft); + t = abs(Cleft - Cleftleft); delta.z = max(max(t.r, t.g), t.b); float3 Ctoptop = SMAASamplePoint(colorTex, offset[2].zw).rgb; - t = abs(C - Ctoptop); + t = abs(Ctop - Ctoptop); delta.w = max(max(t.r, t.g), t.b); // Calculate the final maximum delta: