skinned.vert 765 B

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