This question already has an answer here:
- OpenGL Texture Coordinates in Pixel Space 3 answers
I'm getting into GLSL and need some help with texture lookups. I'm trying to use a texture for storage but I cannot get "proper" texture lookups. I would prefer using the usual texture2D method (using GLSL 1.2) but the results are not good enough.
Using texture2D:
Using texelFetch:
Now obviously something is wrong with the first one. Here is what I am trying to do (yes sizes are correct unless there is something I don't know about):
vec4 texelFetch(sampler2D tex, ivec2 size, ivec2 coord)
{
return texture2D(tex, vec2(float(coord.x) / float(size.x),
float(coord.y) / float(size.y)));
}
So, how would this be done properly?