4
\$\begingroup\$

I have been studiing tangent space calculations and came across two solutions

E. Lengyel - http://www.terathon.com/code/tangent.html

ShaderX5 solution - (solution is also desribed here http://www.thetenthplanet.de/archives/1180)

What is the difference between tangent computed one or another way? Lengyel solution seems "easier" but I am no quite sure of its orthogonality to the normal vector of the tangent plane.

\$\endgroup\$
1
\$\begingroup\$

Lengyel's publication describes the standard method, where every vertex has a position and normal, as well as a tangent and bitangent vector. If the tangent and bitangent are not stored in the mesh, he describes how to calculate them using the normal and the uv texture coordinates.

The 2nd article describes how to calculate the tangent and bitangent in the shader. The advantage is that you do not need to send the tangents and bitangents to the vertex shader, reducing the required bandwidth. One of the disadvantages is that your fragment (pixel) shader now must work harder. It also requires the use of derivative functions (like ddx or dFdx), which are not exactly cheap.

There's even another approach, pioneered by Morten Mikkelsen, that does away with the normal map and simply uses a height map instead. This puts even more load on the fragment (pixel) shader, but you no longer need a normal map and it has advantages when doing procedural generation of textures and meshes. See here for more information.

I recently tried all 3 methods and found the 1st and 3rd option to be the best. Mikkelsen's solution is slightly slower on my machine, and requires a floating point texture for the height map, especially for close-ups. But it looked subjectively better than the 1st solution.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.