View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Space conversions (getting everything properly to tangent space)

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.

No replies to this topic

### #1irreversible  Members

Posted 31 January 2013 - 09:26 PM

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_vecEyePositionWS.xyz) - gd_InVertex);
}


Edited by irreversible, 31 January 2013 - 09:29 PM.

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.