Tangent basis calculation does not work

Dear all,
I’m writing a GLSL shader for bumpmapping with the nornal maps.

1)The shader works ok when I use my own vertex and fragment shader source code in the Shader Designer by Typhoon Labs.
2)The shader doesn’t work when I use it in a simple custom application, developed by me.

In the case 1) the TBN basis is computed by Shader Designer.
In the case 2) I compute the TBN by using functions found in the web.

I have tried 3 different functions found, without results, found at the URLs:



http://www.ati.com/developer/samples/VertexBlendD3D.zip (source code .cpp file : tangentspace.cpp).

Does anyone have some suggestion?

Thank you very much.



You did not mention what sort of problems you are having! I had a few problems regarding TBN matrix and then i fould an old post (very old) somewhere in the advanced coding forum, regarding the same topic. In one reply Eric Lengyl mentioned that most of the techniques found on the net (even those on nVidia and ATI site) are wrong and do not generate the correct TBN space in all cases. He then presented his technique that he had given in his book and he was kind enough to even provide source code for it. I used that and everything has worked fine every since (not to mention that it was also very efficient).

I could have posted that link over here but i didn’t because you should get used to searching the forums especially for mundane topics such as this which have already been discussed to great lengths.

It was a very long thread, and dating back to around 2002, and in case you still can’t find it then i have the page book marked on my office machine and i will give it to you, but that won’t happen until monday :stuck_out_tongue: .

In effect my question in too many general.
In my example application I render a sphere and I can switch between 3 rendering modes (so that I can check the results):

  1. Fixed pipeline mode.
  2. With a shader for usual per-pixel lighting.
  3. With a shader (and with the proper diffuse and normal map textures) for bumpmapping.

In the mode 1) and 2) the rendering’s behaviour is the same, ok.
In the mode 3) I see that diffuse light contribution is as the light has a changed its position with respect the 1) and 2). The same is for the specular contribution.
And the code for the shader in the mode 2) and 3) is the same plus the TBN matrix for the mode 3).

I will check also the old forums.

Tank you,


Here’s the link :slight_smile:


Do read the entire post because the meaning of some symbols used in the code is given by Eric in a later post. I hope this helps you.

Thank you Malik,
the code of Eric works!
In effect,
I found that I have already used it few days ago but now I have found some error in another part of my application…



Please don’t use capital letters as topic name. It is considered to be very rude and should be actually closed at spot.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.