#line 1 "unknown"

#line 1 "D:\Games\The Elder Scrolls V Skyrim VR\reshade-shaders\Shaders\PerfectPerspective.fx"
#line 1 "D:\Games\The Elder Scrolls V Skyrim VR\reshade-shaders\Shaders\ReShadeUI.fxh"
#line 28 "D:\Games\The Elder Scrolls V Skyrim VR\reshade-shaders\Shaders\PerfectPerspective.fx"
#line 30
uniform int FOV <        ui_type = "slider"; 
ui_label = "Game field of view";
ui_tooltip = "This setting should match your in-game FOV (in degrees)";
#line 36
ui_min = 0; ui_max = 170;
ui_category = "Field of View";
> = 90;
#line 40
uniform int Type <        ui_type = "combo"; 
ui_label = "Type of FOV";
ui_tooltip = "...in stereographic mode\n"
"If image bulges in movement (too high FOV),\n"
"change it to 'Diagonal'.\n"
"When proportions are distorted at the periphery\n"
"(too low FOV), choose 'Vertical' or '4:3'.\n"
"\nAdjust so that round objects are still round \n"
"in the corners, and not oblong.\n"
"\n*This method works only in 'navigation' preset,\n"
"or k=0.5 on manual.";
ui_items =
"Horizontal FOV\0"
"Diagonal FOV\0"
"Vertical FOV\0"
"4:3 FOV\0";
ui_category = "Field of View";
> = 0;
#line 59
uniform int Projection <        ui_type = "radio"; 
ui_label = "Type of perspective";
ui_text = "Select game style";
ui_tooltip =
"Choose type of perspective, according to game-play style.\n"
"For manual perspective adjustment, select last option.";
ui_items =
"Navigation\0"
"Aiming\0"
"Feel of distance\0"
"manual adjustment *\0";
ui_category = "Perspective";
ui_category_closed = true;
ui_spacing = 1;
> = 0;
#line 75
uniform float K <      ui_type = "slider"; 
ui_label = "K (manual perspective) *";
ui_tooltip =
"K 1.0 ....Rectilinear projection (standard), preserves straight lines,"
" but doesn't preserve proportions, angles or scale.\n"
"K 0.5 ....Stereographic projection (navigation, shape) preserves angles and proportions,"
" best for navigation through tight spaces.\n"
"K 0 ......Equidistant (aiming) maintains angular speed of motion,"
" best for aiming at fast targets.\n"
"K -0.5 ...Equisolid projection (distance) preserves area relation,"
" best for navigation in open space.\n"
"K -1.0 ...Orthographic projection preserves planar luminance,"
" has extreme radial compression. Found in peephole viewer.";
ui_min = -1.0; ui_max = 1.0;
ui_category = "Perspective";
> = 1.0;
#line 92
uniform float Vertical <      ui_type = "slider"; 
ui_label = "Vertical distortion";
ui_tooltip = "Cylindrical perspective <<>> Spherical perspective";
ui_min = 0.001; ui_max = 1.0;
ui_category = "Perspective";
ui_text = "Global settings";
> = 1.0;
#line 100
uniform float VerticalScale <      ui_type = "slider"; 
ui_label = "Vertical proportions";
ui_tooltip = "Adjust anamorphic correction for cylindrical perspective";
ui_min = 0.8; ui_max = 1.0;
ui_category = "Perspective";
> = 0.95;
#line 107
uniform float Zooming <      ui_type = "drag"; 
ui_label = "Border scale";
ui_tooltip = "Adjust image scale and cropped area";
ui_min = 0.5; ui_max = 2.0; ui_step = 0.001;
ui_category = "Border";
ui_category_closed = true;
> = 1.0;
#line 115
uniform float BorderCorner <      ui_type = "slider"; 
ui_label = "Corner roundness";
ui_tooltip = "Represents corners curvature\n0.0 gives sharp corners";
ui_min = 1.0; ui_max = 0.0;
ui_category = "Border";
> = 0.062;
#line 122
uniform float4 BorderColor <      ui_type = "color"; 
ui_label = "Border color";
ui_tooltip = "Use Alpha to change transparency";
ui_category = "Border";
> = float4(0.027, 0.027, 0.027, 0.784);
#line 128
uniform bool MirrorBorder <       ui_type = "input"; 
ui_label = "Mirrored border";
ui_tooltip = "Choose original or mirrored image at the border";
ui_category = "Border";
> = true;
#line 134
uniform bool DebugPreview <       ui_type = "input"; 
ui_label = "Resolution scale map";
ui_tooltip = "Color map of the Resolution Scale:\n"
" Red   - under-sampling\n"
" Green - super-sampling\n"
" Blue  - neutral sampling";
ui_category = "Tools for debugging";
ui_category_closed = true;
ui_spacing = 2;
> = false;
#line 145
uniform int2 ResScale <        ui_type = "input"; 
ui_label = "Difference";
ui_text = "screen resolution  |  virtual, super resolution";
ui_tooltip = "Simulates application running beyond\n"
"native screen resolution (using VSR or DSR)";
ui_type = "drag";
ui_min = 16; ui_max = 16384; ui_step = 0.2;
ui_category = "Tools for debugging";
> = int2(1920, 1920);
#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 = 1608 * (1.0 / 960);
static const float2 PixelSize = float2((1.0 / 1608), (1.0 / 960));
static const float2 ScreenSize = float2(1608, 960);
#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 156 "D:\Games\The Elder Scrolls V Skyrim VR\reshade-shaders\Shaders\PerfectPerspective.fx"
#line 159
sampler SamplerColor
{
Texture = ReShade::BackBufferTex;
AddressU = MIRROR;
AddressV = MIRROR;
};
#line 172
float grayscale(float3 Color)
{ return max(max(Color.r, Color.g), Color.b); }
#line 175
float sq(float input)
{ return input*input; }
#line 178
float linearstep(float x)
{ return clamp(x/fwidth(x), 0.0, 1.0); }
#line 191
float univPerspective(float k, float l, float2 coord)
{
#line 194
if (k >= 1.0 || FOV == 0)
return 1.0;
#line 197
float R = (l == 1.0) ?
length(coord) : 
sqrt(sq(coord.x) + sq(coord.y)*l); 
#line 201
const float omega = radians(FOV*0.5);
#line 203
float theta;
if (k>0.0)
theta = atan(R*tan(k*omega))/k;
else if (k<0.0)
theta = asin(R*sin(k*omega))/k;
else 
theta = R*omega;
#line 211
const float tanOmega = tan(omega);
return tan(theta)/(tanOmega*R);
}
#line 221
float3 PerfectPerspectivePS(float4 pos : SV_Position, float2 texCoord : TEXCOORD) : SV_Target
{
#line 224
const float aspectRatioInv = 1.0 /  (1608 * (1.0 / 960));
#line 227
float FovType; switch(Type)
{
case 0: FovType = 1.0; break; 
case 1: FovType = sqrt(sq(aspectRatioInv) + 1.0); break; 
case 2: FovType = aspectRatioInv; break; 
case 3: FovType = 4.0/3.0*aspectRatioInv; break; 
}
#line 236
float2 sphCoord = texCoord*2.0 -1.0;
#line 238
sphCoord.y *= aspectRatioInv;
#line 241
sphCoord *= clamp(Zooming, 0.5, 2.0) / FovType; 
#line 244
float k; switch (Projection)
{
case 0: k = 0.5; break;		
case 1: k = 0.0; break;		
case 2: k = -0.5; break;	
default: k = clamp(K, -1.0, 1.0); break; 
}
#line 252
sphCoord *= univPerspective(k, Vertical, sphCoord) * FovType;
#line 255
sphCoord.y *=  (1608 * (1.0 / 960));
#line 258
if(VerticalScale != 1.0 && Vertical != 1.0)
sphCoord.y /= lerp(VerticalScale, 1.0, Vertical);
#line 262
float borderMask;
if (BorderCorner == 0.0) 
borderMask = linearstep( max(abs(sphCoord.x), abs(sphCoord.y)) -1.0 );
else 
{
#line 268
float2 borderCoord = abs(sphCoord);
#line 270
if (ReShade::AspectRatio > 1.0) 
borderCoord.x = borderCoord.x*ReShade::AspectRatio + 1.0-ReShade::AspectRatio;
else if (ReShade::AspectRatio < 1.0) 
borderCoord.y = borderCoord.y*aspectRatioInv + 1.0-aspectRatioInv;
#line 276
borderMask = length(max(borderCoord +BorderCorner -1.0, 0.0)) /BorderCorner;
borderMask = linearstep( borderMask-1.0 );
}
#line 281
sphCoord = sphCoord*0.5 +0.5;
#line 284
float3 display = tex2D(SamplerColor, sphCoord).rgb;
#line 287
display = lerp(
display,
lerp(
MirrorBorder ? display : tex2D(SamplerColor, texCoord).rgb,
BorderColor.rgb,
BorderColor.a
),
borderMask
);
#line 298
if(DebugPreview)
{
#line 301
float4 radialCoord = float4(texCoord, sphCoord) * 2.0 - 1.0;
#line 303
radialCoord.yw *= aspectRatioInv;
#line 306
const float3 underSmpl = float3(1.0, 0.0, 0.2); 
const float3 superSmpl = float3(0.0, 1.0, 0.5); 
const float3 neutralSmpl = float3(0.0, 0.5, 1.0); 
#line 311
float pixelScaleMap = fwidth( length(radialCoord.xy) );
#line 313
pixelScaleMap *= ResScale.x / (fwidth( length(radialCoord.zw) ) * ResScale.y);
pixelScaleMap -= 1.0;
#line 317
float3 resMap = lerp(
superSmpl,
underSmpl,
step(0.0, pixelScaleMap)
);
#line 324
pixelScaleMap = 1.0 - abs(pixelScaleMap);
pixelScaleMap = saturate(pixelScaleMap * 4.0 - 3.0); 
#line 328
resMap = lerp(resMap, neutralSmpl, pixelScaleMap);
#line 331
display = normalize(resMap) * (0.8 * grayscale(display) + 0.2);
}
#line 334
return display;
}
#line 342
technique PerfectPerspective
<
ui_label = "Perfect Perspective";
ui_tooltip = "Adjust perspective for distortion-free picture\n"
"(fish-eye, panini shader)";
>
{
pass
{
VertexShader = PostProcessVS;
PixelShader = PerfectPerspectivePS;
}
}

