Sign in to follow this  

Space conversions (getting everything properly to tangent space)

Recommended Posts

I'm trying to get parallax mapping working and no matter how much I try, the effect ends up being directional. I'm therefore somewhat sure that that I've messed up my tangent space conversions somewhere in the vertex shader. I've cleaned it up to make the code a bit more clear. Here's my (preliminary) test code for the vertex shader. Can anyone point out if there's something wrong with it?



vec3 gdConvertWorld2Object(in vec3 vec)
    return vec3(vec4(vec, 1) * inverse(gd_matModel));
vec3 gdConvertWorld2View(in vec3 vec)
    return vec3(gd_matModelView * vec4(vec, 1));
vec3 gdConvertView2Tangent(in vec3 vec)
    mat3 tbn = mat3(gd_InTangent, cross(gd_InNormal, gd_InTangent), gd_InNormal); //TODO: I know - it's missing handedness!
    mat3 tbni = inverse(tbn);
    return tbni * (inverse(gd_matModelView) * vec4(vec, 0.0)).xyz;
vec3 gdConvertObject2Tangent(in vec3 vec)
    vec3 v = vec3(gd_matModel * vec4(vec, 1.0)); //convert vertex to world space
    mat3 tbn = mat3(gd_InTangent, cross(gd_InNormal, gd_InTangent), gd_InNormal); //TODO: I know - it's missing handedness!
    mat3 tbni = inverse(tbn);
    return tbni * (inverse(gd_matModel) * vec4(v, 0)).xyz;
in vec3 vLightPositionWS;
out vec3 vecLightTangent;
out vec3 vecCameraTangent;
void main()
//gd_InVertex is in object space
vecLightTangent = gdConvertObject2Tangent(gdConvertWorld2Object(vLightPositionWS) - gd_InVertex);
vecCameraTangent = gdConvertObject2Tangent(gdConvertWorld2Object( - gd_InVertex);
Edited by irreversible

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