Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does this OpenGL shader use texture coordinates beyond 1.0?
    text
    copied!<p>I'm trying to get familiar with shaders in opengl. Here is some sample code that I found (working with openframeworks). The code simply blurs an image in two passes, first horizontally, then vertically. Here is the code from the horizontal shader. My only confusion is the texture coordinates. They exceed 1.</p> <pre><code>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; } </code></pre> <p>I can't make heads or tails out of this code. Texture coordinates are supposed to be between 0 and 1, and I've read a bit about what happens when they're greater than 1, but that's not the behavior I'm seeing (or I don't see the connection). blurAmnt varies between 0.0 and 6.4, so s can go from 0 to 25.6. The image just gets blurred more or less depending on the value, I don't see any repeating patterns.</p> <p>My question boils down to this: what exactly is happening when the texture coordinate argument in the call to texture2DRect exceeds 1? And why does the blurring behavior still function perfectly despite this?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload