为什么这个OpenGL着色器使用超过1.0的纹理坐标?

Ala*_*lan 5 opengl shader glsl

我正在尝试熟悉opengl中的着色器.这是我找到的一些示例代码(使用openframeworks).代码只是在两次通过中模糊图像,首先是水平,然后是垂直.这是水平着色器的代码.我唯一的困惑是纹理坐标.他们超过1.

void main( void )
{
    vec2 st = gl_TexCoord[0].st;
    //horizontal blur
    //from http://www.gamerendering.com/2008/10/11/gaussian-blur-filter-shader/

    vec4 color;

    color += 1.0 * texture2DRect(src_tex_unit0, st + vec2(blurAmnt * -4.0, 0));
    color += 2.0 * texture2DRect(src_tex_unit0, st + vec2(blurAmnt * -3.0, 0));
    color += 3.0 * texture2DRect(src_tex_unit0, st + vec2(blurAmnt * -2.0, 0));
    color += 4.0 * texture2DRect(src_tex_unit0, st + vec2(blurAmnt * -1.0, 0));

    color += 5.0 * texture2DRect(src_tex_unit0, st + vec2(blurAmnt , 0));

    color += 4.0 * texture2DRect(src_tex_unit0, st + vec2(blurAmnt * 1.0, 0));
    color += 3.0 * texture2DRect(src_tex_unit0, st + vec2(blurAmnt * 2.0, 0));
    color += 2.0 * texture2DRect(src_tex_unit0, st + vec2(blurAmnt * 3.0, 0));
    color += 1.0 * texture2DRect(src_tex_unit0, st + vec2(blurAmnt * 4.0, 0));

    color /= 5.0;
    gl_FragColor = color;
}
Run Code Online (Sandbox Code Playgroud)

我不能在这段代码中做出正面或反面.纹理坐标应该在0和1之间,我已经读过一些关于当它们大于1时会发生什么,但这不是我看到的行为(或者我没有看到连接).blurAmnt在0.0到6.4之间变化,因此s可以从0到25.6.根据值,图像或多或少会变得模糊,我没有看到任何重复的图案.

我的问题归结为:当texture2DRect调用中的纹理坐标参数超过1时,到底发生了什么?尽管如此,为什么模糊行为仍能完美运作?

Mat*_*gro 8

[0,1]纹理坐标范围仅适用于GL_TEXTURE_2D纹理目标.由于该代码使用texture2DRect(和samplerRect),因此它使用GL_TEXTURE_RECTANGLE_ARB纹理目标,该目标使用非标准化纹理坐标,范围为[0,width] x [0,height].

这就是为什么你有"怪异"纹理坐标.别担心,它们可以很好地处理这个纹理目标.