in vec3 unscaledNormal;
in vec2 vTexCoord;
+in ivec4 boneIds;
+in vec4 boneWeights;
+
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
+uniform mat4 bones[16 + 1];
+
out vec3 normal;
out vec2 texCoords;
void main() {
texCoords = vTexCoord;
- worldPos = vec3(model * vec4(pos, 1.f));
+ mat4 boneTrans = bones[boneIds.x] * boneWeights.x;
+ boneTrans += bones[boneIds.y] * boneWeights.y;
+ boneTrans += bones[boneIds.z] * boneWeights.z;
+ boneTrans += bones[boneIds.w] * boneWeights.w;
+
+ mat4 bonedModel = model * boneTrans;
+
+ worldPos = vec3(bonedModel * vec4(pos, 1.f));
- normal = mat3(transpose(inverse(model))) * unscaledNormal;
+ normal = mat3(transpose(inverse(bonedModel))) * unscaledNormal;
- gl_Position = projection * view * model * vec4(pos, 1.f);
+ gl_Position = projection * view * bonedModel * vec4(pos, 1.f);
}