Simple normal map implementation

This commit is contained in:
2020-10-26 18:15:39 +01:00
parent 9687f5ec89
commit 38ea41b550
6 changed files with 56 additions and 24 deletions

View File

@@ -16,21 +16,35 @@ layout(binding = 0) uniform ObjectUniformData {
layout(location = 0) in vec3 position;
layout(location = 1) in vec2 uv;
layout(location = 2) in vec3 normal;
layout(location = 3) in ivec4 bone_index;
layout(location = 4) in vec4 bone_weight;
layout(location = 3) in vec4 tangent;
layout(location = 4) in ivec4 bone_index;
layout(location = 5) in vec4 bone_weight;
layout(location = 0) out vec2 tex_coords;
layout(location = 1) out vec3 normal_wld;
layout(location = 2) out vec3 position_wld;
layout(location = 3) out mat3 tbn;
out gl_PerVertex {
vec4 gl_Position;
};
void main() {
// Vertex position
gl_Position = ubo.projection * ubo.view * push.model * vec4(position, 1.0);
position_wld = vec3(push.model * vec4(position, 1.0));
// Just interpolate UV coords, no transformation needed
tex_coords = uv;
position_wld = vec3(push.model * vec4(position, 1.0));
// This should probably be in object space? idk
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 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)));
tbn = mat3(t, b, n);
}