Search code examples
opengltextures

Are texture coordinate range ends at the outer edges of edge texels?


From my debugging, I've found that with a 1D texture of 128 pixels in length I have to clamp my s coordinate passed to texture1D in GLSL fragment shader not to the range [0,1], but to something like [0,1-1./257] (increase 257->258 gives the artifact back; the number obtained by bisection to 0.99610897). Otherwise I have repetitions of the values obtained at s==0.

This, of course, doesn't happen when I set texture parameter GL_TEXTURE_WRAP_T to GL_CLAMP_TO_EDGE instead of the default GL_REPEAT.

I'm coming to a conclusion that the ends of texture coordinate range are not at the centers of edge texels, but at the outer edges of them.

It would then make sense that if I set GL_TEXTURE_*_FILTER to GL_NEAREST (in GL_REPEAT mode), it works as if the sampling looks at the texels at right of the specified s, while for GL_LINEAR filter it takes average of left and right texels for s==1.

Is my conclusion correct? Are the ends of texture coordinate range at the outer edges of the texels, not at their centers?


Solution

  • I'm coming to a conclusion that the ends of texture coordinate range are not at the centers of edge texels, but at the outer edges of them.

    Correct.