Skip to main content
GameDev.net gamedev.net
🔒 Locked

Problem on GLSL code(image processing)

Started by rosicky2005 Jan 4, 2007 at 8:00 PM 0 replies 2.6k views
Original Post
rosicky2005
rosicky2005
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?
Lopez
Lopez
You're offsetting your tex coords by a full texture size.

You need to offset by say offset_value/texture_size to get the correct offset.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.