5

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.

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;
}

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.

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?

4
  • Your code doesn't match the page you linked to. What's the definition of texture2DRect? Commented Jul 18, 2011 at 15:58
  • it's an opengl shader thing. texture2DRect is just a function that accesses the pixel information from an underlying texture, given the st coordinates. The page I linked to was actually a comment in the code describing the blurring algorithm and is not directly related to my question, which is "why does the blurring algorithm still work despite texture coordinates greater than 1?" Commented Jul 18, 2011 at 16:02
  • I understand what it's supposed to be, more or less, but it doesn't appear to be a GLSL built-in (at least my OpenGL 4.1 Reference Card doesn't include it). So I thought maybe it's a user-defined wrapper, and there could be some scaling inside the wrapper. Commented Jul 18, 2011 at 16:13
  • apparently, I discovered it's an extension of opengl stackoverflow.com/questions/6736531/… Commented Jul 19, 2011 at 15:33

2 Answers 2

8

The [0, 1] texture coordinate range only applies to the GL_TEXTURE_2D texture target. Since that code uses texture2DRect (and a samplerRect), it's using the GL_TEXTURE_RECTANGLE_ARB texture target, that this target uses Unnormalized texture coordinates, in the range [0, width]x[0, height].

That's why you have "weird" texture coords. Don't worry, they work fine with this texture target.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Matias, I also asked a related question that links to documentation on rectangular textures, for future reference stackoverflow.com/q/6736531/770572
-1

Depends on the host code. If you saw something like

glTexParameteri (GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP);

Then the out of bounds s dimension will be zeros, IIRC. Similar for t.

1 Comment

As s dimension proceeds from 1 all the way to 6.4, the image just gets more and more blurry, which is not the behavior I would expect if it was just zero-ing out. Any ideas?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.