#line 1 "unknown"

#line 1 "C:\GOG Games\Kenshi\reshade-shaders\Shaders\FilmicAnamorphSharpen.fx"
#line 1 "C:\GOG Games\Kenshi\reshade-shaders\Shaders\ReShadeUI.fxh"
#line 15 "C:\GOG Games\Kenshi\reshade-shaders\Shaders\FilmicAnamorphSharpen.fx"
#line 17
uniform float Strength <      ui_type = "slider"; 
ui_label = "Strength";
ui_min = 0.0; ui_max = 100.0; ui_step = 0.01;
> = 60.0;
#line 22
uniform float Offset <      ui_type = "slider"; 
ui_label = "Radius";
ui_tooltip = "High-pass cross offset in pixels";
ui_min = 0.0; ui_max = 2.0; ui_step = 0.01;
> = 0.1;
#line 28
uniform float Clamp <      ui_type = "slider"; 
ui_label = "Clamping";
ui_min = 0.5; ui_max = 1.0; ui_step = 0.001;
> = 0.65;
#line 33
uniform bool UseMask <       ui_type = "input"; 
ui_label = "Sharpen only center";
ui_tooltip = "Sharpen only in center of the image";
> = false;
#line 38
uniform bool DepthMask <       ui_type = "input"; 
ui_label = "Enable depth rim masking";
ui_tooltip = "Depth high-pass mask switch";
ui_category = "Depth mask";
ui_category_closed = true;
> = false;
#line 45
uniform int DepthMaskContrast <        ui_type = "drag"; 
ui_label = "Edges mask strength";
ui_tooltip = "Depth high-pass mask amount";
ui_category = "Depth mask";
ui_min = 0; ui_max = 2000; ui_step = 1;
> = 128;
#line 52
uniform int Coefficient <        ui_type = "radio"; 
ui_tooltip = "For digital video signal use BT.709, for analog (like VGA) use BT.601";
ui_label = "YUV coefficients";
ui_items = "BT.709 - digital\0BT.601 - analog\0";
ui_category = "Additional settings";
ui_category_closed = true;
> = 0;
#line 60
uniform bool Preview <       ui_type = "input"; 
ui_label = "Preview sharpen layer";
ui_tooltip = "Preview sharpen layer and mask for adjustment.\n"
"If you don't see red strokes,\n"
"try changing Preprocessor Definitions in the Settings tab.";
ui_category = "Debug View";
ui_category_closed = true;
> = false;
#line 1 "C:\GOG Games\Kenshi\reshade-shaders\Shaders\ReShade.fxh"
#line 50
namespace ReShade
{
#line 61
static const float AspectRatio = 1280 * (1.0 / 768);
static const float2 PixelSize = float2((1.0 / 1280), (1.0 / 768));
static const float2 ScreenSize = float2(1280, 768);
#line 67
texture BackBufferTex : COLOR;
texture DepthBufferTex : DEPTH;
#line 70
sampler BackBuffer { Texture = BackBufferTex; };
sampler DepthBuffer { Texture = DepthBufferTex; };
#line 74
float GetLinearizedDepth(float2 texcoord)
{
#line 79
texcoord.x /=  1;
texcoord.y /=  1;
#line 84
texcoord.x -=  0 / 2.000000001;
#line 89
texcoord.y +=  0 / 2.000000001;
#line 91
float depth = tex2Dlod(DepthBuffer, float4(texcoord, 0, 0)).x *  1;
#line 100
const float N = 1.0;
depth /= 1000.0 - depth * (1000.0 - N);
#line 103
return depth;
}
}
#line 108
void PostProcessVS(in uint id : SV_VertexID, out float4 position : SV_Position, out float2 texcoord : TEXCOORD)
{
texcoord.x = (id == 2) ? 2.0 : 0.0;
texcoord.y = (id == 1) ? 2.0 : 0.0;
position = float4(texcoord * float2(2.0, -2.0) + float2(-1.0, 1.0), 0.0, 1.0);
}
#line 74 "C:\GOG Games\Kenshi\reshade-shaders\Shaders\FilmicAnamorphSharpen.fx"
#line 77
static const float3 Luma709 = float3(0.2126, 0.7152, 0.0722);
#line 79
static const float3 Luma601 = float3(0.299, 0.587, 0.114);
#line 82
float Overlay(float LayerA, float LayerB)
{
float MinA = min(LayerA, 0.5);
float MinB = min(LayerB, 0.5);
float MaxA = max(LayerA, 0.5);
float MaxB = max(LayerB, 0.5);
return 2.0 * (MinA * MinB + MaxA + MaxB - MaxA * MaxB) - 1.5;
}
#line 92
float Overlay(float LayerAB)
{
float MinAB = min(LayerAB, 0.5);
float MaxAB = max(LayerAB, 0.5);
return 2.0 * (MinAB * MinAB + MaxAB + MaxAB - MaxAB * MaxAB) - 1.5;
}
#line 100
float3 FilmicAnamorphSharpenPS(float4 pos : SV_Position, float2 UvCoord : TEXCOORD0) : SV_Target
{
#line 103
float3 Source = tex2D(ReShade::BackBuffer, UvCoord).rgb;
#line 106
float Mask;
if (UseMask)
{
#line 110
Mask = 1.0-length(UvCoord*2.0-1.0);
Mask = Overlay(Mask) * Strength;
#line 113
if (Mask <= 0) return Source;
}
else Mask = Strength;
#line 118
float2 Pixel =  float2((1.0 / 1280), (1.0 / 768));
#line 120
const float3 LumaCoefficient = bool(Coefficient) ? Luma601 : Luma709;
#line 122
if (DepthMask)
{
float2 DepthPixel = Pixel*Offset + Pixel;
Pixel *= Offset;
#line 127
float SourceDepth = ReShade::GetLinearizedDepth(UvCoord);
#line 129
float2 NorSouWesEst[4] = {
float2(UvCoord.x, UvCoord.y + Pixel.y),
float2(UvCoord.x, UvCoord.y - Pixel.y),
float2(UvCoord.x + Pixel.x, UvCoord.y),
float2(UvCoord.x - Pixel.x, UvCoord.y)
};
#line 136
float2 DepthNorSouWesEst[4] = {
float2(UvCoord.x, UvCoord.y + DepthPixel.y),
float2(UvCoord.x, UvCoord.y - DepthPixel.y),
float2(UvCoord.x + DepthPixel.x, UvCoord.y),
float2(UvCoord.x - DepthPixel.x, UvCoord.y)
};
#line 145
float HighPassColor = 0.0, DepthMask = 0.0;
#line 147
[unroll]for(int s = 0; s < 4; s++)
{
HighPassColor += dot(tex2D(ReShade::BackBuffer, NorSouWesEst[s]).rgb, LumaCoefficient);
DepthMask += ReShade::GetLinearizedDepth(NorSouWesEst[s])
+ ReShade::GetLinearizedDepth(DepthNorSouWesEst[s]);
}
#line 154
HighPassColor = 0.5 - 0.5 * (HighPassColor * 0.25 - dot(Source, LumaCoefficient));
#line 156
DepthMask = 1.0 - DepthMask * 0.125 + SourceDepth;
DepthMask = min(1.0, DepthMask) + 1.0 - max(1.0, DepthMask);
DepthMask = saturate(DepthMaskContrast * DepthMask + 1.0 - DepthMaskContrast);
#line 161
HighPassColor = lerp(0.5, HighPassColor, Mask * DepthMask);
#line 164
HighPassColor = (Clamp != 1.0) ? max(min(HighPassColor, Clamp), 1.0 - Clamp) : HighPassColor;
#line 166
float3 Sharpen = float3(
Overlay(Source.r, HighPassColor),
Overlay(Source.g, HighPassColor),
Overlay(Source.b, HighPassColor)
);
#line 172
if(Preview) 
{
float PreviewChannel = lerp(HighPassColor, HighPassColor * DepthMask, 0.5);
return float3(
1.0 - DepthMask * (1.0 - HighPassColor),
PreviewChannel,
PreviewChannel
);
}
#line 182
return Sharpen;
}
else
{
Pixel *= Offset;
#line 188
float2 NorSouWesEst[4] = {
float2(UvCoord.x, UvCoord.y + Pixel.y),
float2(UvCoord.x, UvCoord.y - Pixel.y),
float2(UvCoord.x + Pixel.x, UvCoord.y),
float2(UvCoord.x - Pixel.x, UvCoord.y)
};
#line 196
float HighPassColor = 0.0;
[unroll]
for(int s = 0; s < 4; s++)
HighPassColor += dot(tex2D(ReShade::BackBuffer, NorSouWesEst[s]).rgb, LumaCoefficient);
HighPassColor = 0.5 - 0.5 * (HighPassColor * 0.25 - dot(Source, LumaCoefficient));
#line 203
HighPassColor = lerp(0.5, HighPassColor, Mask);
#line 206
HighPassColor = (Clamp != 1.0) ? max(min(HighPassColor, Clamp), 1.0 - Clamp) : HighPassColor;
#line 208
float3 Sharpen = float3(
Overlay(Source.r, HighPassColor),
Overlay(Source.g, HighPassColor),
Overlay(Source.b, HighPassColor)
);
#line 215
return Preview ? HighPassColor : Sharpen;
}
}
#line 224
technique FilmicAnamorphSharpen < ui_label = "Filmic Anamorphic Sharpen"; >
{
pass
{
VertexShader = PostProcessVS;
PixelShader = FilmicAnamorphSharpenPS;
}
}

