• Advertisement
Sign in to follow this  

GLSL, Tangent Space, and Vertex lists

This topic is 4260 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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


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



HTH

Share this post


Link to post
Share on other sites
*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.

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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...)

Share this post


Link to post
Share on other sites
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?


16 attributes as of now, and you only have 3 IIRC that you can set if you are using all of GL's built in types. e.g. vertex, texcoords0-7, fog, secondary color, primary color, normals

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement