|
@@ -1,55 +1,66 @@
|
|
- #ifdef NUM_BONES
|
|
|
|
|
|
+#ifdef NUM_BONES
|
|
|
|
+
|
|
|
|
+#if NUM_BONES < 1 || NUM_BONES > 255
|
|
|
|
+#error NUM_BONES must be between 1 and 255.
|
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
+#define NUM_WEIGHTS_PER_VERT 4
|
|
|
|
|
|
attribute vec4 inBoneWeight;
|
|
attribute vec4 inBoneWeight;
|
|
attribute vec4 inBoneIndex;
|
|
attribute vec4 inBoneIndex;
|
|
uniform mat4 m_BoneMatrices[NUM_BONES];
|
|
uniform mat4 m_BoneMatrices[NUM_BONES];
|
|
|
|
|
|
void Skinning_Compute(inout vec4 position){
|
|
void Skinning_Compute(inout vec4 position){
|
|
- #if NUM_WEIGHTS_PER_VERT == 1
|
|
|
|
|
|
+#if NUM_WEIGHTS_PER_VERT == 1
|
|
position = m_BoneMatrices[int(inBoneIndex.x)] * position;
|
|
position = m_BoneMatrices[int(inBoneIndex.x)] * position;
|
|
- #else
|
|
|
|
|
|
+#else
|
|
mat4 mat = mat4(0.0);
|
|
mat4 mat = mat4(0.0);
|
|
mat += m_BoneMatrices[int(inBoneIndex.x)] * inBoneWeight.x;
|
|
mat += m_BoneMatrices[int(inBoneIndex.x)] * inBoneWeight.x;
|
|
mat += m_BoneMatrices[int(inBoneIndex.y)] * inBoneWeight.y;
|
|
mat += m_BoneMatrices[int(inBoneIndex.y)] * inBoneWeight.y;
|
|
mat += m_BoneMatrices[int(inBoneIndex.z)] * inBoneWeight.z;
|
|
mat += m_BoneMatrices[int(inBoneIndex.z)] * inBoneWeight.z;
|
|
mat += m_BoneMatrices[int(inBoneIndex.w)] * inBoneWeight.w;
|
|
mat += m_BoneMatrices[int(inBoneIndex.w)] * inBoneWeight.w;
|
|
position = mat * position;
|
|
position = mat * position;
|
|
- #endif
|
|
|
|
|
|
+#endif
|
|
}
|
|
}
|
|
|
|
|
|
void Skinning_Compute(inout vec4 position, inout vec3 normal){
|
|
void Skinning_Compute(inout vec4 position, inout vec3 normal){
|
|
- #if NUM_WEIGHTS_PER_VERT == 1
|
|
|
|
|
|
+#if NUM_WEIGHTS_PER_VERT == 1
|
|
position = m_BoneMatrices[int(inBoneIndex.x)] * position;
|
|
position = m_BoneMatrices[int(inBoneIndex.x)] * position;
|
|
normal = (mat3(m_BoneMatrices[int(inBoneIndex.x)][0].xyz,
|
|
normal = (mat3(m_BoneMatrices[int(inBoneIndex.x)][0].xyz,
|
|
m_BoneMatrices[int(inBoneIndex.x)][1].xyz,
|
|
m_BoneMatrices[int(inBoneIndex.x)][1].xyz,
|
|
m_BoneMatrices[int(inBoneIndex.x)][2].xyz) * normal);
|
|
m_BoneMatrices[int(inBoneIndex.x)][2].xyz) * normal);
|
|
- #else
|
|
|
|
|
|
+#else
|
|
mat4 mat = mat4(0.0);
|
|
mat4 mat = mat4(0.0);
|
|
mat += m_BoneMatrices[int(inBoneIndex.x)] * inBoneWeight.x;
|
|
mat += m_BoneMatrices[int(inBoneIndex.x)] * inBoneWeight.x;
|
|
mat += m_BoneMatrices[int(inBoneIndex.y)] * inBoneWeight.y;
|
|
mat += m_BoneMatrices[int(inBoneIndex.y)] * inBoneWeight.y;
|
|
mat += m_BoneMatrices[int(inBoneIndex.z)] * inBoneWeight.z;
|
|
mat += m_BoneMatrices[int(inBoneIndex.z)] * inBoneWeight.z;
|
|
mat += m_BoneMatrices[int(inBoneIndex.w)] * inBoneWeight.w;
|
|
mat += m_BoneMatrices[int(inBoneIndex.w)] * inBoneWeight.w;
|
|
position = mat * position;
|
|
position = mat * position;
|
|
- normal = (mat3(mat[0].xyz,mat[1].xyz,mat[2].xyz) * normal);
|
|
|
|
- #endif
|
|
|
|
|
|
+
|
|
|
|
+ mat3 rotMat = mat3(mat[0].xyz, mat[1].xyz, mat[2].xyz);
|
|
|
|
+ normal = rotMat * normal;
|
|
|
|
+#endif
|
|
}
|
|
}
|
|
|
|
|
|
-void Skinning_Compute(inout vec4 position, inout vec4 tangent, inout vec3 normal){
|
|
|
|
- #if NUM_WEIGHTS_PER_VERT == 1
|
|
|
|
|
|
+void Skinning_Compute(inout vec4 position, inout vec3 tangent, inout vec3 normal){
|
|
|
|
+#if NUM_WEIGHTS_PER_VERT == 1
|
|
position = m_BoneMatrices[int(inBoneIndex.x)] * position;
|
|
position = m_BoneMatrices[int(inBoneIndex.x)] * position;
|
|
tangent = m_BoneMatrices[int(inBoneIndex.x)] * tangent;
|
|
tangent = m_BoneMatrices[int(inBoneIndex.x)] * tangent;
|
|
normal = (mat3(m_BoneMatrices[int(inBoneIndex.x)][0].xyz,
|
|
normal = (mat3(m_BoneMatrices[int(inBoneIndex.x)][0].xyz,
|
|
m_BoneMatrices[int(inBoneIndex.x)][1].xyz,
|
|
m_BoneMatrices[int(inBoneIndex.x)][1].xyz,
|
|
m_BoneMatrices[int(inBoneIndex.x)][2].xyz) * normal);
|
|
m_BoneMatrices[int(inBoneIndex.x)][2].xyz) * normal);
|
|
- #else
|
|
|
|
|
|
+#else
|
|
mat4 mat = mat4(0.0);
|
|
mat4 mat = mat4(0.0);
|
|
mat += m_BoneMatrices[int(inBoneIndex.x)] * inBoneWeight.x;
|
|
mat += m_BoneMatrices[int(inBoneIndex.x)] * inBoneWeight.x;
|
|
mat += m_BoneMatrices[int(inBoneIndex.y)] * inBoneWeight.y;
|
|
mat += m_BoneMatrices[int(inBoneIndex.y)] * inBoneWeight.y;
|
|
mat += m_BoneMatrices[int(inBoneIndex.z)] * inBoneWeight.z;
|
|
mat += m_BoneMatrices[int(inBoneIndex.z)] * inBoneWeight.z;
|
|
mat += m_BoneMatrices[int(inBoneIndex.w)] * inBoneWeight.w;
|
|
mat += m_BoneMatrices[int(inBoneIndex.w)] * inBoneWeight.w;
|
|
position = mat * position;
|
|
position = mat * position;
|
|
- tangent = mat * tangent;
|
|
|
|
- normal = (mat3(mat[0].xyz,mat[1].xyz,mat[2].xyz) * normal);
|
|
|
|
- #endif
|
|
|
|
|
|
+
|
|
|
|
+ mat3 rotMat = mat3(mat[0].xyz, mat[1].xyz, mat[2].xyz);
|
|
|
|
+ tangent = rotMat * tangent;
|
|
|
|
+ normal = rotMat * normal;
|
|
|
|
+#endif
|
|
}
|
|
}
|
|
|
|
+
|
|
#endif
|
|
#endif
|