summaryrefslogtreecommitdiff
path: root/ext/gl/effects/gstgleffectssources.c
blob: 6bdc155861f8e08afca8bbdc80e0712507b751ad (plain)
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
/*
 * GStreamer
 * Copyright (C) 2008 Filippo Argiolas <filippo.argiolas@gmail.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

#if HAVE_CONFIG_H
#include "config.h"
#endif

#include <gst/gl/gstglconfig.h>

#include "../gstgleffects.h"
#include "gstgleffectssources.h"
#include <math.h>

/* A common file for sources is needed since shader sources can be
 * generic and reused by several effects */

/* FIXME */
/* Move sooner or later into single .frag .vert files and either bake
 * them into a c file at compile time or load them at run time */


/* fill a normalized and zero centered gaussian vector for separable
 * gaussian convolution */

void
fill_gaussian_kernel (float *kernel, int size, float sigma)
{
  int i;
  float sum;
  int l;

  /* need an odd sized vector to center it at zero */
  g_return_if_fail ((size % 2) != 0);

  sum = 0.0;
  l = (size - 1) / 2;

  for (i = 0; i < size; i++) {
    kernel[i] = expf (-0.5 * pow ((i - l) / sigma, 2.0));
    sum += kernel[i];
  }

  for (i = 0; i < size; i++) {
    kernel[i] /= sum;
  }
}

/* *INDENT-OFF* */

/* Mirror effect */
const gchar *mirror_fragment_source_opengl =
  "uniform sampler2D tex;"
  "void main () {"
  "  vec2 texturecoord = gl_TexCoord[0].xy;"
  "  vec2 normcoord;"
  "  normcoord = texturecoord - 0.5;"
  "  normcoord.x *= sign (normcoord.x);"
  "  texturecoord = normcoord + 0.5;"
  "  vec4 color = texture2D (tex, texturecoord);"
  "  gl_FragColor = color * gl_Color;"
  "}";

const gchar *mirror_fragment_source_gles2 =
  "#ifdef GL_ES\n"
  "precision mediump float;\n"
  "#endif\n"
  "varying vec2 v_texcoord;"
  "uniform sampler2D tex;"
  "void main () {"
  "  vec2 texturecoord = v_texcoord.xy;"
  "  float normcoord = texturecoord.x - 0.5;"
  "  normcoord *= sign (normcoord);"
  "  texturecoord.x = normcoord + 0.5;"
  "  gl_FragColor = texture2D (tex, texturecoord);"
  "}";

const gchar *squeeze_fragment_source_gles2 =
  "#ifdef GL_ES\n"
  "precision mediump float;\n"
  "#endif\n"
  "varying vec2 v_texcoord;"
  "uniform sampler2D tex;"
  "void main () {"
  "  vec2 texturecoord = v_texcoord.xy;"
  "  vec2 normcoord = texturecoord - 0.5;"
  "  float r = length (normcoord);"
  "  r = pow(r, 0.40)*1.3;"
  "  normcoord = normcoord / r;"
  "  texturecoord = (normcoord + 0.5);"
  "  gl_FragColor = texture2D (tex, texturecoord);"
  "}";

const gchar *stretch_fragment_source_gles2 =
  "#ifdef GL_ES\n"
  "precision mediump float;\n"
  "#endif\n"
  "varying vec2 v_texcoord;"
  "uniform sampler2D tex;"
  "void main () {"
	"  vec2 texturecoord = v_texcoord.xy;"
  "  vec2 normcoord;"
  "  normcoord = texturecoord - 0.5;"
  "  float r = length (normcoord);"
  "  normcoord *= 2.0 - smoothstep(0.0, 0.35, r);"
  "  texturecoord = normcoord + 0.5;"
  "  gl_FragColor = texture2D (tex, texturecoord);"
  "}";

const gchar *tunnel_fragment_source_gles2 =
  "#ifdef GL_ES\n"
  "precision mediump float;\n"
  "#endif\n"
  "varying vec2 v_texcoord;"
  "uniform sampler2D tex;"
  "void main () {"
  "  vec2 texturecoord = v_texcoord.xy;"
  "  vec2 normcoord;"
  /* little trick with normalized coords to obtain a circle with
   * rect textures */
  "  normcoord = (texturecoord - 0.5);"
  "  float r = length(normcoord);"
  "  normcoord *= clamp (r, 0.0, 0.275) / r;"
  "  texturecoord = normcoord + 0.5;"
  "  gl_FragColor = texture2D (tex, texturecoord);"
  "}";

const gchar *fisheye_fragment_source_gles2 =
  "#ifdef GL_ES\n"
  "precision mediump float;\n"
  "#endif\n"
  "varying vec2 v_texcoord;"
  "uniform sampler2D tex;"
  "void main () {"
  "  vec2 texturecoord = v_texcoord.xy;"
  "  vec2 normcoord;"
  "  normcoord = texturecoord - 0.5;"
  "  float r = length (normcoord);"
  "  normcoord *= r * 1.41421;" /* sqrt (2) */
  "  texturecoord = normcoord + 0.5;"
  "  gl_FragColor = texture2D (tex, texturecoord);"
  "}";

const gchar *twirl_fragment_source_gles2 =
  "#ifdef GL_ES\n"
  "precision mediump float;\n"
  "#endif\n"
  "varying vec2 v_texcoord;"
	"uniform sampler2D tex;"
  "void main () {"
  "  vec2 texturecoord = v_texcoord.xy;"
  "  vec2 normcoord;"
  "  normcoord = texturecoord - 0.5;"
  "  float r = length (normcoord);"
  /* calculate rotation angle: maximum (about pi/2) at the origin and
   * gradually decrease it up to 0.6 of each quadrant */
  "  float phi = (1.0 - smoothstep (0.0, 0.3, r)) * 1.6;"
  /* precalculate sin phi and cos phi, save some alu */
  "  float s = sin(phi);"
  "  float c = cos(phi);"
  /* rotate */
  "  normcoord *= mat2(c, s, -s, c);"
  "  texturecoord = normcoord + 0.5;"
  "  gl_FragColor = texture2D (tex, texturecoord);"
  "}";

const gchar *bulge_fragment_source_gles2 =
  "#ifdef GL_ES\n"
  "precision mediump float;\n"
  "#endif\n"
  "varying vec2 v_texcoord;"
  "uniform sampler2D tex;"
  "void main () {"
  "  vec2 texturecoord = v_texcoord.xy;"
  "  vec2 normcoord;"
  "  normcoord = texturecoord - 0.5;"
  "  float r =  length (normcoord);"
  "  normcoord *= smoothstep (-0.05, 0.25, r);"
  "  texturecoord = normcoord + 0.5;"
  "  gl_FragColor = texture2D (tex, texturecoord);"
  "}";

const gchar *square_fragment_source_gles2 =
  "#ifdef GL_ES\n"
  "precision mediump float;\n"
  "#endif\n"
  "varying vec2 v_texcoord;"
  "uniform sampler2D tex;"
  "void main () {"
  "  vec2 texturecoord = v_texcoord.xy;"
  "  vec2 normcoord;"
  "  normcoord = texturecoord - 0.5;"
  "  float r = length (normcoord);"
  "  normcoord *= 1.0 + smoothstep(0.125, 0.25, abs(normcoord));"
  "  normcoord /= 2.0; /* zoom amount */"
  "  texturecoord = normcoord + 0.5;"
  "  gl_FragColor = texture2D (tex, texturecoord);"
  "}";

const gchar *luma_threshold_fragment_source_gles2 =
  "#ifdef GL_ES\n"
  "precision mediump float;\n"
  "#endif\n"
  "varying vec2 v_texcoord;"
  "uniform sampler2D tex;"
  "void main () {"
  "  vec2 texturecoord = v_texcoord.xy;"
  "  vec4 color = texture2D(tex, texturecoord);"
  "  float luma = dot(color.rgb, vec3(0.2125, 0.7154, 0.0721));"    /* BT.709 (from orange book) */
  "  gl_FragColor = vec4 (vec3 (smoothstep (0.30, 0.50, luma)), color.a);"
  "}";

const gchar *sep_sobel_length_fragment_source_gles2 =
  "#ifdef GL_ES\n"
  "precision mediump float;\n"
  "#endif\n"
  "varying vec2 v_texcoord;"
  "uniform sampler2D tex;"
  "uniform bool invert;"
  "void main () {"
  "  vec4 g = texture2D (tex, v_texcoord.xy);"
  /* restore black background with grey edges */
  "  g -= vec4(0.5, 0.5, 0.0, 0.0);"
  "  float len = length (g);"
  /* little trick to avoid IF operator */
  /* TODO: test if a standalone inverting pass is worth */
  "  gl_FragColor = abs(vec4(vec3(float(invert) - len), 1.0));"
  "}";

const gchar *desaturate_fragment_source_gles2 =
  "#ifdef GL_ES\n"
  "precision mediump float;\n"
  "#endif\n"
  "varying vec2 v_texcoord;"
  "uniform sampler2D tex;"
  "void main () {"
  "  vec4 color = texture2D (tex, v_texcoord.xy);"
  "  float luma = dot(color.rgb, vec3(0.2125, 0.7154, 0.0721));"
  "  gl_FragColor = vec4(vec3(luma), color.a);"
  "}";

const gchar *sep_sobel_hconv3_fragment_source_gles2 =
  "#ifdef GL_ES\n"
  "precision mediump float;\n"
  "#endif\n"
  "varying vec2 v_texcoord;"
  "uniform sampler2D tex;"
  "uniform float width;"
  "void main () {"
  "  float w = 1.0 / width;"
  "  vec2 texturecoord[3];"
  "  texturecoord[1] = v_texcoord.xy;"
  "  texturecoord[0] = texturecoord[1] - vec2(w, 0.0);"
  "  texturecoord[2] = texturecoord[1] + vec2(w, 0.0);"
  "  float grad_kern[3];"
  "  grad_kern[0] = 1.0;"
  "  grad_kern[1] = 0.0;"
  "  grad_kern[2] = -1.0;"
  "  float blur_kern[3];"
  "  blur_kern[0] = 0.25;"
  "  blur_kern[1] = 0.5;"
  "  blur_kern[2] = 0.25;"
  "  int i;"
  "  vec4 sum = vec4 (0.0);"
  "  for (i = 0; i < 3; i++) { "
  "    vec4 neighbor = texture2D(tex, texturecoord[i]); "
  "    sum.r = neighbor.r * blur_kern[i] + sum.r;"
  "    sum.g = neighbor.g * grad_kern[i] + sum.g;"
  "  }"
  "  gl_FragColor = sum + vec4(0.0, 0.5, 0.0, 0.0);"
  "}";

const gchar *sep_sobel_vconv3_fragment_source_gles2 =
  "#ifdef GL_ES\n"
  "precision mediump float;\n"
  "#endif\n"
  "varying vec2 v_texcoord;"
  "uniform sampler2D tex;"
  "uniform float height;"
  "void main () {"
  "  float h = 1.0 / height;"
  "  vec2 texturecoord[3];"
  "  texturecoord[1] = v_texcoord.xy;"
  "  texturecoord[0] = texturecoord[1] - vec2(0.0, h);"
  "  texturecoord[2] = texturecoord[1] + vec2(0.0, h);"
  "  float grad_kern[3];"
  "  grad_kern[0] = 1.0;"
  "  grad_kern[1] = 0.0;"
  "  grad_kern[2] = -1.0;"
  "  float blur_kern[3];"
  "  blur_kern[0] = 0.25;"
  "  blur_kern[1] = 0.5;"
  "  blur_kern[2] = 0.25;"
  "  int i;"
  "  vec4 sum = vec4 (0.0);"
  "  for (i = 0; i < 3; i++) { "
  "    vec4 neighbor = texture2D(tex, texturecoord[i]); "
  "    sum.r = neighbor.r * grad_kern[i] + sum.r;"
  "    sum.g = neighbor.g * blur_kern[i] + sum.g;"
  "  }"
  "  gl_FragColor = sum + vec4(0.5, 0.0, 0.0, 0.0);"
  "}";

const gchar *hconv7_fragment_source_gles2 =
  "#ifdef GL_ES\n"
  "precision mediump float;\n"
  "#endif\n"
  "varying vec2 v_texcoord;"
  "uniform sampler2D tex;"
  "uniform float kernel[7];"
  "uniform float gauss_width;"
  "void main () {"
  "  float w = 1.0 / gauss_width;"
  "  vec2 texturecoord[7];"
  "  texturecoord[3] = v_texcoord.xy;"
  "  texturecoord[2] = texturecoord[3] - vec2(w, 0.0);"
  "  texturecoord[1] = texturecoord[2] - vec2(w, 0.0);"
  "  texturecoord[0] = texturecoord[1] - vec2(w, 0.0);"
  "  texturecoord[4] = texturecoord[3] + vec2(w, 0.0);"
  "  texturecoord[5] = texturecoord[4] + vec2(w, 0.0);"
  "  texturecoord[6] = texturecoord[5] + vec2(w, 0.0);"
  "  int i;"
  "  vec4 sum = vec4 (0.0);"
  "  for (i = 0; i < 7; i++) { "
  "    vec4 neighbor = texture2D(tex, texturecoord[i]); "
  "    sum += neighbor * kernel[i];"
  "  }"
  "  gl_FragColor = sum;"
  "}";

/* vertical convolution 7x7 */
const gchar *vconv7_fragment_source_gles2 =
  "#ifdef GL_ES\n"
  "precision mediump float;\n"
  "#endif\n"
  "varying vec2 v_texcoord;"
  "uniform sampler2D tex;"
  "uniform float kernel[7];"
  "uniform float gauss_height;"
  "void main () {"
  "  float h = 1.0 / gauss_height;"
  "  vec2 texturecoord[7];"
  "  texturecoord[3] = v_texcoord.xy;"
  "  texturecoord[2] = texturecoord[3] - vec2(0.0, h);"
  "  texturecoord[1] = texturecoord[2] - vec2(0.0, h);"
  "  texturecoord[0] = texturecoord[1] - vec2(0.0, h);"
  "  texturecoord[4] = texturecoord[3] + vec2(0.0, h);"
  "  texturecoord[5] = texturecoord[4] + vec2(0.0, h);"
  "  texturecoord[6] = texturecoord[5] + vec2(0.0, h);"
  "  int i;"
  "  vec4 sum = vec4 (0.0);"
  "  for (i = 0; i < 7; i++) { "
  "    vec4 neighbor = texture2D(tex, texturecoord[i]);"
  "    sum += neighbor * kernel[i];"
  "  }"
  "  gl_FragColor = sum;"
  "}";

/* TODO: support several blend modes */
const gchar *sum_fragment_source_gles2 =
  "#ifdef GL_ES\n"
  "precision mediump float;\n"
  "#endif\n"
  "varying vec2 v_texcoord;"
  "uniform sampler2D base;"
  "uniform sampler2D blend;"
  "uniform float alpha;"
  "uniform float beta;"
  "void main () {"
  "  vec4 basecolor = texture2D (base, v_texcoord.xy);"
  "  vec4 blendcolor = texture2D (blend, v_texcoord.xy);"
  "  gl_FragColor = alpha * basecolor + beta * blendcolor;"
  "}";

const gchar *multiply_fragment_source_gles2 =
  "#ifdef GL_ES\n"
  "precision mediump float;\n"
  "#endif\n"
  "varying vec2 v_texcoord;"
  "uniform sampler2D base;"
  "uniform sampler2D blend;"
  "uniform float alpha;"
  "void main () {"
  "  vec4 basecolor = texture2D (base, v_texcoord.xy);"
  "  vec4 blendcolor = texture2D (blend, v_texcoord.xy);"
  "  gl_FragColor = (1.0 - alpha) * basecolor + alpha * basecolor * blendcolor;"
  "}";

/* lut operations, map luma to tex1d, see orange book (chapter 19) */
const gchar *luma_to_curve_fragment_source_gles2 =
  "#ifdef GL_ES\n"
  "precision mediump float;\n"
  "#endif\n"
  "varying vec2 v_texcoord;"
  "uniform sampler2D tex;"
  "uniform sampler2D curve;"
  "void main () {"
  "  vec2 texturecoord = v_texcoord.xy;"
  "  vec4 color = texture2D (tex, texturecoord);"
  "  float luma = dot(color.rgb, vec3(0.2125, 0.7154, 0.0721));"
  "  color = texture2D (curve, vec2(luma, 0.0));"
  "  gl_FragColor = color;"
  "}";

/* lut operations, map rgb to tex1d, see orange book (chapter 19) */
const gchar *rgb_to_curve_fragment_source_gles2 =
  "#ifdef GL_ES\n"
  "precision mediump float;\n"
  "#endif\n"
  "varying vec2 v_texcoord;"
  "uniform sampler2D tex;"
  "uniform sampler2D curve;"
  "void main () {"
  "  vec4 color = texture2D (tex, v_texcoord.xy);"
  "  vec4 outcolor;"
  "  outcolor.r = texture2D (curve, vec2(color.r, 0.0)).r;"
  "  outcolor.g = texture2D (curve, vec2(color.g, 0.0)).g;"
  "  outcolor.b = texture2D (curve, vec2(color.b, 0.0)).b;"
  "  outcolor.a = color.a;"
  "  gl_FragColor = outcolor;"
  "}";

const gchar *sin_fragment_source_gles2 =
  "#ifdef GL_ES\n"
  "precision mediump float;\n"
  "#endif\n"
  "varying vec2 v_texcoord;"
  "uniform sampler2D tex;"
  "void main () {"
  "  vec4 color = texture2D (tex, vec2(v_texcoord.xy));"
  "  float luma = dot(color.rgb, vec3(0.2125, 0.7154, 0.0721));"
/* calculate hue with the Preucil formula */
  "  float cosh = color.r - 0.5*(color.g + color.b);"
/* sqrt(3)/2 = 0.866 */
  "  float sinh = 0.866*(color.g - color.b);"
/* hue = atan2 h */
  "  float sch = (1.0-sinh)*cosh;"
/* ok this is a little trick I came up because I didn't find any
 * detailed proof of the Preucil formula. The issue is that tan(h) is
 * pi-periodic so the smoothstep thing gives both reds (h = 0) and
 * cyans (h = 180). I don't want to use atan since it requires
 * branching and doesn't work on i915. So take only the right half of
 * the circle where cosine is positive */
/* take a slightly purple color trying to get rid of human skin reds */
/* tanh = +-1.0 for h = +-45, where yellow=60, magenta=-60 */
  "  float a = smoothstep (0.3, 1.0, sch);"
  "  float b = smoothstep (-0.4, -0.1, sinh);"
  "  float mix = a * b;"
  "  gl_FragColor = color * mix + luma * (1.0 - mix);"
  "}";

const gchar *interpolate_fragment_source =
  "uniform sampler2D base;"
  "uniform sampler2D blend;"
  "void main () {"
  "vec4 basecolor = texture2D (base, gl_TexCoord[0].st);"
  "vec4 blendcolor = texture2D (blend, gl_TexCoord[0].st);"
  "vec4 white = vec4(1.0);"
  "gl_FragColor = blendcolor + (1.0 - blendcolor.a) * basecolor;"
  "}";

const gchar *texture_interp_fragment_source =
  "uniform sampler2D base;"
  "uniform sampler2D blend;"
  "uniform sampler2D alpha;"
  "void main () {"
  "  vec4 basecolor = texture2D (base, gl_TexCoord[0].st);"
  "  vec4 blendcolor = texture2D (blend, gl_TexCoord[0].st);"
  "  vec4 alphacolor = texture2D (alpha, gl_TexCoord[0].st);"
  "  gl_FragColor = (alphacolor * blendcolor) + (1.0 - alphacolor) * basecolor;"
  "}";

const gchar *difference_fragment_source =
  "uniform sampler2D saved;"
  "uniform sampler2D current;"
  "void main () {"
  "vec4 savedcolor = texture2D (saved, gl_TexCoord[0].st);"
  "vec4 currentcolor = texture2D (current, gl_TexCoord[0].st);"
  "gl_FragColor = vec4 (step (0.12, length (savedcolor - currentcolor)));"
  "}";

/* This filter is meant as a demo of gst-plugins-gl + glsl
   capabilities. So I'm keeping this shader readable enough. If and
   when this shader will be used in production be careful to hard code
   kernel into the shader and remove unneeded zero multiplications in
   the convolution */
const gchar *conv9_fragment_source_gles2 =
  "#ifdef GL_ES\n"
  "precision mediump float;\n"
  "#endif\n"
  "varying vec2 v_texcoord;"
  "uniform sampler2D tex;"
  "uniform float kernel[9];"
  "uniform float width, height;"
  "uniform bool invert;"
  "void main () {"
  "  float w = 1.0 / width;"
  "  float h = 1.0 / height;"
  "  vec2 texturecoord[9];"
  "  texturecoord[4] = v_texcoord.xy;"                    /*  0  0 */
  "  texturecoord[5] = texturecoord[4] + vec2(w,   0.0);" /*  1  0 */
  "  texturecoord[2] = texturecoord[5] - vec2(0.0, h);"   /*  1 -1 */
  "  texturecoord[1] = texturecoord[2] - vec2(w,   0.0);" /*  0 -1 */
  "  texturecoord[0] = texturecoord[1] - vec2(w,   0.0);" /* -1 -1 */
  "  texturecoord[3] = texturecoord[0] + vec2(0.0, h);"   /* -1  0 */
  "  texturecoord[6] = texturecoord[3] + vec2(0.0, h);"   /* -1  1 */
  "  texturecoord[7] = texturecoord[6] + vec2(w,   0.0);" /*  0  1 */
  "  texturecoord[8] = texturecoord[7] + vec2(w,   0.0);" /*  1  1 */
  "  int i;"
  "  vec3 sum = vec3 (0.0);"
  "  for (i = 0; i < 9; i++) { "
  "    vec4 neighbor = texture2D (tex, texturecoord[i]);"
  "    sum += neighbor.xyz * kernel[i];"
  "  }"
  "  gl_FragColor = vec4 (abs(sum - vec3(float(invert))), 1.0);"
  "}";

/* *INDENT-ON* */