Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Short: Do triangle strips and Tangent Space Normal mapping go together?

According to quite a lot of tutorials on bump mapping, it seems common practice to derive tangent space matrices in a vertex program and transform the light direction vector(s) to tangent space and then pass them on to a fragment program. However, if one was using triangle strips or index buffers, it is a given that the vertex buffer contains vertices that sit at border edges and would thus require more than one normal to derive tangent space matrices to interpolate between in fragment programs.

Is there any reasonable way to not have duplicate vertices in your buffer and still use tangent space normal mapping?

Which one do you think is better: Having normal and tangent encoded in the assets and just optimize the geometry handling to alleviate the cost of duplicate vertices or using triangle strips and computing normals/tangents completely at run time?

Thinking about it, the more reasonable answer seems to be the first one, but why might my professor still be fussing about triangle strips when it seems so obvious?

share|improve this question
add comment

1 Answer

up vote 7 down vote accepted

Short Answer: Yes, you need to average the tangent space vectors for each vertex just like you do with normals to achieve smooth shading. For example if a vertex is shared by 3 triangles then the final tangent frame is the average of the 3 face tangent frames.

Long Answer: These days it is generally considered best practice to use index buffers and not worry about triangle strips. The reason for this is twofold. Firstly if your geometry is optimized for vertex caching an index buffer prevents most duplicate vertex scenarios and will be just as fast as triangle strips. Secondly making tons of pipeline changes and draw calls can dramatically affect performance. A mesh converted into triangle strips will probably result in the need for multiple draw calls as it's unlikely your entire mesh can be converted into one triangle strip and depending on the architecture of your engine may even require multiple vertex buffers.

Personally I prefer to precompute tangent frames and store them with the mesh data instead of calculating them in shaders. The reason for this is that 3d modelling packages such as Maya and 3DS MAX have very accurate and elaborate methods of generating the correct normals, uv's, tangents, and bitangents and it's much easier to just import them. If you develop your own method and it differs significantly from these art packages your artists are going to start asking you why the lighting on their models looks all messed up in-game because it was the way they wanted it in Maya.

share|improve this answer
    
Welcome to gamedev.stackexchange, nice answer! –  Notabene Apr 5 '11 at 8:08
    
Thank you! I figured something along those lines would probably be the answer. Also: +1 for exporting tangent frames from content creation software. Of course that's more natural for the entire art pipeline. I'm not sure if I understand completely, though- Is it correct that averaging tangent frames won't work for right/acute angles in your mesh and that this very case requires at least some redundant vertices? –  Koarl Apr 6 '11 at 21:35
    
You are correct, for right angles or any other scenario where you want a hard edge you will be required to duplicate the edge vertices for each adjacent triangle. For example there's no point in using indexed primitives for a cube because each corner vertex needs to be duplicated for each face anyway - otherwise the shading will be all crazy. –  Corillian Apr 7 '11 at 21:35
    
Alright, thanks. Marking as answer then :) –  Koarl Apr 10 '11 at 20:06
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.