Integer lookup textures

Hello everyone

Since glsl runs into some rather funky compilation problems(using cg compiler) when large arrays are being used(2565ivec3), I decided to put one of my lookup tables for a project on a texture. At first I thought it was so simple as to make java write the values of each vector to the red, green and blue channels respectivly of some image, and then sample this image(image quite naturally generated beforehand, no mystic vodoo message passing between C++ and Java) with coordinates derived from my case value(the case i was to look up in the table), while also mutiplying the values with 255(since they are normalized when sampled with texture(samplerXD, coords)).
Did not work.
So i searcher around for a bit and found out about texelFetch, and tried to fetch the texel in particular, did not work either. At this point, I started to wonder if i were to naive to expect to be able to restore the values from the image(in between i tried to change the sampler for the texture from sampler2d to i sampler2d, not supposed to work?), so I searched around for some kind of alternative, and found out about Integer textures(now we are on openGL grounds, but this post seem more related to GLSL anyways):, which seemed really nifty, but I had a real hard time finding out more about how they were used.

Basically my question boils down to two points:

1, Should I generate some image beforehand(png, jpeg, targa whatever) with the values I am after and sample from those images in some way(please tell me how then because after all my experimentations i am clueless and also pretty pissed at GLSL for, as it appear to me at least, not sampling the right texel with fetchTexel).


2, Should i use Integer textures and create some kind of struct or something with the proper data using my lookup table textfile? And if so, some pointer to as how this would be done would be appreciated.

If that has any impact on the answer I would also like to add that my values are only going to range between 0-12.

Super thanks for your mega time

Deyy tuuk ur djeeebs!

Since glsl runs into some rather funky compilation problems(using cg compiler) when large arrays are being used(2565ivec3)

Depending on your hardware, that’s probably just running out of uniforms.

Should I generate some image beforehand(png, jpeg, targa whatever) with the values I am after

I’m pretty sure that none of these formats use unnormalized integer values. I suppose you could use a TGA or PNG that has normalized integers, then pass them along to OpenGL as unnormalized.

However, you should first make a test application that shows you can create an integer texture, upload data to it, and use that data in the shader to produce some particular output.

I would like to add that the data is strictly static, it is nothing being changed for each object rendered or something like that, so unless uniforms somehow relate to static arrays(although i dont get to use the modifier static since im using the cg compiler, which is kind of funny because that means that GLSL compiled with the cg compiler break glsl specifications =) ), that is not an issue(note: I am not entirly sure I know what a uniform is, other than in the sense of something you send from the CPU to the GPU and which remains uniform for the whole rendering pipeline).

So the data in most image formats IS normalized? Well that sucks, maybe i should try .RAW?

I did a test application and i messed around with it a lot, but to no avail.
Basically its a geometry shader that outputs one triangle for the value of the red channel255 of the texel of the texture that I am sampling. I had the corners completely black and everything else white, and the other way around, but it seemed that each time I sampled texel(0, 0) (i also tried (1, 1) in case thats the corner you start of in, i was not able to find any kind of description of how the texel array is formated) or texel(16, 16) and it seemed that instead of sampling that texel in particular, it took the most prominent feature of the texture as a whole, so when it was mostly white, it gave me 1.0 even in the black corner and the other way around. I did sample in lod 0, which should not matter because i dont have any mipmaps for the texture, and the texture was 1616(but I also tried 256 * 256 in case there is some kind of minimum resolution).

Thanks for your answer anyways.


Just a final “reflection”, is it viable to just use the texel data and mutiply it by 255 to get the RGB values in 0-255 format when sampling normalized textures? Because that would be the best way, yeah? How do you people do when you have large amounts of data you need to lookup in the shader?

Another edit:

For what difference it might make: GEFORCE 9500gt

I have done some more investigations, and it defintivly seems like texelFetch does not sample the correct sample, I am going to read up on whatever documentation i can find and make sure I am using the right arguments(currently a ivec2 for the coordinate pair)

Okay now i know what the problem is, when i use texelFetech it does not start from the upper left corner, but rather the bottom left corner, and moves x texels right and y texels up.
Kind of makes sense when I think about it. So the thing remaining to be seen now is if a normalized texture can be trusted to be multiplyed by 255 to extract the values I want out of them.

Allright consider this thread closed, got every issue in here in check. Thanks for your time