Menu

#45 TBN Fix

open
nobody
None
5
2013-03-28
2013-03-28
Anonymous
No

Here's a fix for a pet peeve of mine... TBN generation.

Calculating tangents and bitangents(binormals, lol, the uneducated) worked fine, until you got a mesh with mirrored (or backward) texturing, then it got a bit funky.

The reason for this... a couple.
First, when determining the texture orientation, a single test was done. This would break if a texture was mirrored on one axis (including if the whole texture was mirrored). this has been broken into 2 seperate tests, the original test (u) and it's opposite (v). Try this test with your fingers - make a 3-axis formation (remember right hand rule?) and then try the cases out (+uv, -uv, +u-v, -u+v) - you'll need to break at least one of your fingers to visualise half of the results... so fixed.

Second. although the small fix helped, it still generated broken TBNs (half left handed, half right), so, a simple test for handedness is performed and the bitangent is recalculated from the cross of the vertex normal and the (corrected) tangent.

Now imported meshes look groovy, you no longer need to correct the TBN and normal maps are easier for the artist to make (you can put down the cape of +10 artistic normal mapping skill, it looked silly anyways).

Ok, it's not 100% optimal, but it works.

anyways, do what you will with the patch (You're welcome).
Richard Swift.

Discussion

  • Nobody/Anonymous

    The fix for tbn generation.

     
  • Anonymous

    Anonymous - 2013-03-28

    Oops, just realised that I got part of the algo the wrong way round...

    localTangent^meshNorm[p]

    should be...

    meshNorm[p]^localTangent

    Hadn't realised until I noticed my terrain was lit differently.

     

    Last edit: Anonymous 2013-11-26
  • Alexander Gessler

    Hi, thanks for your patch! I believe this is related / fixes TBN issues we've had earlier reports on.

    Is there any chance you could upload a test model that exposes the issue? This makes reviewing patches much easier.

    Best, Alex

     
  • Anonymous

    Anonymous - 2013-03-28

    Hmmm, can't attach to a comment...

    Anyways http://ogldev.atspace.co.uk/www/tutorial38/tutorial38.html has a MD5 model called "boblampclean" in the zip file - the head has 'mirrored' UVs and is rendered incorrectly (broken TBN).

    Been throwing models at the patched patch (see last comment) all day so far without any TBN errors.

    Richard

     
  • Anonymous

    Anonymous - 2013-04-03

    The history of how I found this issue is a simple one - I'm using quaternions to store the TBN and transforming back on the shader (less VBO memory used). It's something like glm::quat_cast(glm::mat3(T,B,N)) to convert (using glm obviously). That's why I made the patch.

     

    Last edit: Anonymous 2016-01-10