I have a quick question on matrix palette skinning. I have the following shared which handles my skinning as expected. It skins the vertex to each bone, then multiplies the skinned position by weight:
#version 330 core
uniform mat4 view;
uniform mat4 model;
uniform mat4 projection;
uniform mat4 skeleton[120];
in vec3 position;
in vec2 texcoord;
in ivec4 bones;
in vec4 weights;
out vec2 uv;
void main() {
vec4 pos = vec4(position.x, position.y, position.z, 1.0);
vec4 vertex = vec4(0.0f, 0.0f, 0.0f, 0.0f);
vertex += (skeleton[bones.x] * pos) * weights.x;
vertex += (skeleton[bones.y] * pos) * weights.y;
vertex += (skeleton[bones.z] * pos) * weights.z;
vertex += (skeleton[bones.w] * pos) * weights.w;
vertex.w = 1.0f;
gl_Position = projection * view * model * vertex;
uv = texcoord;
}
Whats confusing me is i can change this to scale & add the matrices, which yields the exact same results?!?
#version 330 core
uniform mat4 view;
uniform mat4 model;
uniform mat4 projection;
uniform mat4 skeleton[120]; // matrix pallete for skinning
in vec3 position;
in vec2 texcoord;
in ivec4 bones;
in vec4 weights;
out vec2 uv;
void main() {
vec4 pos = vec4(position.x, position.y, position.z, 1.0);
mat4 pallete = skeleton[bones.x] * weights.x;
pallete += skeleton[bones.y] * weights.y;
pallete += skeleton[bones.z] * weights.z;
pallete += skeleton[bones.w] * weights.w;
gl_Position = projection * view * model * pallete * pos;
uv = texcoord;
}
I don't understand why the second version woks at all. I assumed since the upper 3x3 matrix contains both scale and rotation, doing this would introduce artifacts, but it doesn't....
Does anyone have any insight into why this might be? is blending matrices in this fashion safe / acceptable?