Wednesday 15 August 2012

glsl - Unnecessary grid lines in sobel filter Opengl ES -



glsl - Unnecessary grid lines in sobel filter Opengl ES -

my aim create sobel filter in opengl es. using netbeans ide. working fine in debug mode in release mode getting grid lines. code running on raspberry pi.

can help me rid of these lines?

this fragment shader code.

varying vec2 tcoord; uniform sampler2d tex; uniform vec2 texelsize; void main(void) { vec4 tm1m1 = texture2d(tex,tcoord+vec2(-1,-1)*texelsize); vec4 tm10 = texture2d(tex,tcoord+vec2(-1,0)*texelsize); vec4 tm1p1 = texture2d(tex,tcoord+vec2(-1,1)*texelsize); vec4 tp1m1 = texture2d(tex,tcoord+vec2(1,-1)*texelsize); vec4 tp10 = texture2d(tex,tcoord+vec2(1,0)*texelsize); vec4 tp1p1 = texture2d(tex,tcoord+vec2(1,1)*texelsize); vec4 t0m1 = texture2d(tex,tcoord+vec2(0,-1)*texelsize); vec4 t0p1 = texture2d(tex,tcoord+vec2(0,-1)*texelsize); vec4 xdiff = -1.0*tm1m1 + -2.0*tm10 + -1.0*tm1p1 + 1.0*tp1m1 + 2.0*tp10 + 1.0*tp1p1; vec4 ydiff = -1.0*tm1m1 + -2.0*t0m1 + -1.0*tp1m1 + 1.0*tm1p1 + 2.0*t0p1 + 1.0*tp1p1; vec4 tot = sqrt((xdiff*xdiff)+(ydiff*ydiff)); vec4 col = tot; col.a = 1.0; gl_fragcolor = clamp(col,vec4(0),vec4(1)); }

this debug image.

release image.

this partial answer. did notice wrong sign in shader:

vec4 t0m1 = texture2d(tex,tcoord+vec2(0,-1)*texelsize); vec4 t0p1 = texture2d(tex,tcoord+vec2(0,-1)*texelsize);

those 2 same value. next pattern of other values, should be:

vec4 t0m1 = texture2d(tex,tcoord+vec2(0,-1)*texelsize); vec4 t0p1 = texture2d(tex,tcoord+vec2(0,1)*texelsize);

i don't believe explain grid lines, though. should improve quality of result.

opengl-es glsl opengl-es-2.0 raspberry-pi

No comments:

Post a Comment