Texture sampling : fragment shader

I’m trying to achieve a glow by outputting each pixel as an average of its 8 neighboring pixels (horizontal and vertical).

umm…how do I know the texture coordinates of the neighboring texels to a given texel?

suppose I’m using a texture sampling range and domain of 0-1 (basic OpenGL way).

I’m rendering my scene to a pbuffer of size MxN.
When i receive the texture coords for a texel in the fragment shader can i sample the next texel over (horizontally) using texCoord.x + 1/M, the texel two texels over using texCoord.x + 2*(1/M) and so on?

Has anyone done a glow shader in GLSL?

thanks for any and all help.

Yep, that should do it. You might also want to try turning on filtering for that texture and sampling right between pixels in order to have the card average four pixels for you. For example, you could average a block of sixteen pixels with just four reads in the shader if you sampled at texCoord + vec2(+/- 1.5/M, +/- 1.5/N), assuming tecCoord is in the center of a texel.

I believe that in OpenGL texels are sampled from the center, are they not?

what type of filtering would do it?
is GL_LINEAR for both
GL_TEXTURE_MAG_FILTER
and
GL_TEXTURE_MIN_FILTER
good enough?

is that what you’re talking about?

What I’m trying to do is extremely performance critical; dropping down to 4 texture lookups would be fantastic.

thanks.

Originally posted by Aeluned:
I believe that in OpenGL texels are sampled from the center, are they not?

I’m not sure what you’re asking. I think for the purpose of interpolation, the center of each texel is used as the “location” of that texel.

[b]
what type of filtering would do it?
is GL_LINEAR for both
GL_TEXTURE_MAG_FILTER
and
GL_TEXTURE_MIN_FILTER
good enough?

is that what you’re talking about?

What I’m trying to do is extremely performance critical; dropping down to 4 texture lookups would be fantastic.

thanks.[/b]
Yes, that’ll do it. (Actually, I think the minification filter is the only one that matters in this case but I don’t understand filtering very well.)

Since texture coordinates are defined in float pecision you can sample the edge of a pixel, the exact center or inbetween. When you choose a location exactly between (horizontal and vertical) 4 pixels you get the most out of a GL_LINEAR mapped texture.

uv coordinates of (0.0, 0.0) correspond not to the first pixel in the texture but the most outer corner of the first pixel.
For best filtering use (1.0/tex_width, 1.0/tex_height) to get a filtered result of the outer 2x2 corner pixels.

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