Jump to content

  • Log In with Google      Sign In   
  • Create Account

Computing tangent frame in pixel shader


Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
3 replies to this topic

#1 maxest   Members   -  Reputation: 473

Like
0Likes
Like

Posted 07 August 2011 - 03:10 PM

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:
PositionDelta = TexCoordDelta * Tangent 
whereas Schuler defines it:
PositionDelta * Tangent = TexCoordDelta
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?

Attached Files



Sponsor:

#2 maxest   Members   -  Reputation: 473

Like
0Likes
Like

Posted 08 August 2011 - 04:27 PM

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):
delta_u = |delta_P| |T| cos(alpha)	->	delta_u = delta_P dot T
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:
delta_u2 / |delta_P2| = cos(alpha)
If we substitute this to the Schuler's equations we get:
delta_u2 = |delta_P2| |T| cos(alpha)
delta_u2 = |delta_P2| |T| (delta_u2 / |delta_P2|)	->	|T| = 1
Do I misinterpret something?

#3 AverageJoeSSU   Members   -  Reputation: 564

Like
0Likes
Like

Posted 10 August 2011 - 12:21 PM

I used the article from ShaderX5 and it worked quite well.

I am not familiar with schuler so i cannot comment on his discrepency.

------------------------------

redwoodpixel.com


#4 maxest   Members   -  Reputation: 473

Like
0Likes
Like

Posted 10 August 2011 - 05:14 PM

I didn't say it didn't work. I'm just saying I don't fully understand his theory :). Would be great if somebody could verify my statement about the length of T vector




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.




PARTNERS