# How to build Skinning Matrix with Blended.

## Recommended Posts

Hi!

So I'm struggling with this problem about skinning.

Let's say you have a vertex that is skinning blended to 4 bones. How do you build the bone matrix / transform in vertex shader?

Can you make a 'total' bone matrix based on the sum of bone matrices according to their weights together. Like in Urho3D:

//Skin() Method
void Skin(inout VertexShaderInput input, uniform int boneCount)
{
float4x4 skinning = 0;
[unroll]
for (int i = 0; i < boneCount; i++)
{
skinning += Bones[input.Indices[i]] * input.Weights[i];
}
input.Position = mul(input.Position, skinning);
}

Or what I see in every topic on gamedev, where you multiply the bone matrix for each vector position multiplied by the weight, like here:

https://www.gamedev.net/forums/topic/549125-hlsl-skinning/

VS_OUTPUT_BASE Out = (VS_OUTPUT_BASE) 0;

float3 Pos = 0.0f;
float4 src = float4(inPos.xyz,1.0f);

Pos += mul(u_pose[int(indicies.x)] ,src) *  weights.x/255;
Pos += mul(u_pose[int(indicies.y)] ,src) *  weights.y/255;
Pos += mul(u_pose[int(indicies.z)] ,src) *  weights.z/255;
Pos += mul(u_pose[int(indicies.w)] ,src) *  weights.w/255;

Out.Pos  = mul(u_model_view_proj_matrix,float4(Pos,1.0f) );

I think the first method is right, but I'm still curious. I think it's right because with the second method it's impossible to build the vertex buffer with vector positions that are multiplied by the inverse of the bind pose bone matrix, but it's still weird that it's out there being discussed.

## Create an account

Register a new account

1. 1
2. 2
3. 3
Rutin
13
4. 4
5. 5

• 26
• 10
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633695
• Total Posts
3013374
×