forked from crosire/reshade-shaders
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAspectRatio.fx
89 lines (71 loc) · 1.72 KB
/
AspectRatio.fx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/** Aspect Ratio PS, version 1.0.2
by Fubax 2019 for ReShade
*/
#include "ReShadeUI.fxh"
uniform float A < __UNIFORM_SLIDER_FLOAT1
ui_label = "Correct proportions";
ui_category = "Aspect ratio";
ui_min = -1.0; ui_max = 1.0;
> = 0.0;
uniform float Zoom < __UNIFORM_SLIDER_FLOAT1
ui_label = "Scale image";
ui_category = "Aspect ratio";
ui_min = 1.0; ui_max = 1.5;
> = 1.0;
uniform bool FitScreen < __UNIFORM_INPUT_BOOL1
ui_label = "Scale image to borders";
ui_category = "Borders";
> = true;
uniform float3 Color < __UNIFORM_COLOR_FLOAT3
ui_label = "Background color";
ui_category = "Borders";
> = float3(0.027, 0.027, 0.027);
#include "ReShade.fxh"
//////////////
/// SHADER ///
//////////////
float3 AspectRatioPS(float4 pos : SV_Position, float2 coord : TEXCOORD0) : SV_Target
{
bool Mask = false;
// Center coordinates
coord -= 0.5;
// if (Zoom != 1.0) coord /= Zoom;
if (Zoom != 1.0) coord /= clamp(Zoom, 1.0, 1.5); // Anti-cheat
// Squeeze horizontally
if (A<0)
{
coord.x *= abs(A)+1.0; // Apply distortion
// Scale to borders
if (FitScreen) coord /= abs(A)+1.0;
else // Mask image borders
Mask = abs(coord.x)>0.5;
}
// Squeeze vertically
else if (A>0)
{
coord.y *= A+1.0; // Apply distortion
// Scale to borders
if (FitScreen) coord /= abs(A)+1.0;
else // Mask image borders
Mask = abs(coord.y)>0.5;
}
// Coordinates back to the corner
coord += 0.5;
// Sample display image and return
return Mask? Color : tex2D(ReShade::BackBuffer, coord).rgb;
}
///////////////
/// DISPLAY ///
///////////////
technique AspectRatioPS
<
ui_label = "Aspect Ratio";
ui_tooltip = "Correct image aspect ratio";
>
{
pass
{
VertexShader = PostProcessVS;
PixelShader = AspectRatioPS;
}
}