ProjectArcade

Форк
0
133 строки · 5.4 Кб
1
/*
2
   Hyllian's 5xBR v3.5a Shader
3
   
4
   Copyright (C) 2011 Hyllian/Jararaca - sergiogdb@gmail.com
5
  
6
   This program is free software; you can redistribute it and/or
7
   modify it under the terms of the GNU General Public License
8
   as published by the Free Software Foundation; either version 2
9
   of the License, or (at your option) any later version.
10

11
   This program is distributed in the hope that it will be useful,
12
   but WITHOUT ANY WARRANTY; without even the implied warranty of
13
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
   GNU General Public License for more details.
15

16
   You should have received a copy of the GNU General Public License
17
   along with this program; if not, write to the Free Software
18
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19
   
20
*/
21
#ifdef GL_ES
22
precision mediump float;
23
precision mediump int;
24
#endif
25

26
uniform sampler2D sampler0;
27
uniform vec2 u_texelDelta;
28
uniform vec2 u_pixelDelta;
29
varying vec2 v_texcoord0;
30

31
const float coef			= 2.0;
32
const vec3  rgbw			= vec3(16.163, 23.351, 8.4772);
33

34
const vec4 Ao = vec4( 1.0, -1.0, -1.0, 1.0 );
35
const vec4 Bo = vec4( 1.0,  1.0, -1.0,-1.0 );
36
const vec4 Co = vec4( 1.5,  0.5, -0.5, 0.5 );
37
const vec4 Ax = vec4( 1.0, -1.0, -1.0, 1.0 );
38
const vec4 Bx = vec4( 0.5,  2.0, -0.5,-2.0 );
39
const vec4 Cx = vec4( 1.0,  1.0, -0.5, 0.0 );
40
const vec4 Ay = vec4( 1.0, -1.0, -1.0, 1.0 );
41
const vec4 By = vec4( 2.0,  0.5, -2.0,-0.5 );
42
const vec4 Cy = vec4( 2.0,  0.0, -1.0, 0.5 );
43

44

45
vec4 df(vec4 A, vec4 B) {
46
	return abs(A-B);
47
}
48

49
vec4 weighted_distance(vec4 a, vec4 b, vec4 c, vec4 d, vec4 e, vec4 f, vec4 g, vec4 h) {
50
	return (df(a,b) + df(a,c) + df(d,e) + df(d,f) + 4.0*df(g,h));
51
}
52

53

54
void main(){
55

56
 bool upscale = u_texelDelta.x > (1.6 * u_pixelDelta.x);
57
 vec3 res = texture2D(sampler0, v_texcoord0.xy).xyz;
58

59
 // Let's skip the whole scaling if output size smaller than 1.6x of input size
60
 if (upscale) {
61

62
	bvec4 edr, edr_left, edr_up, px; // px = pixel, edr = edge detection rule
63
	bvec4 interp_restriction_lv1, interp_restriction_lv2_left, interp_restriction_lv2_up;
64
	bvec4 nc; // new_color
65
	bvec4 fx, fx_left, fx_up; // inequations of straight lines.
66

67
	vec2 pS  = 1.0 / u_texelDelta.xy;
68
	vec2 fp  = fract(v_texcoord0.xy*pS.xy);
69
	vec2 TexCoord_0 = v_texcoord0.xy-fp*u_pixelDelta.xy;
70
	vec2 dx  = vec2(u_texelDelta.x,0.0);
71
	vec2 dy  = vec2(0.0,u_texelDelta.y);
72
	vec2 y2  = dy + dy; vec2 x2  = dx + dx;
73

74
	vec3 A  = texture2D(sampler0, TexCoord_0 -dx -dy	).xyz;
75
	vec3 B  = texture2D(sampler0, TexCoord_0	 -dy	).xyz;
76
	vec3 C  = texture2D(sampler0, TexCoord_0 +dx -dy	).xyz;
77
	vec3 D  = texture2D(sampler0, TexCoord_0 -dx		).xyz;
78
	vec3 E  = texture2D(sampler0, TexCoord_0			).xyz;
79
	vec3 F  = texture2D(sampler0, TexCoord_0 +dx		).xyz;
80
	vec3 G  = texture2D(sampler0, TexCoord_0 -dx +dy	).xyz;
81
	vec3 H  = texture2D(sampler0, TexCoord_0	 +dy	).xyz;
82
	vec3 I  = texture2D(sampler0, TexCoord_0 +dx +dy	).xyz;
83
	vec3 A1 = texture2D(sampler0, TexCoord_0	 -dx -y2).xyz;
84
	vec3 C1 = texture2D(sampler0, TexCoord_0	 +dx -y2).xyz;
85
	vec3 A0 = texture2D(sampler0, TexCoord_0 -x2	 -dy).xyz;
86
	vec3 G0 = texture2D(sampler0, TexCoord_0 -x2	 +dy).xyz;
87
	vec3 C4 = texture2D(sampler0, TexCoord_0 +x2	 -dy).xyz;
88
	vec3 I4 = texture2D(sampler0, TexCoord_0 +x2	 +dy).xyz;
89
	vec3 G5 = texture2D(sampler0, TexCoord_0	 -dx +y2).xyz;
90
	vec3 I5 = texture2D(sampler0, TexCoord_0	 +dx +y2).xyz;
91
	vec3 B1 = texture2D(sampler0, TexCoord_0		 -y2).xyz;
92
	vec3 D0 = texture2D(sampler0, TexCoord_0 -x2		).xyz;
93
	vec3 H5 = texture2D(sampler0, TexCoord_0		 +y2).xyz;
94
	vec3 F4 = texture2D(sampler0, TexCoord_0 +x2		).xyz;
95

96
	vec4 b  = vec4(dot(B ,rgbw), dot(D ,rgbw), dot(H ,rgbw), dot(F ,rgbw));
97
	vec4 c  = vec4(dot(C ,rgbw), dot(A ,rgbw), dot(G ,rgbw), dot(I ,rgbw));
98
	vec4 d  = vec4(b.y, b.z, b.w, b.x);
99
	vec4 e  = vec4(dot(E,rgbw));
100
	vec4 f  = vec4(b.w, b.x, b.y, b.z);
101
	vec4 g  = vec4(c.z, c.w, c.x, c.y);
102
	vec4 h  = vec4(b.z, b.w, b.x, b.y);
103
	vec4 i  = vec4(c.w, c.x, c.y, c.z);
104
	vec4 i4 = vec4(dot(I4,rgbw), dot(C1,rgbw), dot(A0,rgbw), dot(G5,rgbw));
105
	vec4 i5 = vec4(dot(I5,rgbw), dot(C4,rgbw), dot(A1,rgbw), dot(G0,rgbw));
106
	vec4 h5 = vec4(dot(H5,rgbw), dot(F4,rgbw), dot(B1,rgbw), dot(D0,rgbw));
107
	vec4 f4 = vec4(h5.y, h5.z, h5.w, h5.x);
108

109
	// These inequations define the line below which interpolation occurs.
110
	fx	  = greaterThan(Ao*fp.y+Bo*fp.x,Co); 
111
	fx_left = greaterThan(Ax*fp.y+Bx*fp.x,Cx);
112
	fx_up   = greaterThan(Ay*fp.y+By*fp.x,Cy);
113

114
	interp_restriction_lv1	  = bvec4(vec4(notEqual(e,f))*vec4(notEqual(e,h)));
115
	interp_restriction_lv2_left = bvec4(vec4(notEqual(e,g))*vec4(notEqual(d,g)));
116
	interp_restriction_lv2_up   = bvec4(vec4(notEqual(e,c))*vec4(notEqual(b,c)));
117

118
	edr	  = bvec4(vec4(lessThan(weighted_distance( e, c, g, i, h5, f4, h, f), weighted_distance( h, d, i5, f, i4, b, e, i)))*vec4(interp_restriction_lv1));
119
	edr_left = bvec4(vec4(lessThanEqual(coef*df(f,g),df(h,c)))*vec4(interp_restriction_lv2_left)); 
120
	edr_up   = bvec4(vec4(greaterThanEqual(df(f,g),coef*df(h,c)))*vec4(interp_restriction_lv2_up));
121

122
	nc.x = ( edr.x && (fx.x || edr_left.x && fx_left.x || edr_up.x && fx_up.x) );
123
	nc.y = ( edr.y && (fx.y || edr_left.y && fx_left.y || edr_up.y && fx_up.y) );
124
	nc.z = ( edr.z && (fx.z || edr_left.z && fx_left.z || edr_up.z && fx_up.z) );
125
	nc.w = ( edr.w && (fx.w || edr_left.w && fx_left.w || edr_up.w && fx_up.w) );	
126

127
	px = lessThanEqual(df(e,f),df(e,h));
128

129
	res = nc.x ? px.x ? F : H : nc.y ? px.y ? B : F : nc.z ? px.z ? D : B : nc.w ? px.w ? H : D : E;	
130
 }
131
	gl_FragColor.rgb = res;
132
	gl_FragColor.a = 1.0;
133
}
134

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

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

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

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