#line 1 "unknown"

#line 1 "D:\Games\The Elder Scrolls V Skyrim VR\reshade-shaders\Shaders\CRT.fx"
#line 1 "D:\Games\The Elder Scrolls V Skyrim VR\reshade-shaders\Shaders\ReShadeUI.fxh"
#line 13 "D:\Games\The Elder Scrolls V Skyrim VR\reshade-shaders\Shaders\CRT.fx"
#line 15
uniform float Amount <      ui_type = "slider"; 
ui_min = 0.0; ui_max = 1.0;
ui_tooltip = "Amount of CRT effect you want";
> = 1.00;
uniform float Resolution <      ui_type = "slider"; 
ui_min = 1.0; ui_max = 8.0;
ui_tooltip = "Input size coefficient (low values gives the 'low - res retro look').";
> = 1.15;
uniform float Gamma <      ui_type = "slider"; 
ui_min = 0.0; ui_max = 4.0;
ui_tooltip = "Gamma of simulated CRT";
> = 2.4;
uniform float MonitorGamma <      ui_type = "slider"; 
ui_min = 0.0; ui_max = 4.0;
ui_tooltip = "Gamma of display monitor";
> = 2.2;
uniform float Brightness <      ui_type = "slider"; 
ui_min = 0.0; ui_max = 3.0;
ui_tooltip = "Used to boost brightness a little.";
> = 0.9;
#line 36
uniform int ScanlineIntensity <        ui_type = "slider"; 
ui_min = 2; ui_max = 4;
ui_label = "Scanline Intensity";
> = 2;
uniform bool ScanlineGaussian <
ui_label = "Scanline Bloom Effect";
ui_tooltip = "Use the new nongaussian scanlines bloom effect.";
> = true;
#line 45
uniform bool Curvature <
ui_tooltip = "Barrel effect";
> = false;
uniform float CurvatureRadius <      ui_type = "slider"; 
ui_min = 0.0; ui_max = 2.0;
ui_label = "Curvature Radius";
> = 1.5;
uniform float CornerSize <      ui_type = "slider"; 
ui_min = 0.00; ui_max = 0.02; ui_step = 0.001;
ui_label = "Corner Size";
ui_tooltip = "Higher values => more rounded corner";
> = 0.0100;
uniform float ViewerDistance <      ui_type = "slider"; 
ui_min = 0.0; ui_max = 4.0;
ui_Label = "Viewer Distance";
ui_tooltip = "Simulated distance from viewer to monitor";
> = 2.00;
uniform float2 Angle <      ui_type = "slider"; 
ui_min = -0.2; ui_max = 0.2;
ui_tooltip = "Tilt angle in radians";
> = 0.00;
#line 67
uniform float Overscan <      ui_type = "slider"; 
ui_min = 1.0; ui_max = 1.10; ui_step = 0.01;
ui_tooltip = "Overscan (e.g. 1.02 for 2% overscan).";
> = 1.01;
uniform bool Oversample <
ui_tooltip = "Enable 3x oversampling of the beam profile (warning : performance hit)";
> = true;
#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 = 3020 * (1.0 / 1804);
static const float2 PixelSize = float2((1.0 / 3020), (1.0 / 1804));
static const float2 ScreenSize = float2(3020, 1804);
#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 75 "D:\Games\The Elder Scrolls V Skyrim VR\reshade-shaders\Shaders\CRT.fx"
#line 102
float intersect(float2 xy)
{
float A = dot(xy,xy) + (ViewerDistance * ViewerDistance);
float B = 2.0 * (CurvatureRadius * (dot(xy,  sin(Angle)) - ViewerDistance *  cos(Angle).x *  cos(Angle).y) - ViewerDistance * ViewerDistance);
float C = ViewerDistance * ViewerDistance + 2.0 * CurvatureRadius * ViewerDistance *  cos(Angle).x *  cos(Angle).y; 
return (-B - sqrt(B * B -4.0 * A * C)) / (2.0 * A);
}
#line 110
float2 bkwtrans(float2 xy)
{
float c = intersect(xy);
float2 _point = float2(c, c) * xy;
_point -= float2(-CurvatureRadius, -CurvatureRadius) *  sin(Angle);
_point /= float2(CurvatureRadius, CurvatureRadius);
float2 tang =  sin(Angle) /  cos(Angle);
float2 poc = _point /  cos(Angle);
float A = dot(tang, tang) + 1.0;
float B = -2.0 * dot(poc, tang);
float C = dot(poc, poc) - 1.0;
float a = (-B + sqrt(B * B -4.0 * A * C)) / (2.0 * A);
float2 uv = (_point - a *  sin(Angle)) /  cos(Angle);
float r = CurvatureRadius * acos(a);
return uv * r / sin(r / CurvatureRadius);
}
float2 fwtrans(float2 uv)
{
float r =  max(abs(sqrt(dot(uv, uv))), 1e-5);;
uv *= sin(r / CurvatureRadius) / r;
float x = 1.0 - cos(r / CurvatureRadius);
float D = ViewerDistance / CurvatureRadius + x *  cos(Angle).x *  cos(Angle).y + dot(uv,  sin(Angle));
return ViewerDistance * (uv *  cos(Angle) - x *  sin(Angle)) / D;
}
#line 135
float3 maxscale()
{
float2 c = bkwtrans(-CurvatureRadius *  sin(Angle) / (1.0 + CurvatureRadius / ViewerDistance *  cos(Angle).x *  cos(Angle).y));
float2 a = float2(0.5, 0.5) *  float2(1.0, 0.75);
float2 lo = float2(fwtrans(float2(-a.x, c.y)).x, fwtrans(float2(c.x,-a.y)).y) /  float2(1.0, 0.75);
float2 hi = float2(fwtrans(float2(+a.x, c.y)).x, fwtrans(float2(c.x, +a.y)).y) /  float2(1.0, 0.75);
return float3((hi + lo) *  float2(1.0, 0.75) * 0.5, max(hi.x - lo.x, hi.y - lo.y));
}
#line 144
float2 transform(float2 coord, float2 textureSize, float2 inputSize)
{
coord *= textureSize / inputSize;
coord = (coord - 0.5) *  float2(1.0, 0.75) *  maxscale().z +  maxscale().xy;
return (bkwtrans(coord) / float2(Overscan, Overscan) /  float2(1.0, 0.75) + 0.5) * inputSize / textureSize;
}
#line 151
float corner(float2 coord, float2 textureSize, float2 inputSize)
{
coord *= textureSize / inputSize;
coord = (coord - 0.5) * float2(Overscan, Overscan) + 0.5;
coord = min(coord, 1.0 - coord) *  float2(1.0, 0.75);
float2 cdist = float2(CornerSize, CornerSize);
coord = (cdist - min(coord, cdist));
float dist = sqrt(dot(coord, coord));
return clamp((cdist.x-dist) * 1000.0, 0.0, 1.0);
}
#line 168
float4 scanlineWeights(float distance, float4 color)
{
#line 180
if (!ScanlineGaussian)
{
float4 wid = 0.3 + 0.1 * pow(abs(color), 3.0);
float4 weights = float4(distance / wid);
return 0.4 * exp(-weights * weights) / wid;
}
else
{
float4 wid = 2.0 * pow(abs(color), 4.0) + 2.0;
float4 weights = (distance / 0.3).xxxx;
return 1.4 * exp(-pow(abs(weights * rsqrt(0.5 * wid)), abs(wid))) / (0.2 * wid + 0.6);
}
}
#line 194
float3 AdvancedCRTPass(float4 position : SV_Position, float2 tex : TEXCOORD) : SV_Target
{
#line 217
float  Input_ratio = ceil(256 * Resolution);
float2 Resolution = float2(Input_ratio, Input_ratio);
float2 rubyTextureSize = Resolution;
float2 rubyInputSize = Resolution;
float2 rubyOutputSize =  float2(3020, 1804);
#line 223
float2 orig_xy = Curvature ? transform(tex, rubyTextureSize, rubyInputSize) : tex;
float cval = corner(orig_xy, rubyTextureSize, rubyInputSize);
#line 228
float2 ratio_scale = orig_xy * rubyTextureSize - 0.5;
#line 230
float filter = fwidth(ratio_scale.y);
float2 uv_ratio = frac(ratio_scale);
#line 234
float2 xy = (floor(ratio_scale) + 0.5) / rubyTextureSize;
#line 239
float4 coeffs =  3.1415927 * float4(1.0 + uv_ratio.x, uv_ratio.x, 1.0 - uv_ratio.x, 2.0 - uv_ratio.x);
#line 242
coeffs =  max(abs(coeffs), 1e-5);;
#line 245
coeffs = 2.0 * sin(coeffs) * sin(coeffs / 2.0) / (coeffs * coeffs);
#line 248
coeffs /= dot(coeffs, 1.0);
#line 253
float4 col  = clamp(mul(coeffs, float4x4(
 tex2D(ReShade::BackBuffer, (xy + float2(- 1.0 / rubyTextureSize.x, 0.0))),
 tex2D(ReShade::BackBuffer, (xy)),
 tex2D(ReShade::BackBuffer, (xy + float2( 1.0 / rubyTextureSize.x, 0.0))),
 tex2D(ReShade::BackBuffer, (xy + float2(2.0 *  1.0 / rubyTextureSize.x, 0.0))))),
0.0, 1.0);
float4 col2 = clamp(mul(coeffs, float4x4(
 tex2D(ReShade::BackBuffer, (xy + float2(- 1.0 / rubyTextureSize.x,  1.0 / rubyTextureSize.y))),
 tex2D(ReShade::BackBuffer, (xy + float2(0.0,  1.0 / rubyTextureSize.y))),
 tex2D(ReShade::BackBuffer, (xy +  1.0 / rubyTextureSize)),
 tex2D(ReShade::BackBuffer, (xy + float2(2.0 *  1.0 / rubyTextureSize.x,  1.0 / rubyTextureSize.y))))),
0.0, 1.0);
#line 267
col  = pow(abs(col) , Gamma);
col2 = pow(abs(col2), Gamma);
#line 273
float4 weights  = scanlineWeights(uv_ratio.y, col);
float4 weights2 = scanlineWeights(1.0 - uv_ratio.y, col2);
#line 279
if (Oversample)
{
uv_ratio.y = uv_ratio.y + 1.0 / 3.0 * filter;
weights = (weights + scanlineWeights(uv_ratio.y, col)) / 3.0;
weights2 = (weights2 + scanlineWeights(abs(1.0 - uv_ratio.y), col2)) / 3.0;
uv_ratio.y = uv_ratio.y - 2.0 / 3.0 * filter;
weights = weights + scanlineWeights(abs(uv_ratio.y), col) / 3.0;
weights2 = weights2 + scanlineWeights(abs(1.0 - uv_ratio.y), col2) / 3.0;
}
#line 289
float3 mul_res = (col * weights + col2 * weights2).rgb * cval.xxx;
#line 293
float3 dotMaskWeights = lerp(float3(1.0, 0.7, 1.0), float3(0.7, 1.0, 0.7), floor( tex.x * rubyTextureSize.x * rubyOutputSize.x / rubyInputSize.x % ScanlineIntensity));
mul_res *= dotMaskWeights * float3(0.83, 0.83, 1.0) * Brightness;
#line 297
mul_res = pow(abs(mul_res), 1.0 / MonitorGamma);
#line 299
float3 color =  tex2D(ReShade::BackBuffer, (orig_xy)).rgb * cval.xxx;
color = lerp(color, mul_res, Amount);
#line 302
return saturate(color);
}
#line 305
technique AdvancedCRT
{
pass
{
VertexShader = PostProcessVS;
PixelShader = AdvancedCRTPass;
}
}

