skinned.vert 671 B

12345678910111213141516171819202122
  1. uniform mat4 mvp;
  2. uniform mat4 boneMatrices[16];
  3. attribute vec3 position;
  4. attribute vec3 normal;
  5. attribute vec4 boneIndices; // should be ivec4
  6. attribute vec3 boneWeights;
  7. varying vec3 vertexNormal;
  8. void main() {
  9. float fourthBoneWeight = 1.0 - boneWeights[0] - boneWeights[1] - boneWeights[2];
  10. mat4 boneMatrix = boneWeights[0] * boneMatrices[int(boneIndices.x)];
  11. boneMatrix += boneWeights[1] * boneMatrices[int(boneIndices.y)];
  12. boneMatrix += boneWeights[2] * boneMatrices[int(boneIndices.z)];
  13. boneMatrix += fourthBoneWeight * boneMatrices[int(boneIndices.w)];
  14. vertexNormal = mat3(boneMatrix) * normal;
  15. gl_Position = mvp * boneMatrix * vec4(position, 1.0);
  16. }