-
Notifications
You must be signed in to change notification settings - Fork 16
/
unsharp.fs
40 lines (32 loc) · 1.1 KB
/
unsharp.fs
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
uniform sampler2DRect tex0;
float value0 = 1.0;
float kernel[9];
vec2 offset[9];
void main(void){
vec2 st = gl_TexCoord[0].st;
vec4 sum = vec4(0.0);
offset[0] = vec2(-1.0, -1.0);
offset[1] = vec2(0.0, -1.0);
offset[2] = vec2(1.0, -1.0);
offset[3] = vec2(-1.0, 0.0);
offset[4] = vec2(0.0, 0.0);
offset[5] = vec2(1.0, 0.0);
offset[6] = vec2(-1.0, 1.0);
offset[7] = vec2(0.0, 1.0);
offset[8] = vec2(1.0, 1.0);
kernel[0] = 1.0/16.0; kernel[1] = 2.0/16.0; kernel[2] = 1.0/16.0;
kernel[3] = 2.0/16.0; kernel[4] = 4.0/16.0; kernel[5] = 2.0/16.0;
kernel[6] = 1.0/16.0; kernel[7] = 2.0/16.0; kernel[8] = 1.0/16.0;
int i = 0;
for (i = 0; i < 4; i++){
vec4 tmp = texture2DRect(tex0, st + offset[i]);
sum += tmp * kernel[i];
}
for (i = 5; i < 9; i++){
vec4 tmp = texture2DRect(tex0, st + offset[i]);
sum += tmp * kernel[i];
}
vec4 color0 = texture2DRect(tex0, st + offset[4]);
sum += color0 * kernel[4];
gl_FragColor = (1.0 - value0) * color0 + value0 * vec4(sum.rgb, color0.a);
}