Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions Shaders/AdaptiveSharpen.fx
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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) )
Expand All @@ -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 )
Expand All @@ -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]));
Expand Down Expand Up @@ -170,21 +170,21 @@ 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 ]
// [ d19, d10, d4, d0, d5, d11, d16 ]
// [ 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),
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand All @@ -387,7 +387,7 @@ technique AdaptiveSharpen
{
VertexShader = PostProcessVS;
PixelShader = AdaptiveSharpenP0;
RenderTarget = Pass0Tex;
RenderTarget = AS_Pass0Tex;
}

pass AdaptiveSharpenPass2
Expand Down
8 changes: 4 additions & 4 deletions Shaders/Colourfulness.fx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;

Expand Down
67 changes: 43 additions & 24 deletions Shaders/FXAA.fx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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
Expand All @@ -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"

Expand All @@ -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)));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use the square of the color?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The lightness/luma weights should be multiplied with the color in linear light to be correct. It can be done in gamma light with some error but the speed difference is negligible.

Before, color was decoded with sRGB gamma and then encoded in the alpha channel with 1/2.0 gamma, resulting in slight error in lightness. Now its decoded with 2.0 gamma and encoded with 1/2.0 gamma.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah. I see. Didn't realize the change in the line right above.

return color;
}
#endif

float4 FXAAPixelShader(float4 vpos : SV_Position, noperspective float2 texcoord : TEXCOORD) : SV_Target
Expand All @@ -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
}
}
6 changes: 3 additions & 3 deletions Shaders/SMAA.fx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions Shaders/SMAA.fxh
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what this change does. It reduces the distance between the two samples the delta is calculated of, but why?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if it helps but this is the commit for that particular change with explanation. :)
iryoku/smaa#11

Copy link
Contributor Author

@bacondither bacondither Sep 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Under luma edge detection the Calculate left-left and top-top deltas are computed with left & leftleft and top & toptop pixels ( line 730 ). But for the Color Edge Detection it uses the center pixel instead of the left and top one.

Both ways cant be correct! Im not so sure anymore which one is correct, perhaps I should send a mail to Jorge Jimenez and ask politely.

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:
Expand Down