# Space conversions (getting everything properly to tangent space)

This topic is 2142 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

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

Edited by irreversible

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5

• 26
• 11
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633702
• Total Posts
3013450
×