From 521daed91da5df3878fdb806a8df34aca22883bf Mon Sep 17 00:00:00 2001 From: codeanticode Date: Wed, 31 Oct 2012 00:39:05 +0000 Subject: [PATCH] made edges filter compatible with GMA 950 --- .../Topics/Shaders/EdgeDetect/data/edges.glsl | 58 ++++++++----------- .../Topics/Shaders/EdgeFilter/data/edges.glsl | 58 ++++++++----------- 2 files changed, 48 insertions(+), 68 deletions(-) diff --git a/java/examples/Topics/Shaders/EdgeDetect/data/edges.glsl b/java/examples/Topics/Shaders/EdgeDetect/data/edges.glsl index b032743d0..933cf91d9 100644 --- a/java/examples/Topics/Shaders/EdgeDetect/data/edges.glsl +++ b/java/examples/Topics/Shaders/EdgeDetect/data/edges.glsl @@ -9,40 +9,30 @@ uniform vec2 texcoordOffset; varying vec4 vertColor; varying vec4 vertTexcoord; -#define KERNEL_SIZE 9 - -// Edge detection kernel -// -1 -1 -1 -// -1 +8 -1 -// -1 -1 -1 -float kernel[KERNEL_SIZE]; - -vec2 offset[KERNEL_SIZE]; - void main(void) { - int i = 0; - vec4 sum = vec4(0.0); + // Grouping texcoord variables in order to make it work in the GMA 950. See post #13 + // in this thread: + // http://www.idevgames.com/forums/thread-3467.html + vec2 tc0 = vertTexcoord.st + vec2(-texcoordOffset.s, -texcoordOffset.t); + vec2 tc1 = vertTexcoord.st + vec2( 0.0, -texcoordOffset.t); + vec2 tc2 = vertTexcoord.st + vec2(+texcoordOffset.s, -texcoordOffset.t); + vec2 tc3 = vertTexcoord.st + vec2(-texcoordOffset.s, 0.0); + vec2 tc4 = vertTexcoord.st + vec2( 0.0, 0.0); + vec2 tc5 = vertTexcoord.st + vec2(+texcoordOffset.s, 0.0); + vec2 tc6 = vertTexcoord.st + vec2(-texcoordOffset.s, +texcoordOffset.t); + vec2 tc7 = vertTexcoord.st + vec2( 0.0, +texcoordOffset.t); + vec2 tc8 = vertTexcoord.st + vec2(+texcoordOffset.s, +texcoordOffset.t); + + vec4 col0 = texture2D(textureSampler, tc0); + vec4 col1 = texture2D(textureSampler, tc1); + vec4 col2 = texture2D(textureSampler, tc2); + vec4 col3 = texture2D(textureSampler, tc3); + vec4 col4 = texture2D(textureSampler, tc4); + vec4 col5 = texture2D(textureSampler, tc5); + vec4 col6 = texture2D(textureSampler, tc6); + vec4 col7 = texture2D(textureSampler, tc7); + vec4 col8 = texture2D(textureSampler, tc8); - offset[0] = vec2(-texcoordOffset.s, -texcoordOffset.t); - offset[1] = vec2(0.0, -texcoordOffset.t); - offset[2] = vec2(texcoordOffset.s, -texcoordOffset.t); - - offset[3] = vec2(-texcoordOffset.s, 0.0); - offset[4] = vec2(0.0, 0.0); - offset[5] = vec2(texcoordOffset.s, 0.0); - - offset[6] = vec2(-texcoordOffset.s, texcoordOffset.t); - offset[7] = vec2(0.0, texcoordOffset.t); - offset[8] = vec2(texcoordOffset.s, texcoordOffset.t); - - kernel[0] = -1.0; kernel[1] = -1.0; kernel[2] = -1.0; - kernel[3] = -1.0; kernel[4] = 8.0; kernel[5] = -1.0; - kernel[6] = -1.0; kernel[7] = -1.0; kernel[8] = -1.0; - - for(i = 0; i < KERNEL_SIZE; i++) { - vec4 tmp = texture2D(textureSampler, vertTexcoord.st + offset[i]); - sum += tmp * kernel[i]; - } - - gl_FragColor = vec4(sum.rgb, 1.0) * vertColor; + vec4 sum = 8.0 * col4 - (col0 + col1 + col2 + col3 + col5 + col6 + col7 + col8); + gl_FragColor = vec4(sum.rgb, 1.0) * vertColor; } diff --git a/java/examples/Topics/Shaders/EdgeFilter/data/edges.glsl b/java/examples/Topics/Shaders/EdgeFilter/data/edges.glsl index b032743d0..933cf91d9 100644 --- a/java/examples/Topics/Shaders/EdgeFilter/data/edges.glsl +++ b/java/examples/Topics/Shaders/EdgeFilter/data/edges.glsl @@ -9,40 +9,30 @@ uniform vec2 texcoordOffset; varying vec4 vertColor; varying vec4 vertTexcoord; -#define KERNEL_SIZE 9 - -// Edge detection kernel -// -1 -1 -1 -// -1 +8 -1 -// -1 -1 -1 -float kernel[KERNEL_SIZE]; - -vec2 offset[KERNEL_SIZE]; - void main(void) { - int i = 0; - vec4 sum = vec4(0.0); + // Grouping texcoord variables in order to make it work in the GMA 950. See post #13 + // in this thread: + // http://www.idevgames.com/forums/thread-3467.html + vec2 tc0 = vertTexcoord.st + vec2(-texcoordOffset.s, -texcoordOffset.t); + vec2 tc1 = vertTexcoord.st + vec2( 0.0, -texcoordOffset.t); + vec2 tc2 = vertTexcoord.st + vec2(+texcoordOffset.s, -texcoordOffset.t); + vec2 tc3 = vertTexcoord.st + vec2(-texcoordOffset.s, 0.0); + vec2 tc4 = vertTexcoord.st + vec2( 0.0, 0.0); + vec2 tc5 = vertTexcoord.st + vec2(+texcoordOffset.s, 0.0); + vec2 tc6 = vertTexcoord.st + vec2(-texcoordOffset.s, +texcoordOffset.t); + vec2 tc7 = vertTexcoord.st + vec2( 0.0, +texcoordOffset.t); + vec2 tc8 = vertTexcoord.st + vec2(+texcoordOffset.s, +texcoordOffset.t); + + vec4 col0 = texture2D(textureSampler, tc0); + vec4 col1 = texture2D(textureSampler, tc1); + vec4 col2 = texture2D(textureSampler, tc2); + vec4 col3 = texture2D(textureSampler, tc3); + vec4 col4 = texture2D(textureSampler, tc4); + vec4 col5 = texture2D(textureSampler, tc5); + vec4 col6 = texture2D(textureSampler, tc6); + vec4 col7 = texture2D(textureSampler, tc7); + vec4 col8 = texture2D(textureSampler, tc8); - offset[0] = vec2(-texcoordOffset.s, -texcoordOffset.t); - offset[1] = vec2(0.0, -texcoordOffset.t); - offset[2] = vec2(texcoordOffset.s, -texcoordOffset.t); - - offset[3] = vec2(-texcoordOffset.s, 0.0); - offset[4] = vec2(0.0, 0.0); - offset[5] = vec2(texcoordOffset.s, 0.0); - - offset[6] = vec2(-texcoordOffset.s, texcoordOffset.t); - offset[7] = vec2(0.0, texcoordOffset.t); - offset[8] = vec2(texcoordOffset.s, texcoordOffset.t); - - kernel[0] = -1.0; kernel[1] = -1.0; kernel[2] = -1.0; - kernel[3] = -1.0; kernel[4] = 8.0; kernel[5] = -1.0; - kernel[6] = -1.0; kernel[7] = -1.0; kernel[8] = -1.0; - - for(i = 0; i < KERNEL_SIZE; i++) { - vec4 tmp = texture2D(textureSampler, vertTexcoord.st + offset[i]); - sum += tmp * kernel[i]; - } - - gl_FragColor = vec4(sum.rgb, 1.0) * vertColor; + vec4 sum = 8.0 * col4 - (col0 + col1 + col2 + col3 + col5 + col6 + col7 + col8); + gl_FragColor = vec4(sum.rgb, 1.0) * vertColor; }