Files
gpu-renderer/model-vert.glsl
T

37 lines
948 B
GLSL

#version 450
layout(location = 0) in vec3 position;
layout(location = 1) in vec3 normal;
layout(location = 2) in uvec4 bone_indices;
layout(location = 3) in vec4 weights;
layout(location = 0) out vec3 frag_normal;
layout(location = 1) out vec4 light_pos;
layout(push_constant) uniform vps_t {
mat4 vp;
mat4 light_vp;
} vps;
layout(binding = 0) uniform transform_t {
mat4 model;
} transform;
layout(binding = 1) uniform skeleton_t {
mat4 matrices[32];
} bones;
void main() {
const mat4 skinning_matrix
= weights.x * bones.matrices[bone_indices.x]
+ weights.y * bones.matrices[bone_indices.y]
+ weights.z * bones.matrices[bone_indices.z]
+ weights.w * bones.matrices[bone_indices.w];
const vec4 world_pos
= transform.model * skinning_matrix * vec4(position, 1.0);
gl_Position = vps.vp * world_pos;
frag_normal = transpose(
inverse(mat3(transform.model * skinning_matrix))) * normal;
light_pos = vps.light_vp * world_pos;
}