Sample neighbor texels

Started by
2 comments, last by karwosts 12 years, 8 months ago
Hi,

I have 2 questions about GLSL texture sampling.

1) If I sample a texture with texture2DRect( diffuseTex , gl_TexCoord[0].xy ) ;
where xy are non-normalized coordinates (i.e. from (0,0) to (800,600),
where does a coordinate of (0,0) sample? Is this the bottom left cornor of a texel or the center or...?

2) What offsets do I need if I want to sample the right and left neighbor of the current texel in the fragment shader.


RightNeighborSample = texture2DRect( diffuseTex , gl_TexCoord[0].xy + rightOffset );
LeftNeighborSample = texture2DRect( diffuseTex , gl_TexCoord[0].xy + leftOffset );

Which values do I need for rightOffset? vec2(1,0) or vec2(0.5, 0), or ...?

Thanks!
Advertisement
texcoord_X + 1.0/size_width
texcoord_Y + 1.0/size_height

because texcoord go from 0.0 to 1.0 (0 to width)
and
for the height 0.0 to 1.0
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
Well, thanks. But actually that did not answer my questions.

First of all I am using texture2DRect(), which uses NON normalized coordiantes (I wrote it in my posting). Second I want to know where the sampling point in the texels is.
For regular textures, (0,0) is the lower left corner of the lower left texel, so I would imagine that it is the same for rectangular textures as well.

If each texel is already lined up with a pixel boundary, then gl_TexCoord[0].xy should already be selecting the center of a texel, so you'll just want to add 1.0 in each direction that you want to get the neighbor texel.
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game

This topic is closed to new replies.

Advertisement