ProjectArcade

Форк
0
/
upscale_spline36.fsh 
121 строка · 3.1 Кб
1
// Spline36 upscaling shader.
2
// See issue #3921
3
// Modified as per #15566
4

5
#ifdef GL_ES
6
precision mediump float;
7
precision mediump int;
8
#endif
9

10
uniform sampler2D sampler0;
11
varying vec2 v_position;
12

13
uniform vec2 u_texelDelta;
14
uniform vec2 u_pixelDelta;
15

16
const vec2 HALF_PIXEL = vec2(0.5, 0.5);
17

18
float spline36_0_1(float x) {
19
	return ((13.0 / 11.0 * x - 453.0 / 209.0) * x - 3.0 / 209.0) * x + 1.0;
20
}
21

22
float spline36_1_2(float x) {
23
	return ((-6.0 / 11.0 * x + 612.0 / 209.0) * x - 1038.0 / 209.0) * x + 540.0 / 209.0;
24
}
25

26
float spline36_2_3(float x) {
27
	return ((1.0 / 11.0 * x - 159.0 / 209.0) * x + 434.0 / 209.0) * x - 384.0 / 209.0;
28
}
29

30
vec4 rgb(int inputX, int inputY) {
31
	return texture2D(sampler0, (vec2(inputX, inputY) + HALF_PIXEL) * u_texelDelta);
32
}
33

34
vec4 interpolateHorizontally(vec2 inputPos, ivec2 inputPosFloor, int dy) {
35
	float sumOfWeights = 0.0;
36
	vec4 sumOfWeightedPixel = vec4(0.0);
37

38
	float x;
39
	float weight;
40

41
	x = inputPos.x - float(inputPosFloor.x - 2);
42
	weight = spline36_2_3(x);
43
	sumOfWeights += weight;
44
	sumOfWeightedPixel += weight * rgb(inputPosFloor.x - 2, inputPosFloor.y + dy);
45

46
	--x;
47
	weight = spline36_1_2(x);
48
	sumOfWeights += weight;
49
	sumOfWeightedPixel += weight * rgb(inputPosFloor.x - 1, inputPosFloor.y + dy);
50

51
	--x;
52
	weight = spline36_0_1(x);
53
	sumOfWeights += weight;
54
	sumOfWeightedPixel += weight * rgb(inputPosFloor.x + 0, inputPosFloor.y + dy);
55

56
	x = 1.0 - x;
57
	weight = spline36_0_1(x);
58
	sumOfWeights += weight;
59
	sumOfWeightedPixel += weight * rgb(inputPosFloor.x + 1, inputPosFloor.y + dy);
60

61
	++x;
62
	weight = spline36_1_2(x);
63
	sumOfWeights += weight;
64
	sumOfWeightedPixel += weight * rgb(inputPosFloor.x + 2, inputPosFloor.y + dy);
65

66
	++x;
67
	weight = spline36_2_3(x);
68
	sumOfWeights += weight;
69
	sumOfWeightedPixel += weight * rgb(inputPosFloor.x + 3, inputPosFloor.y + dy);
70

71
	return sumOfWeightedPixel / sumOfWeights;
72
}
73

74
vec4 process(vec2 outputPos) {
75
	vec2 inputPos = outputPos / u_texelDelta - HALF_PIXEL;
76
	ivec2 inputPosFloor = ivec2(inputPos);
77

78
	// Vertical interporation
79
	float sumOfWeights = 0.0;
80
	vec4 sumOfWeightedPixel = vec4(0.0);
81

82
	float weight;
83
	float y;
84

85
	y = inputPos.y - float(inputPosFloor.y - 2);
86
	weight = spline36_2_3(y);
87
	sumOfWeights += weight;
88
	sumOfWeightedPixel += weight * interpolateHorizontally(inputPos, inputPosFloor, -2);
89

90
	--y;
91
	weight = spline36_1_2(y);
92
	sumOfWeights += weight;
93
	sumOfWeightedPixel += weight * interpolateHorizontally(inputPos, inputPosFloor, -1);
94

95
	--y;
96
	weight = spline36_0_1(y);
97
	sumOfWeights += weight;
98
	sumOfWeightedPixel += weight * interpolateHorizontally(inputPos, inputPosFloor, +0);
99

100
	y = 1.0 - y;
101
	weight = spline36_0_1(y);
102
	sumOfWeights += weight;
103
	sumOfWeightedPixel += weight * interpolateHorizontally(inputPos, inputPosFloor, +1);
104

105
	++y;
106
	weight = spline36_1_2(y);
107
	sumOfWeights += weight;
108
	sumOfWeightedPixel += weight * interpolateHorizontally(inputPos, inputPosFloor, +2);
109

110
	++y;
111
	weight = spline36_2_3(y);
112
	sumOfWeights += weight;
113
	sumOfWeightedPixel += weight * interpolateHorizontally(inputPos, inputPosFloor, +3);
114

115
	return vec4((sumOfWeightedPixel / sumOfWeights).xyz, 1.0);
116
}
117

118
void main()
119
{
120
  gl_FragColor.rgba = process(v_position);
121
}
122

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.