## Calculating tangent coords for arbitrary poly meshes

Sage
Posts: 1,199
Joined: 2004.10
Post: #1
I imagine some of the better modeling tools will calculate tangent coords automatically, but as far as I can tell Wings3D does not, or the OBJ format doesn't support it so Wings doesn't write them out.

So, I'm in a pickle. I'd like meaningful tangent coords for bumpmapping, but the attempts I've made to calculate them have produced really crappy output.

Does anybody have any suggestions?
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
NVidia has an open-source C++ library which'll do it for you.
Member
Posts: 151
Joined: 2002.09
Post: #3
I've once tried to come up with methods myself. However I don't currently remember much of the last method i used.
Some of my theory behind it if anyone is interested:

I assume that for a triangle (which is easier to work with) you can get the general tangent space which is aligned to the face normal (as when it's flat) and to get per vertex space you just need to align it to the vertex normal (by rotating).

To get the space of a flat triangle (A,B,C) I just solved linear equations for:
(TBN * (TexCoordOffsetAC.h,TexCoordOffsetAC.v,0) = C - A) and
(TBN * (TexCoordOffsetAB.h,TexCoordOffsetAB.v,0) = B - A)
which is the same as
(TB * TexCoordOffsetAC = C - A) and
(TB * TexCoordOffsetAB = B - A)
(or BT instead of TB depending on how you define it)
(or i suppose you could include the per vertex normal in the equation, or maybe not (as B and T aren't orthogonal to N that way) )

This was quite some time ago when i didn't find much useful stuff, so i'd go with NVidias stuff.
Sage
Posts: 1,199
Joined: 2004.10
Post: #4
Where is this C++ lib from NVidia? I'm going to start searching, but their dev site is huge.

AARG! Searching NVidia's site I see a tool called NVMeshMender, which seems to be exactly what I want. But the download link is dead.
Member
Posts: 567
Joined: 2004.07
Post: #5

then look for the 'koders' link; I haven't looked at them (because I don't know what to look for), but that looks promising.

It's not magic, it's Ruby.
Member
Posts: 320
Joined: 2003.06
Post: #6
let us know when you figure it out, I spent hours trying to create valid tangents and gave up!

Chopper, iSight Screensavers, DuckDuckDuck: http://majicjungle.com
Sage
Posts: 1,199
Joined: 2004.10
Post: #7
Thanks Nayr, I got the source. It's going to take a little work to figure out how best to integrate it into my mesh code, but I'm confident I can!
Sage
Posts: 1,199
Joined: 2004.10
Post: #8
So, many days later. I did manage to integrate NVMeshMender, but really to no avail. The output wasn't any better than my own, since both my code and NVMM are doing the same thing ( generating "good enough" automatic texture coords if none already exist and then running established algorithms to create tangents from them ).

So, that being said, I did fix a bug in my own implementation, and the normalmapped rendering is... presentable... now. But I'm at the point now where I think my GLSL is at fault. It's hard to debug graphics code when you're not certain where the bug is. Are my tangents bad? Is my GLSL bad? Or are both bad? Who knows!?

All I can say for certain is that my specular lighting looks pretty broken. That is to say, if you look closely, it's not really in the right place. With a non-critical eye, it looks fine.

Member
Posts: 151
Joined: 2002.09
Post: #9
draw little lines along your tangents to see if they look correct. You may also just have some axes swapped.