1#ifdef USE_HWSKINNING
2
3#ifndef NUM_BONES
4#error A required pre-processor define "NUM_BONES" is not set!
5#endif
6
7attribute vec4 inBoneWeight;
8attribute vec4 inBoneIndices;
9uniform mat4 m_BoneMatrices[NUM_BONES];
10
11void Skinning_Compute(inout vec4 position, inout vec4 normal){
12    vec4 index  = inBoneIndices;
13    vec4 weight = inBoneWeight;
14
15    vec4 newPos    = vec4(0.0);
16    vec4 newNormal = vec4(0.0);
17
18    for (float i = 0.0; i < 4.0; i += 1.0){
19        mat4 skinMat = m_BoneMatrices[int(index.x)];
20        newPos    += weight.x * (skinMat * position);
21        newNormal += weight.x * (skinMat * normal);
22        index = index.yzwx;
23        weight = weight.yzwx;
24    }
25
26    position = newPos;
27    normal = newNormal;
28}
29
30#else
31
32void Skinning_Compute(inout vec4 position, inout vec4 normal){
33   // skinning disabled, leave position and normal unaltered
34}
35
36#endif