View Full Version : Accessng neighbouring pixels in OpenGL SL
surgin
07-26-2004, 07:19 AM
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
FenKz
07-26-2004, 10:45 AM
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
splat
07-26-2004, 11:50 PM
Originally posted by FenKz:
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.
- FenKzI 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?
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.