Aller au contenu

Photo

Calculating mesh vertex tangents/bitangents?


  • Veuillez vous connecter pour répondre
7 réponses à ce sujet

#1
tmp7704

tmp7704
  • Members
  • 11 156 messages
Currently using function as outlined in http://www.terathon....de/tangent.html

This appears to match DA stock models which use regular armour shader, but results in noticeably different appearance for items like hair. For these, it seems swapping the equations for tangent and bitangent provides correct shading, except it can result in some nasty glitches in certain spots, plusit breaks the appearance for regular shader.

Just wondering if someone figured out a better/more universal way to calculate these.

#2
ChewyGumball

ChewyGumball
  • Members
  • 282 messages
The way I calculated them is this if the normal is [x,y,z]:

Tangent: [-y,x,z] x [x,y,z] (thats cross product)

Bitangent: Tangent x Normal (again cross product)



I have no idea how it works for hair though.

#3
tmp7704

tmp7704
  • Members
  • 11 156 messages
Yup, tried some of the simpler ways like that but that doesn't really work either -- with regular shader the misaligned vectors affect just the normal mapping so it's easier to overlook, but hair seems to do some specular/reflection tricks to simulate closer the real thing, which highlights the issue.

Would be much easier to get it all match if there was some kind of debug switch either in toolset or in game itself to render the tangent vectors, but i suppose if there's such thing it's not published anywhere.

Modifié par tmp7704, 04 avril 2010 - 03:54 .


#4
Eshme

Eshme
  • Members
  • 756 messages
Why dont you try to match results?

Halla model: (these are all added as vertex normals)



Normal Original

Posted Image

Normals as exported

Posted Image

Tangents Original

Posted Image

Tangents exported

Posted Image

Binormals Original

Posted Image

Binormals exported

Posted Image

#5
tmp7704

tmp7704
  • Members
  • 11 156 messages
That's a great idea. Unfortunately Lightwave support for showing vertex normals is pretty much non-existent so can't use it... i guess i could tweak the importer though, to generate extra geometry out of the tangent/bitangent data. That's something to look into, thanks.

#6
tmp7704

tmp7704
  • Members
  • 11 156 messages
OK, some results of poking around:

Posted Image

on the left are DA meshes imported straight, on the right it's the same meshes after export and re-import. Top half has pictures of light armour model, bottom half is a strand of hair model. Red vector is tangent, green is bitangent, blue is normal.

As you can see, the normals for the light armour model match pretty close. For hair model however, DA apparently expects the tangent and bitangent to be swapped -- that is, while in normal shader the tangent is generally aligned with S-direction of the uv map, for hair it's aligned with T-direction instead. Rather bizzare, but i guess when in Rome etc.

Incidentally, turned out the glitches i mentioned in OP were result of some hideously sloppy uv-mapping of the base model i've used as source. Once these were straightened the errors disappeared... i guess BioWare's own tools work different and/or are more sophisticated, since they clearly managed to preduce mapping which avoided that issue.

#7
Eshme

Eshme
  • Members
  • 756 messages
What kind of sloppy hair model was it can you tell?



At least your birnomaltangent stuff is abit right lol. I would leave the possibility that this is not the problem. But is strange i guess. What kind of problem do you have now that the glitch is gone?

#8
tmp7704

tmp7704
  • Members
  • 11 156 messages

Eshme wrote...

What kind of sloppy hair model was it can you tell?

At least your birnomaltangent stuff is abit right lol. I would leave the possibility that this is not the problem. But is strange i guess. What kind of problem do you have now that the glitch is gone?

It was the *hb4 model for human females if i remember right, but i wouldn't be surprised if more meshes were affected by it, as the models shipped with game come with tangents/bitangents which make it seem fine.

I guess it's just weird decision to have some shaders work with the vectors arranged in one way, but another requiring them to be arranged just the opposite -- short of adding explicit switch in exporter config or something and expecting the artist to actually know they have to flip it on export, that can't be really automated. In any case not having further problems with it (for now at least), i just posted that last pic/update in case one day someone else stumbled upon this too and also wondered what the heck Posted Image