I am trying to sample one whole texture for each fragment in the fragmentshader but the way I do it seems to be very inaccurate. I am having a GL_TEXTURE_2D which is 1px high and lets say 8px wide. I set it up like this:
I expect this code to read each pixel of the texture exactly once, but there seem to be inaccuracies which read one pixel twice and skip others. Is there something I am doing obviously wrong here? I also tried to replace GL_CLAMP in my texture setup with CLAMP_TO_EDGE and REPEAT without any success.
thank you so much, it works! I am trying to implement spatial hashing on the GPU and this simple mistake was causing me a headache for 24 hours yesterday!
Another question about texCoords occured to me. I init one of my lookup textures to the maximum size needed which is eg. 1024x1px. Now I want to update the texture content using glTexSubImage2D like this:
so that I dont have to reallocate memory for the texture each time I update it. Since the needed pixels will most likely be less than the allocated number of pixels I thought I could simply calculate a factor like this to adjust my texel size in the shader:
uniform float attribTexRatio; //same as factor from above
uniform float attribTexFormat; //width of texture in pixels 512 in this case
float tlTexelSize = (attribTexRatio/attribTexFormat);
then I do the texture lookups as described by zBuffer before, but unfortunatelly it does not work. I am propably missing something simple again!
if I reallocate the whole texture each time and set the texel size to 1.0/attribTexFormat it works fine, but as stated I would like to avoid that.