summaryrefslogtreecommitdiffstats
path: root/progs/glsl/convolution.frag
diff options
context:
space:
mode:
authorZack Rusin <[email protected]>2008-05-20 18:49:40 -0400
committerZack Rusin <[email protected]>2008-05-20 18:49:51 -0400
commitcd87aeae00e17e49e258d4d0db6524d808ba7d3f (patch)
tree017ada57bb139d03278dfe76ecb81c0c682db77c /progs/glsl/convolution.frag
parent26f874e967e5bcbd0e0c73674df3d3900b98d35b (diff)
add a simple but nice example of convolution filters in glsl
shows basics of image processing with glsl
Diffstat (limited to 'progs/glsl/convolution.frag')
-rw-r--r--progs/glsl/convolution.frag21
1 files changed, 21 insertions, 0 deletions
diff --git a/progs/glsl/convolution.frag b/progs/glsl/convolution.frag
new file mode 100644
index 00000000000..e49b8acf545
--- /dev/null
+++ b/progs/glsl/convolution.frag
@@ -0,0 +1,21 @@
+
+const int KernelSize = 9;
+
+//texture offsets
+uniform vec2 Offset[KernelSize];
+//convolution kernel
+uniform vec4 KernelValue[KernelSize];
+uniform sampler2D srcTex;
+uniform vec4 ScaleFactor;
+uniform vec4 BaseColor;
+
+void main(void)
+{
+ int i;
+ vec4 sum = vec4(0.0);
+ for (i = 0; i < KernelSize; ++i) {
+ vec4 tmp = texture2D(srcTex, gl_TexCoord[0].st + Offset[i]);
+ sum += tmp * KernelValue[i];
+ }
+ gl_FragColor = sum * ScaleFactor + BaseColor;
+}