• 14
• 12
• 9
• 10
• 9

# Skinned Models are Inverted

This topic is 2899 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Some part of my skinning code is causing my models to seem to flip similar to flipping the winding of the model but it is also affecting the models normals so just flipping the winding for skinned models still causes lighting problems. Example: I've used the Skinned model as a base but have added a few things such as blending between keyframes and some code that reduces the matrix size so I can have more bones in the shader. However, since the start I've had backface culling off and hadn't implemented anything using normals so there was no way of knowing about this problem and whether it has been there from the start or its from my changes. This is the code that converts the skinningData into 3x3 Matrixes:
Matrix[] bones = animationPlayer.GetSkinTransforms();

Vector4[] values = new Vector4[bones.Length * 3];
for (int i = 0; i < bones.Length; i++)
{
values[i * 3 + 0] = new Vector4(bones.M11, bones.M21, bones.M31, bones.M41);
values[i * 3 + 1] = new Vector4(bones.M12, bones.M22, bones.M32, bones.M42);
values[i * 3 + 2] = new Vector4(bones.M13, bones.M23, bones.M33, bones.M43);
}

effect.Parameters["g_bones"].SetValue(values);

float4x4 skinTransform = 0;

skinTransform += RebuildSkinMatrix(input.BoneIndices.x * 3) * input.BoneWeights.x;
skinTransform += RebuildSkinMatrix(input.BoneIndices.y * 3) * input.BoneWeights.y;
skinTransform += RebuildSkinMatrix(input.BoneIndices.z * 3) * input.BoneWeights.z;
skinTransform += RebuildSkinMatrix(input.BoneIndices.w * 3) * input.BoneWeights.w;

float4 position = mul(skinTransform, input.Position);
output.Position = mul(mul(position, g_matView), g_matProj);

output.tangentToWorld[0] = mul(input.Tangent, skinTransform);
output.tangentToWorld[1] = mul(input.Binormal, skinTransform);
output.tangentToWorld[2] = mul(input.Normal, skinTransform);
That RebuildSkinMatrix function is:
float4x4 RebuildSkinMatrix(float index)
{
return float4x4(
g_bones[index],
g_bones[index + 1],
g_bones[index + 2],
float4(0, 0, 0, 1));
}
Any help would be greatly appreciated, thanks.