Hello,
I have a Problem with GPU Skinning, I load from a COLLADA File my object with the vertices and the weights and bone indices for it and the bones with the matrices.
For every vertex I choose 4 weights and 4 bone indices.
For every non skin vertex i choose by the weights 1 0 0 0 and bone indices 0 0 0 0 (In the Bone Matrices Array is index 0 a Matrix Idetity)
And i check up if all weights values together is always 1 or i calculate it to 1.
So far so good, my Shader looks like this:
bool HasBones;
matrix BoneMatrices[256];
struct Vertex
{
float3 Position : POSITION;
float3 Normal : NORMAL;
float2 UV : TEXCOORD0;
float3 Tangent : TANGENT;
float4 Weights : WEIGHTS;
int4 BoneIndices : BONEINDICES;
};
float4 ApplyBoneTransform(Vertex input, float4 value)
{
if(HasBones)
{
float4x4 skinTransform = (float4x4)0;
skinTransform += BoneMatrices[input.BoneIndices.x] * input.Weights.x;
skinTransform += BoneMatrices[input.BoneIndices.y] * input.Weights.y;
skinTransform += BoneMatrices[input.BoneIndices.z] * input.Weights.z;
skinTransform += BoneMatrices[input.BoneIndices.w] * input.Weights.w;
float4 position = mul(value, skinTransform);
return position;
}
else
return value;
}
Pixel vertexShader(Vertex input)
{
Pixel result = (Pixel) 0;
float4 posWorld = mul(ApplyBoneTransform(input, float4(input.Position.xyz, 1.0f)), World);
result.Position = mul(mul(posWorld, View), Projection);
result.Normal = normalize(mul(ApplyBoneTransform(input, float4(input.Normal.xyz, 1.0f)), WorldIT));
result.UV = input.UV;
result.View = ViewInverse[3] - mul(float4(input.Position.xyz, 1.0f), World);
result.Tangent = normalize(mul(ApplyBoneTransform(input, float4(input.Tangent.xyz, 1.0f)), WorldIT).xyz);
result.Binormal = normalize(cross(input.Normal, input.Tangent));
return result;
}
And if i set HasBones to true, my object will not draw right anymore, i only see two dark triangles
I believe it depends on the bone matrices i load from the controller_lib of the COLLADA File and send it to the BoneMatrices in the shader + at the index 0 the Matrix Idetity.
Has anyone an Idea what I make wrong and could help and explain me it?
And i upload to this post the Collada file and images of the object draw in HasBones = false and HasBones = true
Greets
Benajmin