Jump to content

  • Log In with Google      Sign In   
  • Create Account

#Actualirreversible

Posted 31 January 2013 - 09:29 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);
}

#1irreversible

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. I've cleaned it up to make the code a bit more clear. Here's my (preliminary) test code for the vertex shader:

 

 
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);
}

PARTNERS