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: accessing neighbouring fragments

  1. #1
    Intern Contributor
    Join Date
    Apr 2007
    Posts
    61

    accessing neighbouring fragments

    Hi,All
    I noticed that people use the following code to access the neighboring fragment in fragment shader:
    "
    .....
    float step_w = 1.0/ width; // width is the texture width
    float step_h = 1.0/ height;
    vec2 offset = vec2(-step_w, -step_h);
    vec4 tmp = texture2D(myTexture, gl_TexCoord[0].st + offset);
    .....
    "
    my question is, what is going to happen when (gl_TexCoord[0].st + offset).x < 0.0 ?. Does opengl automatically set it as 0.0? or we have to manually handle the "boundary" case?

    tks

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Apr 2004
    Posts
    999

    Re: accessing neighbouring fragments

    That depends on the texture wrapping mode of the texture you're sampling.

    GL_TEXTURE_WRAP_S
    Sets the wrap parameter for texture coordinate s to GL_CLAMP, GL_REPEAT, GL_CLAMP_TO_BORDER_EXT, or GL_CLAMP_TO_EDGE_EXT. GL_CLAMP causes s coordinates to be clamped to the range [0, 1] and is useful for preventing wrapping artifacts when mapping a single image onto an object. GL_REPEAT causes the integer part of the s coordinate to be ignored; the GL uses only the fractional part, thereby creating a repeating pattern. GL_CLAMP_TO_BORDER_EXT causes s coordinates to be clamped to a range 1/2 texel outside [0, 1]; this prevents the "half border, half edge" color artifact. GL_CLAMP_TO_EDGE_EXT causes s coordinates to be clamped to a range 1/2 texel inside [0, 1]; this prevents any border colors from showing up in the image. Border texture elements are accessed only if wrapping is set to GL_CLAMP or GL_CLAMP_TO_BORDER_EXT. Initially, GL_TEXTURE_WRAP_S is set to GL_REPEAT.

    GL_TEXTURE_WRAP_T
    Sets the wrap parameter for texture coordinate t to GL_CLAMP, GL_REPEAT, GL_CLAMP_TO_BORDER_EXT, or GL_CLAMP_TO_EDGE_EXT. See the discussion under GL_TEXTURE_WRAP_S. Initially, GL_TEXTURE_WRAP_T is set to GL_REPEAT.

    N.

  3. #3
    Intern Contributor
    Join Date
    Apr 2007
    Posts
    61

    Re: accessing neighbouring fragments

    got it!

    thanks alot

Posting Permissions

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