55 lines
1.2 KiB
GLSL
55 lines
1.2 KiB
GLSL
#version 450 core
|
|
layout (location = 0) in vec3 aPos;
|
|
layout (location = 1) in vec3 aNormal;
|
|
layout (location = 2) in vec2 aTexCoords;
|
|
layout (location = 3) in ivec4 boneIds;
|
|
layout (location = 4) in vec4 weights;
|
|
|
|
out vec2 TexCoords;
|
|
out vec3 WorldPos;
|
|
out vec3 Normal;
|
|
|
|
uniform mat4 model;
|
|
uniform mat4 view;
|
|
uniform mat4 projection;
|
|
|
|
const int MAX_BONES = 100;
|
|
const int MAX_BONE_INFLUENCE = 4;
|
|
layout (std140, binding = 1) uniform FinalBonesMatrices
|
|
{
|
|
mat4 finalBonesMatrices[MAX_BONES];
|
|
};
|
|
|
|
void main()
|
|
{
|
|
vec4 totalPosition = vec4(0.0f);
|
|
vec3 totalNormal = vec3(0);
|
|
int boneCount = 0;
|
|
for(int i = 0 ; i < MAX_BONE_INFLUENCE ; i++)
|
|
{
|
|
if(boneIds[i] == -1)
|
|
continue;
|
|
if(boneIds[i] >= MAX_BONES)
|
|
{
|
|
totalPosition = vec4(aPos,1.0f);
|
|
break;
|
|
}
|
|
boneCount++;
|
|
vec4 localPosition = finalBonesMatrices[boneIds[i]] * vec4(aPos,1.0f);
|
|
totalPosition += localPosition * weights[i];
|
|
vec3 localNormal = mat3(finalBonesMatrices[boneIds[i]]) * aNormal;
|
|
totalNormal += localNormal * weights[i];
|
|
}
|
|
|
|
if(boneCount == 0)
|
|
{
|
|
totalPosition = vec4(aPos, 1);
|
|
totalNormal = vec3(aNormal);
|
|
}
|
|
|
|
TexCoords = aTexCoords;
|
|
WorldPos = vec3(model * totalPosition);
|
|
Normal = mat3(model) * totalNormal;
|
|
|
|
gl_Position = projection * view * vec4(WorldPos, 1.0);
|
|
} |