#line 1 "unknown"

#line 1 "D:\Games\The Elder Scrolls V Skyrim VR\reshade-shaders\Shaders\CAS.fx"
#line 56
uniform float Contrast <
ui_type = "drag";
ui_label = "Contrast Adaptation";
ui_tooltip = "Adjusts the range the shader adapts to high contrast (0 is not all the way off).  Higher values = more high contrast sharpening.";
ui_min = 0.0; ui_max = 1.0;
> = 0.0;
#line 63
uniform float Sharpening <
ui_type = "drag";
ui_label = "Sharpening intensity";
ui_tooltip = "Adjusts sharpening intensity by averaging the original pixels to the sharpened result.  1.0 is the unmodified default.";
ui_min = 0.0; ui_max = 1.0;
> = 1.0;
#line 1 "D:\Games\The Elder Scrolls V Skyrim VR\reshade-shaders\Shaders\ReShade.fxh"
#line 50
namespace ReShade
{
#line 61
static const float AspectRatio = 3438 * (1.0 / 2053);
static const float2 PixelSize = float2((1.0 / 3438), (1.0 / 2053));
static const float2 ScreenSize = float2(3438, 2053);
#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 70 "D:\Games\The Elder Scrolls V Skyrim VR\reshade-shaders\Shaders\CAS.fx"
#line 73
texture TexColor : COLOR;
sampler sTexColor {Texture = TexColor; SRGBTexture = true;};
#line 76
float3 CASPass(float4 vpos : SV_Position, float2 texcoord : TexCoord) : SV_Target
{
#line 84
float3 b =  tex2D(sTexColor, texcoord, int2(0, -1)).rgb;
float3 d =  tex2D(sTexColor, texcoord, int2(-1, 0)).rgb;
#line 89
float4 red_efhi = tex2DgatherR(sTexColor, texcoord + 0.5 *  float2((1.0 / 3438), (1.0 / 2053)));
#line 91
float3 e = float3( red_efhi.w, red_efhi.w, red_efhi.w);
float3 f = float3( red_efhi.z, red_efhi.z, red_efhi.z);
float3 h = float3( red_efhi.x, red_efhi.x, red_efhi.x);
float3 i = float3( red_efhi.y, red_efhi.y, red_efhi.y);
#line 96
float4 green_efhi = tex2DgatherG(sTexColor, texcoord + 0.5 *  float2((1.0 / 3438), (1.0 / 2053)));
#line 98
e.g = green_efhi.w;
f.g = green_efhi.z;
h.g = green_efhi.x;
i.g = green_efhi.y;
#line 103
float4 blue_efhi = tex2DgatherB(sTexColor, texcoord + 0.5 *  float2((1.0 / 3438), (1.0 / 2053)));
#line 105
e.b = blue_efhi.w;
f.b = blue_efhi.z;
h.b = blue_efhi.x;
i.b = blue_efhi.y;
#line 120
float3 g =  tex2D(sTexColor, texcoord, int2(-1, 1)).rgb;
float3 a =  tex2D(sTexColor, texcoord, int2(-1, -1)).rgb;
float3 c =  tex2D(sTexColor, texcoord, int2(1, -1)).rgb;
#line 130
float3 mnRGB = min(min(min(d, e), min(f, b)), h);
float3 mnRGB2 = min(mnRGB, min(min(a, c), min(g, i)));
mnRGB += mnRGB2;
#line 134
float3 mxRGB = max(max(max(d, e), max(f, b)), h);
float3 mxRGB2 = max(mxRGB, max(max(a, c), max(g, i)));
mxRGB += mxRGB2;
#line 139
float3 rcpMRGB = rcp(mxRGB);
float3 ampRGB = saturate(min(mnRGB, 2.0 - mxRGB) * rcpMRGB);
#line 143
ampRGB = rsqrt(ampRGB);
#line 145
float peak = -3.0 * Contrast + 8.0;
float3 wRGB = -rcp(ampRGB * peak);
#line 148
float3 rcpWeightRGB = rcp(4.0 * wRGB + 1.0);
#line 153
float3 window = (b + d) + (f + h);
float3 outColor = saturate((window * wRGB + e) * rcpWeightRGB);
#line 156
return lerp(e, outColor, Sharpening);
}
#line 159
technique ContrastAdaptiveSharpen
<
ui_label = "AMD FidelityFX Contrast Adaptive Sharpening";
ui_tooltip =
"CAS is a low overhead adaptive sharpening algorithm that AMD includes with their drivers.\n"
"This port to Reshade works with all cards from all vendors,\n"
"but cannot do the optional scaling that CAS is normally also capable of when activated in the AMD drivers.\n"
"\n"
"The algorithm adjusts the amount of sharpening per pixel to target an even level of sharpness across the image.\n"
"Areas of the input image that are already sharp are sharpened less, while areas that lack detail are sharpened more.\n"
"This allows for higher overall natural visual sharpness with fewer artifacts.";
>
{
pass
{
VertexShader = PostProcessVS;
PixelShader = CASPass;
SRGBWriteEnable = true;
}
}

