Files
rust-engine/shaders/triangle.vert

50 lines
1.4 KiB
GLSL

#version 450
#extension GL_ARB_separate_shader_objects : enable
layout(push_constant) uniform PushConstants {
mat4 model;
} push;
layout(binding = 0) uniform ObjectUniformData {
mat4 view;
mat4 projection;
float time;
vec3 light_position;
vec3 camera_position;
} ubo;
layout(location = 0) in vec3 position;
layout(location = 1) in vec2 uv;
layout(location = 2) in vec3 normal;
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;
// 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);
}