• 12
• 12
• 9
• 10
• 13

# Sample neighbor texels

This topic is 2407 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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!

##### Share on other sites
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

##### Share on other sites
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.