Calculating tangent coords for arbitrary poly meshes
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?
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?
NVidia has an opensource C++ library which'll do it for you.
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.
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.
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.
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.
google "nvmeshmender download"
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.
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.
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
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!
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 noncritical eye, it looks fine.
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 noncritical eye, it looks fine.
draw little lines along your tangents to see if they look correct. You may also just have some axes swapped.
Possibly Related Threads...
Thread:  Author  Replies:  Views:  Last Post  
Lowpoly lamp with adjustable glow color  Ben3d  0  2,954 
Nov 29, 2017 09:36 AM Last Post: Ben3d 

OpenGL and concave meshes  Ashford  3  6,102 
Nov 21, 2009 10:31 AM Last Post: AnotherJake 

Help converting normals from global space to tangent space  Muthaias  6  9,233 
Apr 1, 2008 06:28 AM Last Post: Muthaias 

Rendering a reflection about an arbitrary plane  TomorrowPlusX  3  6,516 
Jan 14, 2008 07:51 AM Last Post: TomorrowPlusX 

Indexed Face Sets (meshes)  wyrmmage  4  6,408 
Dec 15, 2006 11:18 AM Last Post: wyrmmage 