Use Tangents for correct normal calculation

The normal maps are looking good now!
This commit is contained in:
karl 2020-11-18 16:04:44 +01:00
parent fd9317a5f5
commit 83936f66fb
2 changed files with 8 additions and 2 deletions

View File

@ -5,6 +5,7 @@ in mediump vec2 TexCoord;
in mediump vec3 Normal;
in mediump vec3 FragPos;
in mediump vec4 FragPosLightSpace;
in mediump mat3 TBN;
layout(binding=0) uniform sampler2D shadowMap;
layout(binding=1) uniform sampler2D tex;
@ -46,8 +47,7 @@ void main()
// Get normal from normal map in the range [-1,1]
mediump vec3 map_normal = normalize(texture(normalmap, TexCoord).rgb * 2.0 - 1.0);
mediump vec3 final_normal = map_normal;
mediump vec3 final_normal = normalize(TBN * map_normal);
// Alpha Scissors
if(texColor.a < 0.1)

View File

@ -9,6 +9,7 @@ out vec2 TexCoord;
out vec3 Normal;
out vec3 FragPos;
out vec4 FragPosLightSpace;
out mat3 TBN;
uniform mat4 model;
uniform mat4 view;
@ -22,4 +23,9 @@ void main()
Normal = NORMAL;
FragPos = vec3(model * vec4(aPos, 1.0));
FragPosLightSpace = lightSpaceMatrix * vec4(FragPos, 1.0);
vec3 T = normalize(vec3(model * vec4(TANGENT, 0.0)));
vec3 B = normalize(vec3(model * vec4(BITANGENT, 0.0)));
vec3 N = normalize(vec3(model * vec4(NORMAL, 0.0)));
TBN = mat3(T, B, N);
}