Say I have an image of size 320x240. Now, sampling from an sampler2D with integer image coordinates ux, uy I must normalize for te
Texture coordinates (and pixel coordinates) go from 0 to 1 on the edges of the pixels no matter how many pixels.
A 4 pixel wide texture
0 0.5 1 <- texture coordinate
| | |
V V v
+-----+-----+-----+-----+
| | | | |
| | | | | <- texels
+-----+-----+-----+-----+
A 5 pixel wide texture
0 0.5 1 <- texture coordinate
| | |
V V v
+-----+-----+-----+-----+-----+
| | | | | |
| | | | | | <- texels
+-----+-----+-----+-----+-----+
A 6 pixel wide texture
0 0.5 1 <- texture coordinate
| | |
V V V
+-----+-----+-----+-----+-----+-----+
| | | | | | |
| | | | | | | <- texels
+-----+-----+-----+-----+-----+-----+
A 1 pixel wide texture
0 0.5 1 <- texture coordinate
| | |
V V V
+-----+
| |
| | <- texels
+-----+
If you use u = integerTextureCoordinate / width for each texture coordinate you'd get these coordinates
0 0.25 0.5 0.75 <- u = intU / width;
| | | |
V V V V
+-----+-----+-----+-----+
| | | | |
| | | | | <- texels
+-----+-----+-----+-----+
Those coordinates point directly between texels.
But, the texture coords you want if you want to address specific texels are like this
0.125 0.375 0.625 0.875
| | | |
V V V V
+-----+-----+-----+-----+
| | | | |
| | | | | <- texels
+-----+-----+-----+-----+
Which you get from
u = (integerTextureCoord + .5) / width