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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
#version 330 core
out vec4 frag_color;
in vec2 tex_coords;
uniform sampler2D texture1;
vec4
inversion()
{
vec4 result = vec4(1.0-vec3(texture(texture1, tex_coords)), 1.0);
return(result);
}
vec4
grayscale_average()
{
vec4 tex_color = texture(texture1, tex_coords);
float average = (tex_color.r+tex_color.g+tex_color.b)/3.0;
vec4 result = vec4(average, average, average, 1.0);
return(result);
}
vec4
grayscale_weights()
{
vec4 tex_color = texture(texture1, tex_coords);
float average = 0.2126*tex_color.r+0.7152*tex_color.g+0.0722*tex_color.b;
vec4 result = vec4(average, average, average, 1.0);
return(result);
}
const float offset = 1.0/300.0;
vec4
kernel_effect(float[9] kernel)
{
vec2 offsets[9] = vec2[](
vec2(-offset, offset), /* top-left */
vec2(0.0, offset), /* top-center */
vec2(offset, offset), /* top-right */
vec2(-offset, 0.0), /* center-left */
vec2(0.0, 0.0), /* center-center */
vec2(offset, 0.0), /* center-right */
vec2(-offset, -offset), /* bottom-left */
vec2(0.0, -offset), /* bottom-center */
vec2(offset, -offset) /* bottom-right */
);
vec3 sample_texture[9];
for (int offset_index = 0;
offset_index < 9;
++offset_index)
{
sample_texture[offset_index] =
vec3(texture(texture1, tex_coords+offsets[offset_index]));
}
vec3 color = vec3(0.0);
for (int i = 0; i < 9; ++i)
color += sample_texture[i]*kernel[i];
return(vec4(color, 1.0));
}
void
main(void)
{
float strange_kernel[9] = float[](
-1, -1, -1,
-1, 9, -1,
-1, -1, -1
);
float gaussian_blur_kernel[9] = float[](
1.0/16.0, 2.0/16.0, 1.0/16.0,
2.0/16.0, 4.0/16.0, 2.0/16.0,
1.0/16.0, 2.0/16.0, 1.0/16.0
);
float box_blur_kernel[9] = float[](
1.0/9.0, 1.0/9.0, 1.0/9.0,
1.0/9.0, 1.0/9.0, 1.0/9.0,
1.0/9.0, 1.0/9.0, 1.0/9.0
);
float edge_detection_kernel[9] = float[](
1.0, 1.0, 1.0,
1.0, -8.0, 1.0,
1.0, 1.0, 1.0
);
float sharpening_kernel[9] = float[](
0.0, -1.0, 0.0,
-1.0, 5.0, -1.0,
0.0, -1.0, 0.0
);
float sobel_kernel_vertical[9] = float[](
-1.0, 0.0, 1.0,
-2.0, 0.0, 2.0,
-1.0, 0.0, 0.0
);
float sobel_kernel_horizontal[9] = float[](
-1.0, -2.0, -1.0,
0.0, 0.0, 0.0,
1.0, 2.0, 1.0
);
float funny_kernel[9] = float[](
1.0, 1.0, 1.0,
1.0, -4.0, 1.0,
1.0, 1.0, 1.0
);
frag_color = kernel_effect(funny_kernel);
frag_color *= vec4(0.76, 0.47, 0.84, 1.0);
}
|