KP3Dii/Data/resources/shaders/.kp3d/map_v.glsl

48 lines
1.2 KiB
GLSL
Raw Normal View History

2024-07-22 07:48:42 +00:00
#version 330 core
uniform mat4 u_mvp;
layout (location = 0) in vec3 position;
layout (location = 1) in vec3 normal;
layout (location = 2) in vec2 texcoord;
2024-07-29 22:06:31 +00:00
layout (location = 3) in vec3 tangent;
layout (location = 4) in vec3 bitangent;
2024-08-10 09:03:37 +00:00
layout (location = 5) in uvec4 bone_ids; // Skinning (experimental)
layout (location = 6) in vec4 weights;
2024-07-22 07:48:42 +00:00
out vec3 v_position;
out vec3 v_normal;
out vec3 v_proj_normal;
out vec2 v_texcoord;
2024-07-29 22:06:31 +00:00
out vec3 v_tangent;
out vec3 v_bitangent;
2024-07-22 07:48:42 +00:00
out float v_id;
2024-08-10 21:14:28 +00:00
const int MAX_BONES = 96;
2024-08-10 09:03:37 +00:00
uniform mat4 u_bones[MAX_BONES];
uniform int u_has_bones;
2024-07-22 07:48:42 +00:00
void main()
{
v_position = position;
v_normal = normal;
v_proj_normal = vec4(u_mvp * vec4(normal, 1.0)).xyz;
2024-07-31 07:03:41 +00:00
v_texcoord = vec2(texcoord.x, -texcoord.y);
2024-07-29 22:06:31 +00:00
v_tangent = tangent;
v_bitangent = bitangent;
2024-07-22 07:48:42 +00:00
v_id = gl_VertexID;
2024-08-10 09:03:37 +00:00
if (u_has_bones == 1) {
mat4 bone_transform = u_bones[bone_ids[0]] * weights[0];
bone_transform += u_bones[bone_ids[1]] * weights[1];
bone_transform += u_bones[bone_ids[2]] * weights[2];
bone_transform += u_bones[bone_ids[3]] * weights[3];
gl_Position = u_mvp * (bone_transform * vec4(v_position, 1.0));
return;
}
2024-07-22 07:48:42 +00:00
gl_Position = u_mvp * vec4(v_position, 1.0);
2024-07-29 22:06:31 +00:00
}