Correct issue with tangents

This commit is contained in:
Ray 2018-03-04 23:24:30 +01:00
parent 85850a955a
commit 276847eca9

View File

@ -12,7 +12,7 @@
in vec3 vertexPosition; in vec3 vertexPosition;
in vec2 vertexTexCoord; in vec2 vertexTexCoord;
in vec3 vertexNormal; in vec3 vertexNormal;
in vec3 vertexTangent; in vec4 vertexTangent;
// Input uniform values // Input uniform values
uniform mat4 mvp; uniform mat4 mvp;
@ -28,7 +28,7 @@ out vec3 fragBinormal;
void main() void main()
{ {
// Calculate binormal from vertex normal and tangent // Calculate binormal from vertex normal and tangent
vec3 vertexBinormal = cross(vertexNormal, vertexTangent); vec3 vertexBinormal = cross(vertexNormal, vec3(vertexTangent));
// Calculate fragment normal based on normal transformations // Calculate fragment normal based on normal transformations
mat3 normalMatrix = transpose(inverse(mat3(mMatrix))); mat3 normalMatrix = transpose(inverse(mat3(mMatrix)));
@ -39,7 +39,7 @@ void main()
// Send vertex attributes to fragment shader // Send vertex attributes to fragment shader
fragTexCoord = vertexTexCoord; fragTexCoord = vertexTexCoord;
fragNormal = normalize(normalMatrix*vertexNormal); fragNormal = normalize(normalMatrix*vertexNormal);
fragTangent = normalize(normalMatrix*vertexTangent); fragTangent = normalize(normalMatrix*vec3(vertexTangent));
fragTangent = normalize(fragTangent - dot(fragTangent, fragNormal)*fragNormal); fragTangent = normalize(fragTangent - dot(fragTangent, fragNormal)*fragNormal);
fragBinormal = normalize(normalMatrix*vertexBinormal); fragBinormal = normalize(normalMatrix*vertexBinormal);
fragBinormal = cross(fragNormal, fragTangent); fragBinormal = cross(fragNormal, fragTangent);