Help converting normals from global space to tangent space
Hi, I'm developing a simple normal map generator. One that takes two meshes, one lowpoly and one highpoly and creates a normal map for the lowpoly. (Yes I know that there exists such things already, but I'm doing it just for the kicks )
The result when rendering a global space normal map is quite satisfying but when it comes to the tangent space one it get's worse. I can't seem to get a grip on how to generate a tangent space normal map using the smoothed normals of the lowpoly model. I can however generate one that looks decent for the hard normals but such a normal map just isn't good enough for anything
This is how I was thinking when using the hard normals:
Where all the vectors are normalized and the two tangents are parallell to their corresponding edge of the triangle. The normal is ofcourse the hard normal of the triangle. (The T is the transformation matrix which I would use to transform the global space normals to tanget space.)
For the smoothed normals I was thinking of generating a matrix for every pixel of the global space map where I use the interpolated smoothed normal as the normal and the same tangents and uv vectors as before. I would like some input on that method before implementing it though.
Any input is greatly appreciated.
The result when rendering a global space normal map is quite satisfying but when it comes to the tangent space one it get's worse. I can't seem to get a grip on how to generate a tangent space normal map using the smoothed normals of the lowpoly model. I can however generate one that looks decent for the hard normals but such a normal map just isn't good enough for anything
This is how I was thinking when using the hard normals:
Where all the vectors are normalized and the two tangents are parallell to their corresponding edge of the triangle. The normal is ofcourse the hard normal of the triangle. (The T is the transformation matrix which I would use to transform the global space normals to tanget space.)
For the smoothed normals I was thinking of generating a matrix for every pixel of the global space map where I use the interpolated smoothed normal as the normal and the same tangents and uv vectors as before. I would like some input on that method before implementing it though.
Any input is greatly appreciated.
Someone correct me if I am wrong, but shouldn't your three axises form an orthonormal coordinate system?
 Sohta
I think, you are right about that.
I've actually thought about making the vectors orthonormal but it feels like the results would differ quite a bit depending on which vector I choose as the first and second base vector.
Perhaps I'm just making a faulty assumption.
I've actually thought about making the vectors orthonormal but it feels like the results would differ quite a bit depending on which vector I choose as the first and second base vector.
Perhaps I'm just making a faulty assumption.
If they're not orthonormal the matrix won't be (purely) a rotation matrix.
Alright, it's been a while since I did any of that stuff, but here goes:
IIRC, your tangent vector is the direction that will match the u axis of your texture coordinate minus its projection on the normal vector (normalizing the end result). Your "second tangent" (normally referred to as the binormal) has to be the cross product of the tangent and the normal (in order to preserve the orthonormality). You have the choice of precalculating that value, or generate it in your shader (depending on where your bottleneck is).
IIRC, your tangent vector is the direction that will match the u axis of your texture coordinate minus its projection on the normal vector (normalizing the end result). Your "second tangent" (normally referred to as the binormal) has to be the cross product of the tangent and the normal (in order to preserve the orthonormality). You have the choice of precalculating that value, or generate it in your shader (depending on where your bottleneck is).
 Sohta
Sohta: Yeah... that sounds like a reasonable plan. One thing I got to thinking about, when I was just about to try it, was this.
To get the tangent which is pointing in the direction of the Ucoordinate one could use the inverse of my matrix T and use it on the vector [1, 0, 0]. After that, if one has a matrix for every pixel you would use inv(T) on the vector [0, 0, 1].
Using a perfectly constructed UVmap one would get the bitangent using inv(T) on [0, 1, 0]. (This would result in the a transformation of the Imatrix which again iresults in inv(T).)
So I was thinking, is it really the correct way to actually build a orthonormal matrix? Wouldn't a transformation matrix be more "correct" if one wants to convert to a local coordinate system?
Thanks for the input
To get the tangent which is pointing in the direction of the Ucoordinate one could use the inverse of my matrix T and use it on the vector [1, 0, 0]. After that, if one has a matrix for every pixel you would use inv(T) on the vector [0, 0, 1].
Using a perfectly constructed UVmap one would get the bitangent using inv(T) on [0, 1, 0]. (This would result in the a transformation of the Imatrix which again iresults in inv(T).)
So I was thinking, is it really the correct way to actually build a orthonormal matrix? Wouldn't a transformation matrix be more "correct" if one wants to convert to a local coordinate system?
Thanks for the input
Possibly Related Threads...
Thread:  Author  Replies:  Views:  Last Post  
showing off new space game  gooncorp  1  4,893 
Nov 8, 2012 02:35 PM Last Post: PythonBlue 

converting quartz to openGL ES  aerospaceman  2  5,322 
Apr 12, 2010 10:57 AM Last Post: ThemsAllTook 

Transforming directional light to eye space in GLSL  Coyote  4  9,225 
Dec 8, 2009 03:16 PM Last Post: Coyote 

OpenGL global and local coordinate problem.  mikey  4  6,389 
May 26, 2009 08:48 AM Last Post: mikey 

Screenspace techniques  mattz  4  6,072 
Nov 6, 2008 08:55 PM Last Post: Bachus 