ProjectArcade

Форк
0
/
upscale_catmull_rom.fsh 
54 строки · 1.6 Кб
1
// Bicubic (Catmull-Rom) upscaling shader.
2

3
#ifdef GL_ES
4
precision mediump float;
5
precision mediump int;
6
#endif
7

8
uniform sampler2D sampler0;
9
varying vec2 v_position;
10

11
uniform vec2 u_texelDelta;
12
uniform vec2 u_pixelDelta;
13

14
const vec2 HALF_PIXEL = vec2(0.5, 0.5);
15

16
vec3 rgb(int inputX, int inputY)
17
{
18
	return texture2D(sampler0, (vec2(inputX, inputY) + HALF_PIXEL) * u_texelDelta).xyz;
19
}
20

21
// Catmull-Rom coefficients, multiplied by 2.
22
float A(float x) {return x*((2.0-x)*x-1.0);}
23
float B(float x) {return x*x*(3.0*x-5.0)+2.0;}
24
float C(float x) {return x*((4.0-3.0*x)*x+1.0);}
25
float D(float x) {return x*x*(x-1.0);}
26

27
vec3 interpolateHorizontally(vec2 inputPos, ivec2 inputPosFloor, int dy) {
28
	vec3 ret = vec3(0.0);
29
	float x = inputPos.x - float(inputPosFloor.x);
30

31
	ret += A(x) * rgb(inputPosFloor.x - 1, inputPosFloor.y + dy);
32
        ret += B(x) * rgb(inputPosFloor.x    , inputPosFloor.y + dy);
33
        ret += C(x) * rgb(inputPosFloor.x + 1, inputPosFloor.y + dy);
34
        ret += D(x) * rgb(inputPosFloor.x + 2, inputPosFloor.y + dy);
35
	return ret;
36
}
37

38
vec4 process(vec2 outputPos) {
39
	vec2 inputPos = outputPos / u_texelDelta - HALF_PIXEL;
40
	ivec2 inputPosFloor = ivec2(inputPos);
41

42
        vec3 ret = vec3(0.0);
43
	float y = inputPos.y - float(inputPosFloor.y);
44
	ret += A(y) * interpolateHorizontally(inputPos, inputPosFloor, -1);
45
	ret += B(y) * interpolateHorizontally(inputPos, inputPosFloor,  0);
46
	ret += C(y) * interpolateHorizontally(inputPos, inputPosFloor, +1);
47
	ret += D(y) * interpolateHorizontally(inputPos, inputPosFloor, +2);
48
	return vec4(0.25 * ret, 1.0);
49
}
50

51
void main()
52
{
53
        gl_FragColor.rgba = process(v_position);
54
}
55

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

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

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

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