/
NLS#.glsl
105 lines (85 loc) · 2.49 KB
/
NLS#.glsl
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// NLS# by NotMithical
// https://github.com/NotMithical/mpv-config/blob/main/Personal/portable_config/shaders/AspectRatio/NLS%23.glsl
//
// --Parameters Summary --
// HorizontalStretch and VerticalStretch:
// Adjust balance between Horizontal and Vertical Stretching. Combined values of each should add up to 1.
// CropAmount:
// Crop image edges. Raising this value results in loss of content but results in less stretching.
// BarsAmount:
// Scale the image down and add padding in the form of black bars. Raising this value results in less stretching.
//
// The defaults will distribute stretching across all edges and will not crop or pad the image.
//!PARAM HorizontalStretch
//!TYPE float
//!MINIMUM 0.0
//!MAXIMUM 1.0
0.5
//!PARAM VerticalStretch
//!TYPE float
//!MINIMUM 0.0
//!MAXIMUM 1.0
0.5
//!PARAM CropAmount
//!TYPE float
//!MINIMUM 0.0
//!MAXIMUM 1.0
0.0
//!PARAM BarsAmount
//!TYPE float
//!MINIMUM 0.0
//!MAXIMUM 1.0
0.0
//!HOOK MAINPRESUB
//!BIND HOOKED
//!DESC Bidirectional Nonlinear Stretch
vec2 stretch(vec2 pos, float h_par, float v_par)
{
float h_m_stretch = pow(h_par, HorizontalStretch),
v_m_stretch = pow(v_par, VerticalStretch),
x = pos.x - 0.5,
y = pos.y - 0.5;
// Check how far each pixel is past the target boundaries
float x_offset = abs(x) - 0.5 + 0.5 / HOOKED_size.x;
float y_offset = abs(y) - 0.5 + 0.5 / HOOKED_size.y;
// Check if each pixel is outside the target boundaries
bool outOfBounds = x_offset > 0.5 || y_offset > 0.5;
//Map x & y coordinates to themselves with a curve, taking into account cropping and padding
if (h_par < 1)
{
return vec2(mix(x * abs(x) * (2 - (CropAmount * 2)), x, h_m_stretch) + 0.5, mix(y * abs(y) * (2 - (BarsAmount * 2)), y, v_m_stretch) + 0.5);
}
else
{
return vec2(mix(x * abs(x) * (2 - (BarsAmount * 2)), x, h_m_stretch) + 0.5, mix(y * abs(y) * (2 - (CropAmount * 2)), y, v_m_stretch) + 0.5);
}
}
vec4 hook()
{
float dar = target_size.x / target_size.y,
sar = HOOKED_size.x / HOOKED_size.y,
h_par = dar / sar,
v_par = sar / dar;
vec2 stretchedPos = stretch(HOOKED_pos, h_par, v_par);
// Check what pixels are outside the target boundaries
bool outOfBounds;
if (any(lessThan(stretchedPos, vec2(0.0))) || any(greaterThan(stretchedPos, vec2(1.0))))
{
outOfBounds = true;
}
else
{
outOfBounds = false;
}
// Black out pixels outside target boundaries
vec4 color;
if (outOfBounds == true)
{
color = vec4(0.0);
}
else
{
color = HOOKED_tex(stretchedPos);
}
return color;
}