Accessng neighbouring pixels in OpenGL SL

I am using an OpenGL SL kernel to perform operations on a texture in an Xcode project under OS X. To allow for anisotropic filtering (that is, smoothing without edge loss), I need to access the neighbouring pixels to construct a gradient map.

How does one access neighbouring pixels (above, below, left, and right) in a texture to compare their values with the pixel of interest?

Thanks in advance for any help that may be offered.

-surgin

You can sample your texture with the actual fragment coords + an offset.

I used this code and it worked pretty good :

  
uniform sampler2D map;
const float textureSize = 512.0; // or uniform

void main()
{
    vec2 coord = vec2(gl_TexCoord[0]);
    vec2 offset = vec2(1.0, 0.0) / textureSize;
    vec4 color = texture2D(map, coord + offset);

    ...
}

I used this while playing with post-processing effects. I rendered the scene on a 512x512 texture and map it on a quad in a 512x512 window.
It worked the way i wanted.

I hope this can help you.

  • FenKz

Originally posted by FenKz:
[b]You can sample your texture with the actual fragment coords + an offset.

I used this code and it worked pretty good :

  
uniform sampler2D map;
const float textureSize = 512.0; // or uniform

void main()
{
vec2 coord = vec2(gl_TexCoord[0]);
vec2 offset = vec2(1.0, 0.0) / textureSize;
vec4 color = texture2D(map, coord + offset);

...

}

I used this while playing with post-processing effects. I rendered the scene on a 512x512 texture and map it on a quad in a 512x512 window.
It worked the way i wanted.

I hope this can help you.

  • FenKz[/b]
    I know this should work and is the common way, but my offset needed to be up to 400 or so sometimes if i wanted to see an effct. Could this be because i used mipmapping?

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.