Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: Accessng neighbouring pixels in OpenGL SL

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2004
    Posts
    3

    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

  2. #2
    Junior Member Newbie
    Join Date
    Jul 2004
    Location
    Belfort - France
    Posts
    6

    Re: Accessng neighbouring pixels in OpenGL SL

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

    I used this code and it worked pretty good :
    Code :
    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

  3. #3
    Intern Newbie
    Join Date
    Jul 2004
    Location
    Germany
    Posts
    33

    Re: Accessng neighbouring pixels in OpenGL SL

    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 :
    Code :
    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
    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?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •