Use correct normal for tangent calculations

This commit is contained in:
2021-03-07 16:32:41 +01:00
parent 45286b8178
commit 062ee8c1c5
3 changed files with 6 additions and 4 deletions

Binary file not shown.

View File

@@ -31,21 +31,23 @@ out gl_PerVertex {
};
void main() {
// Vertex position
// Vertex position in camera
gl_Position = ubo.projection * ubo.view * push.model * vec4(position, 1.0);
// Vertex position in world
position_wld = vec3(push.model * vec4(position, 1.0));
// Just interpolate UV coords, no transformation needed
tex_coords = uv;
// This should probably be in object space? idk
// Normal _direction_ in world (not use atm)
normal_wld = vec3(mat3(transpose(inverse(push.model))) * normal);
// Tangent->object space matrix
vec3 tangent3 = vec3(tangent.xy, 1.0);
vec3 bitangent = -cross(tangent3, normal_wld);
vec3 bitangent = -cross(tangent3, normal);
vec3 t = normalize(vec3(push.model * vec4(tangent3, 0.0)));
vec3 b = normalize(vec3(push.model * vec4(bitangent, 0.0)));
vec3 n = normalize(vec3(push.model * vec4(normal_wld, 0.0)));
vec3 n = normalize(vec3(push.model * vec4(normal, 0.0)));
tbn = mat3(t, b, n);
}

Binary file not shown.