I'm not sure what you mean by un-normalized texture coordinates. All texture lookups are going to be in the range of 0-1. You can have them be anywhere in that range however. If you're having precision problems in the range of 0-1 I suspect something else going on.
A couple of hints to help fix this:
For example, make sure you don't have GL_LINEAR
set for your texture. For a lookup to be accurate you're probably going to want GL_NEAREST
. Otherwise it could average the data around the textel and give you a interpolated result. Same goes for the GL_WRAP settings. You probably want something like this:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
I once had a large texture atlas (2048x2048) with a bunch of sprites on it. And in one small area of the texture I had a look up table. So in that case the lookup S started at 1024/2048 and ended at 1536/2048. So I passed to the shader uniforms for SStart
and SWidth
. And TStart
and TWidth
. SStart
was 0.5
and SWidth
was 0.25
. In my S direction I had 512 steps on the lookup, or 0.25
of 2048
. In the T direction it was also a small segment, but there I also needed to make sure it didn't bleed over in to the one next to it. So I made each lookup in the texture about 8 pixels wide, and in code I aimed to hit the middle.
The math for the S direction was an input of 0-1, so the formula was s = SStart + input * SWidth
.
There is plenty of precision in a lowp variable to handle a lookup in the range of 0-1 for any texture size that your hardware supports. Even 1/4096
. This is what the gxf card is designed to do.
GL_LINEAR
instead ofGL_NEAREST
. \$\endgroup\$