Lookup textures ???

Hey!

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);
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);
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE,GL_MODULATE);

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

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

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)

@+
Yannoo

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: :frowning: :sorrow: :sleeping:

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.

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. :wink:

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 :frowning:

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
http://www.opengl.org/wiki/Vertex_Texture_Fetch

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 :smiley:

Thanks to all!!