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

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.

got it!

thanks alot

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