forked from jdgleaver/ppsspp_shaders
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathupscale_spline36.fsh
More file actions
120 lines (92 loc) · 3.03 KB
/
upscale_spline36.fsh
File metadata and controls
120 lines (92 loc) · 3.03 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// Spline36 upscaling shader.
// See issue #3921
#ifdef GL_ES
precision mediump float;
precision mediump int;
#endif
uniform sampler2D sampler0;
varying vec2 v_position;
uniform vec2 u_texelDelta;
uniform vec2 u_pixelDelta;
const vec2 HALF_PIXEL = vec2(0.5, 0.5);
float spline36_0_1(float x) {
return ((13.0 / 11.0 * x - 453.0 / 209.0) * x - 3.0 / 209.0) * x + 1.0;
}
float spline36_1_2(float x) {
return ((-6.0 / 11.0 * x + 612.0 / 209.0) * x - 1038.0 / 209.0) * x + 540.0 / 209.0;
}
float spline36_2_3(float x) {
return ((1.0 / 11.0 * x - 159.0 / 209.0) * x + 434.0 / 209.0) * x - 384.0 / 209.0;
}
vec4 rgb(int inputX, int inputY) {
return texture2D(sampler0, (vec2(inputX, inputY) + HALF_PIXEL) * u_texelDelta);
}
vec4 interpolateHorizontally(vec2 inputPos, ivec2 inputPosFloor, int dy) {
float sumOfWeights = 0.0;
vec4 sumOfWeightedPixel = vec4(0.0);
float x;
float weight;
x = inputPos.x - float(inputPosFloor.x - 2);
weight = spline36_2_3(x);
sumOfWeights += weight;
sumOfWeightedPixel += weight * rgb(inputPosFloor.x - 2, inputPosFloor.y + dy);
--x;
weight = spline36_1_2(x);
sumOfWeights += weight;
sumOfWeightedPixel += weight * rgb(inputPosFloor.x - 1, inputPosFloor.y + dy);
--x;
weight = spline36_0_1(x);
sumOfWeights += weight;
sumOfWeightedPixel += weight * rgb(inputPosFloor.x + 0, inputPosFloor.y + dy);
x = 1.0 - x;
weight = spline36_0_1(x);
sumOfWeights += weight;
sumOfWeightedPixel += weight * rgb(inputPosFloor.x + 1, inputPosFloor.y + dy);
++x;
weight = spline36_1_2(x);
sumOfWeights += weight;
sumOfWeightedPixel += weight * rgb(inputPosFloor.x + 2, inputPosFloor.y + dy);
++x;
weight = spline36_2_3(x);
sumOfWeights += weight;
sumOfWeightedPixel += weight * rgb(inputPosFloor.x + 3, inputPosFloor.y + dy);
return sumOfWeightedPixel / sumOfWeights;
}
vec4 process(vec2 outputPos) {
vec2 inputPos = outputPos / u_texelDelta;
ivec2 inputPosFloor = ivec2(inputPos);
// Vertical interporation
float sumOfWeights = 0.0;
vec4 sumOfWeightedPixel = vec4(0.0);
float weight;
float y;
y = inputPos.y - float(inputPosFloor.y - 2);
weight = spline36_2_3(y);
sumOfWeights += weight;
sumOfWeightedPixel += weight * interpolateHorizontally(inputPos, inputPosFloor, -2);
--y;
weight = spline36_1_2(y);
sumOfWeights += weight;
sumOfWeightedPixel += weight * interpolateHorizontally(inputPos, inputPosFloor, -1);
--y;
weight = spline36_0_1(y);
sumOfWeights += weight;
sumOfWeightedPixel += weight * interpolateHorizontally(inputPos, inputPosFloor, +0);
y = 1.0 - y;
weight = spline36_0_1(y);
sumOfWeights += weight;
sumOfWeightedPixel += weight * interpolateHorizontally(inputPos, inputPosFloor, +1);
++y;
weight = spline36_1_2(y);
sumOfWeights += weight;
sumOfWeightedPixel += weight * interpolateHorizontally(inputPos, inputPosFloor, +2);
++y;
weight = spline36_2_3(y);
sumOfWeights += weight;
sumOfWeightedPixel += weight * interpolateHorizontally(inputPos, inputPosFloor, +3);
return vec4((sumOfWeightedPixel / sumOfWeights).xyz, 1.0);
}
void main()
{
gl_FragColor.rgba = process(v_position);
}