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
|
uniform sampler2D ColorMap;
vec4 convolve3x3(vec4 IN,
float W00, float W01, float W02,
float W10, float W11, float W12,
float W20, float W21, float W22,
float Sum,
float step_w,
float step_h)
{
int i = 0;
vec4 C = vec4(0.0);
float kernel[9];
vec2 offset[9];
offset[0] = vec2(-step_w, -step_h);
offset[1] = vec2(0.0, -step_h);
offset[2] = vec2(step_w, -step_h);
offset[3] = vec2(-step_w, 0.0);
offset[4] = vec2(0.0, 0.0);
offset[5] = vec2(step_w, 0.0);
offset[6] = vec2(-step_w, step_h);
offset[7] = vec2(0.0, step_h);
offset[8] = vec2(step_w, step_h);
kernel[0] = W00; kernel[1] = W01; kernel[2] = W02;
kernel[3] = W10; kernel[4] = W11; kernel[5] = W12;
kernel[6] = W20; kernel[7] = W21; kernel[8] = W22;
for( i=0; i < 9; i++){
vec4 tmp = texture2D(ColorMap, IN.st + offset[i]);
C += tmp * (kernel[i]/Sum);
}
return C;
}
//texture size
uniform float width;
uniform float height;
void main(){
gl_FragColor = convolve3x3(gl_TexCoord[0],
1.0, 1.0, 2.0,
1.0, 4.0, 3.0,
2.0, 3.0, 3.0,
16.0,
1.0/width,
1.0/height);
}
|