GLSL, Tangent Space, and Vertex lists

Started by
9 comments, last by MARS_999 17 years, 9 months ago
Hi guys, I've been mucking around with some normal mapping stuff, and for the most part it is working as I want it to; but for my testing I have not been using Vertex Lists which is what I use in my engine to help my rendering speeds. My question is: If I want to have a normal mapped object that uses vertex lists how do I specify the tangent for the shader to use for each vertex? With normal rendering I just do a calculation and pass it to the shader as a parameter, but with a Vertex list I don't know how this is possible. A solution I thought of would be to add the tangent calculations to the section where I create the vertex list, but I don't think that it would work. Any feedback / suggestions would be greatly appreciated. -Tim
Advertisement
upload your tangents as texture coordinates, use generic attributes, ect... You are using GLSL correct? If so the easiest way is to send the tangents through as texture coordinates. Now depending on how many texture coordinate sets you are sending to GLSL, e.g. unit 0 is the only one, then unit 1 you can upload the tangents there.

glActiveTextureARB(GL_TEXTURE1_ARB);glBindTexture(GL_TEXTURE_2D, textureObject);glClientActiveTextureARB(GL_TEXTURE1_ARB);glTexCoordPointer(2, GL_FLOAT, vertexStride, BUFFER_OFFSET(offsetForTangentCoords));glEnableClientState(GL_TEXTURE_COORD_ARRAY);

this example uses VBO's but VA if you are using them is similar just drop the BUFFER_OFFSET macro and use a memory address(pointer) to the tangent data.

and then in the shader

//VSvoid main(){vec3 tangent = vec3(gl_MultiTexCoord1);//do stuff with tangent vector now}


HTH
*sigh* using texture coords for other data just makes your code less clear and I do wish people wouldn't do it.

Instead, define 'attribute' varibles in the vertex shader, query their location post-GLSL link and then use the attributes as you would a vertex array.
Quote:Original post by phantom
*sigh* using texture coords for other data just makes your code less clear and I do wish people wouldn't do it.

Instead, define 'attribute' varibles in the vertex shader, query their location post-GLSL link and then use the attributes as you would a vertex array.


Yes and I agree I would rather have "tangent" or "bitangent" but I have no clue to his knowledge on GLSL so I just gave him the simplest way to getup and running...
If I did that phantom would I not need to keep a local copy of the tangents and the render order of the vercies from the model in some kind of local memory and iterate through them as I did the render?

I am not quite sure exactly what you mean?

I do understand the hiding the tangents in texture coordinates, but I also understand that it is not a "nice" solution.

-Tim
Quote:Original post by stramit
If I did that phantom would I not need to keep a local copy of the tangents and the render order of the vercies from the model in some kind of local memory and iterate through them as I did the render?

I am not quite sure exactly what you mean?

I do understand the hiding the tangents in texture coordinates, but I also understand that it is not a "nice" solution.

-Tim


You need the tangents in an array, and you upload them like you do your vertices, normals, texture coordinates, ect... with the gl*Pointer()'s. But if you are/want to use tangents as a correct label for your data then you need to setup generic attribute arrays, if not like I said before you can use the glTexCoordPointer() to load them and not have to setup GLSL to use the label "tangent" or in your VS attribute vec3 tangent;

I recommend buying the "More OpenGL Game Programming" book Phantom wrote the chapter on GLSL and is quite good... :) Now if he would just dump his code on the website some millennium! ;P
Thanks very much for the help guys it is most apreciated.

I'll go into the book shop this week and if the book is as good as you say I will snag myself a copy. It would be nice to finally find a programming book that doesn't cater to much to the noobier ideas, and has a focus on what is done in the industry.

-Tim
Quote:Original post by phantom
*sigh* using texture coords for other data just makes your code less clear and I do wish people wouldn't do it.

Instead, define 'attribute' varibles in the vertex shader, query their location post-GLSL link and then use the attributes as you would a vertex array.


whats the maximum number of attributes / the number of attribute registers one can use?
http://www.8ung.at/basiror/theironcross.html
Quote:Original post by Basiror
Quote:Original post by phantom
*sigh* using texture coords for other data just makes your code less clear and I do wish people wouldn't do it.

Instead, define 'attribute' varibles in the vertex shader, query their location post-GLSL link and then use the attributes as you would a vertex array.


whats the maximum number of attributes / the number of attribute registers one can use?

Actually it doesn't matter whether you use MARS_999's method or what phantom suggested wrt your point. The number of active attributes stays the same. If you don't use texcoord set 1, it isn't an active attribute and thus doesn't count.
Quote:Original post by MARS_999
Now if he would just dump his code on the website some millennium! ;P


It's being worked on, I'm having some crazy problems with moving the code from my own framework to the framework used by the book [sad]
(I did have an inital version I thought I'd sent Dave but it got lose in a hard drive crash...)

This topic is closed to new replies.

Advertisement