Sign in to follow this  
Prune

Texture to world space with *correct scaling* ??

Recommended Posts

Prune    224
Geometry sources generally give me normalized normals and tangents, and then the B is expected to be computed as a cross product in the vertex shader. This means that shear and scaling are gone, and I'm unable to convert from texture space to world space for anything but directions. I could assume the UV mapping is low-stretch and approximate by ignoring shear, but the scaling kills me! I need help to figure out how to do this conversion for the following: if I'm doing volume rendering on layers that are separated by some world-space distance from each other, and I know the offset in texture space of a point on one layer from the corresponding one on the previous layer (and layer offset is dynamic), I need to calculate the normal from that. Clearly, either the offset needs to go to world space, or the layer separation to texture space (also, my layers are non-planar but shells around a mesh, I'm doing fur rendering and I need individual hair normals). So how do I do this transform without being able to modify incoming vertex data (that is, I'm stuck with the normalized normals and tangents generated by the skinning library I'm using)? The only idea I had is to go through screen space first by using dFdx/dFdy in GLSL on texture and position...not sure if this will work. Also, someone asked a similar question back in 2006 and no one answered: http://www.gamedev.net/community/forums/topic.asp?topic_id=422107 I'm really hoping I'll be able to get more help than that guy -.-

Share this post


Link to post
Share on other sites
Prune    224
I found code that in the fragment shader computes TBN as follows;
varying vec3 position, normal:
void main(void)
{
vec3 v0 = dFdx(position), v1 = dFdy(position);
vec2 st0 = dFdx(gl_TexCoord[0].st),
st1 = dFdy(gl_TexCoord[0].st);
mat3 TBN = mat3(normalize(v0 * st1.t - v1 * st0.t),
normalize(v1 * st0.s - v0 * st1.s),
normalize(normal));
// Stuff using TBN
}

Because B is not calculated as a cross-product, the shearing should be correct. However, the normalization obviously takes out the scaling. I'm wondering if I simply omit the normalization, if that will give me the correct scaling, or there's some other factor needed here. Then there's the issue of the scaling of the normal itself--do I cross the un-normalized T and B or whatever.

Any ideas?

Share this post


Link to post
Share on other sites

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