Re: Tricky question on shader

Almar Klein <[email protected]>
Newsgroups gmane.comp.python.opengl.user
Message-ID <CAB_T6=nXzhadJcpELxeO7AJLYpwOvYJ0ft6KpOmJX=yYVKghcg@mail.gmail.com>
Hi,


> I've been playing with gaussian texture filtering using shaders and I
> obtained a strange "grid" effect on a completely uniform texture. Since all
> fragments get the same processing and same neighbouring values,I wonder if
> the grid is the result of some kind of artifact with floating points or the
> way texture coordinates are interpolated. Or I missed something completely
> obvious…
>

The Gaussian kernel is in theory infinite. Of course you need to cut it off
somewhere, but you should normalize the kernel such that its sum is 1.0. I'm
guessing that the fact that your kernel is asymetric does not help either.

The code below fixes the pattern:

 vec4

filter( float x, vec4 c0, vec4 c1, vec4 c2, vec4 c3 )

{

float w;

 w = gaussian(x+1.0); // h.x;

float w_sum = w;

vec4 r = c0 * w;

 w = gaussian(x+0.0); // h.y;

w_sum += w;

r += c1 * w;

 w = gaussian(1.0-x); // h.z;

w_sum += w;

r += c2 * w;

 w = gaussian(2.0-x); // h.w;

w_sum += w;

r += c3 * w;

 return r/w_sum;

}


Also a suggestion. I'm doing something similar in visvis to anti-alias 2D
images. I also use a vec4 to represent the kernel, but I make use of the
fact that the Gaussian kernel is symetric: kernel[0] is the center element,
and kernel[1] to kernel[3] are the 3 elements on each side of the center.
This way I get a kernel of effectively 7 elements. Further, I calculate (and
normalize) the kernel beforehand in Python, and pass it as a uniform vec4.
This way, it does not have to be calculated for each pixel. I'm not sure how
significant this is for the speed, but there is a costly exp call in there
...

Regards,
  Almar

------------------------------------------------------------------------------
Special Offer -- Download ArcSight Logger for FREE!
Finally, a world-class log management solution at an even better 
price-free! And you'll get a free "Love Thy Logs" t-shirt when you
download Logger. Secure your free ArcSight Logger TODAY!
http://p.sf.net/sfu/arcsisghtdev2dev

_______________________________________________
PyOpenGL Homepage
http://pyopengl.sourceforge.net
_______________________________________________
PyOpenGL-Users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pyopengl-users
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.