# Linear Blend Skinning

Linear blend skinning is the idea of transforming vertices inside a single mesh by a (blend) of multiple transforms. Each transform is the concatenation of a "bind matrix" that takes the vertex into the local space of a given "bone" and a transformation matrix that moves from that bone's local space to a new position.

In other words, you will be using a shader that looks something like:

``````#version 330
uniform mat4 mvp;
uniform mat4x3 bones[40]; //make sure this is more than the number of bones
in vec4 Position;
in vec3 Normal;
in vec4 Color;
in vec2 TexCoord;
in vec4 BoneWeights;
in uvec4 BoneIndices;
out vec3 normal;
out vec4 color;
out vec2 texCoord;
void main() {
vec3 skinned =
BoneWeights.x * ( bones[ BoneIndices.x ] * Position)
+ BoneWeights.y * ( bones[ BoneIndices.y ] * Position)
+ BoneWeights.z * ( bones[ BoneIndices.z ] * Position)
+ BoneWeights.w * ( bones[ BoneIndices.w ] * Position);
gl_Position = mvp * vec4(skinned, 1.0);

vec3 skinned_normal = inverse(transpose(
BoneWeights.x * mat3(bones[ BoneIndices.x ])
+ BoneWeights.y * mat3(bones[ BoneIndices.y ])
+ BoneWeights.z * mat3(bones[ BoneIndices.z ])
+ BoneWeights.w * mat3(bones[ BoneIndices.w ]) )) * Normal;
normal = skinned_normal;

color = Color;

texCoord = TexCoord;
}``````