Sign in to follow this  

Computing tangent frame in pixel shader

This topic is 2315 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

In ShaderX5 there is a nice article about generating tangent basis from within a pixel shader, without using precomputed tangents. Since I don't exactly grasp the idea why it works, I decided to take a look somewhere else. And in the popular Eric Lengyel's book I found some nice derivation which is quite close to the one from ShaderX article, but differs in one substantial aspect.
To avoid explaining or writing down the formulas, I took the liberty and scanned selected pages from those books. The scans are in the attachment. There are 3 pages from "Mathematics for 3D Game Programming and Computer Graphics" by Eric Lengyel (named lenX.jpg, X >= 1 && X <= 3) as well as 3 pages from "Normal Mapping wtihout Precomputed Tangents" in ShaderX5 by Christian Schuler (named schX.jpg, X >= 1 && X <= 3. What bothers me is the final formulation of the tangent frame. In Lengyel, in file len2.jpg there is formula 6.35 at the bottom of the page, and something similar in sch3.jpg at the top of the page.
For short, I see Lengyel defining tangent vectors like this:
[code]
PositionDelta = TexCoordDelta * Tangent
[/code]
whereas Schuler defines it:
[code]
PositionDelta * Tangent = TexCoordDelta
[/code]
Where does this discrepancy come from?
Moreover, I swiftly tried computing the tangent vector and visualizing it, and the Lengyel's result was quite close to the visualization of precomputed tangents, whereas Schuler looked completely broken. Note that for Schuler I literally took the code from the book. I'm quite sure that I screwed up cause pictures in Schuler's article are correct so his algorithm must work. In the meantime I struggle with this I thought I could write about these formulas' discrepancy where it all starts so maybe you guys could give me some hint. Any idea?

Share this post


Link to post
Share on other sites
I've taken a look again at the equations in Schuler's article and I dare to say the equations are not exactly correct. Schuler claims the following (scan sch2):
[code]
delta_u = |delta_P| |T| cos(alpha) -> delta_u = delta_P dot T
[/code]
It is said that "the length of T corresponds to the magnitude of the u-gradient". I say that these equations assume that the length of T is 1. To verify, please, take a look at the figure 2.6.1 in scan sch2. Let's consider delta_P2 and delta_u2. We can clearly state that:
[code]
delta_u2 / |delta_P2| = cos(alpha)
[/code]
If we substitute this to the Schuler's equations we get:
[code]
delta_u2 = |delta_P2| |T| cos(alpha)
delta_u2 = |delta_P2| |T| (delta_u2 / |delta_P2|) -> |T| = 1
[/code]
Do I misinterpret something?

Share this post


Link to post
Share on other sites

This topic is 2315 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this