Skip to main content
GameDev.net gamedev.net
🔒 Locked

Computing tangent frame in pixel shader

Started by maxest Aug 7, 2011 at 9:10 PM 2 replies 6k views
Original Post
maxest
maxest
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?
maxest
maxest
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?
AverageJoeSSU
AverageJoeSSU
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
maxest
maxest
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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.