View Full Version : Lookup textures ???

01-24-2010, 09:31 AM

Been searching the forum but didnt find anything that describes my little problem.
Im reading texture coordinates from a texture. If I read from the texture in the vertex shader everything is ok.
Except that the performance drop makes the program useless :sorrow:.
If I move the lookup to the fragment shader performance is good, but the texture coordinates is totally screwed.
I set up the lookup texture with filters set to GL_NEAREST, so there should be no filtering.
This is the texture creation I use:

glBindTexture (GL_TEXTURE_2D,coordT);

glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,128,128,0,GL_R GB,GL_FLOAT,coordbase);

Im probably missing something silly as usual, but please enlighten me :D.

01-24-2010, 12:15 PM
You make something like this in the fragment shader ?

indexed = texture2D(indexmap, vec2(s,t));
value = texture2D(colormap, vec2(indexed.r,indexed.g));

If yes, this a random memory access problem.

With the indexed redirection, the shader as to wait that the sample of indexmap is finish before to can sample into the colormap

==> they are serialised operations and you have "pseudo-randoms" access to the colormap that aren't cached by the hardware (a more little "colormap samples distance" into the indexed array can sometimes resolve this)


01-25-2010, 12:06 AM
Thanks for the answer.

Hmm....Yep, thats the way I do it in the fragment shader.
But now Im beginning to wonder, whats the use of lookup textures if they dont return the correct data???

Reading from a texture in the vertex shader is to slow on my Quadro FX4500.

Damn, is there a better way to send data to the shader???
Im using a display list since I have a tremendous amount of texture object swapping, and as far as I know you cant do state changes with vertex buffers.

I need to be able to change the texture coordinates and thought I FINALLY found a great way to do it :sorrow: :eek: :( :sorrow: :sleeping:

Alfonse Reinheart
01-25-2010, 12:47 AM
whats the use of lookup textures if they dont return the correct data???

They do. If you're not getting the data you set into them back out, then it's something you're doing wrong.

01-25-2010, 06:43 AM
They do. If you're not getting the data you set into them back out, then it's something you're doing wrong.

Okay, just like I stated above I guess I could have made a misstake.
But if everything is good when I access the texture in the vertex shader, except performance, but is wrong in the fragment shader the texture setup cant be that wrong I suppose.

Apart from that Im interessted in WHAT Im doing wrong. Not THAT Im doing something wrong.
Seems like someone is eager to stay on top on the Top Posters list. ;)

02-03-2010, 05:40 AM
Well, since no one seemed to have a solution for using lookup textures in the fragment shader I struggled on myself.
I found out that I can get hardware vertex texture lookup by using the GL_LUMINANCE_FLOAT32_ATI as texture format for the lookup texture.
But this only works with nVidia cards :sorrow:!!

More investigation on the web makes me even more puzzled since some people says it should work on ATI cards and some dont.
Of course the easiest way would to be able to use the lookup in the fragment shader.

Please!! Someone MUST have used lookup textures in the fragment shader before :(

02-06-2010, 12:33 PM
If it is slow sampling a texture from a vertex shader, then it depends on the texture format that is supported or should I say not supported by your GPU. All that [censored] is explained here

02-07-2010, 08:05 AM
Thanx for the answers.
I actually found a better way by adding a separate glMultiTexCoord3f in my display list that could be used in the vertex shader.
And it actually works great. Plus, I dont need to use the glTexImage command.

But its still funny, since the Orange Book talks a lot about lookup textures, if you dont get the correct value in the fragment shader and vertex textures is only supported by some graphics cards.
Anyway, problem solved for me......for the moment at least :D

Thanks to all!!