Original Post
I am doing Sobel edge algorithm using OpenGL. The mask is like this: x = ------------- | 1 | 2 | 1 | ------------- | 0 | 0 | 0 | ------------- | -1| -2| -1| ------------- and y= ------------- | 1 | 0 | -1| ------------- | 2 | 0 | 2 | ------------- | 1 | 0 | -1| ------------- Here is my code in GLSL.
uniform sampler2DRect image;
const vec2 offsets[9] = {
vec2(-1,-1),vec2(-1, 0 ),vec2(-1,1),
vec2( 0,-1 ),vec2( 0,0),vec2( 0,1),
vec2( 1,-1),vec2( 1, 0),vec2( 1,1)};
void main(void) {
float result,temp;
float col[9];
int i;
float x,y ;
for(i=0;i<9;i++)
{
col = texture2DRect(image, gl_TexCoord[0].st+offsets).x;
}
x= -col[6]-2*col[7]-col[8]+col[0]+2*col[1]+col[2];
y= -col[0]-2*col[3]-col[6]+col[2]+2*col[5]+col[8];
temp = x*x+y*y;
result = sqrt(temp);
if(result>255)result=255;
gl_FragColor.x = result;
}
However, some unusual lines is printed out on the picture. What's wrong with my piece of code?