# vertex structure for skinned mesh

## Recommended Posts

Icebone1000    1958
Hi, Im starting on skeletal animation, and not sure how I should store skin info, is this ok?:

struct vposnormaltexskin{

XMFLOAT4 pos;
XMFLOAT4 normal;
XMFLOAT2 tex; //uv
//skeletal animation data:
UINT boneIDs[5];
FLOAT skinWeights[5];

};

So boneIDs are the index on an array of matrices that specifies bone transformations(so a vertex can be tied up to 5 bones), Im not sure if thats a good way to do this..

I will probaly have one of those arrays per animation keyframe, and pass it to shader, dont know how yet( interpolation is also donne on GPU or I pass the matrix of bones alredy interpolated?)..

What do you think?

##### Share on other sites
remigius    1172
The struct looks fairly standard to me, only the typical number of bone influences seems to be 4 per vertex, allowing you to use float4's in your shader's vertex structs. I'm getting the impression you're unsure about how this is meant to work though; I apologize if I misunderstood you, but the basic idea is that you have your bone data as shader constants:

float4x4 Bones[50];

These are typically constructed from the animation keyframes, made absolute (so you don't need to walk up the bone hierarchy in your shader) and set on the shader each frame. Then the model is rendered with the bone matrices for the current animation frame, like this:

// for each vertex, ie in a vertex shader (the input variable is the vertex):    float4x4 skinTransform = 0;        skinTransform += Bones[input.BoneIndices.x] * input.BoneWeights.x;    skinTransform += Bones[input.BoneIndices.y] * input.BoneWeights.y;    skinTransform += Bones[input.BoneIndices.z] * input.BoneWeights.z;    skinTransform += Bones[input.BoneIndices.w] * input.BoneWeights.w;        // Skin the vertex position.    float4 position = mul(input.Position, skinTransform);    // Skin the vertex normal, then compute lighting.    float3 normal = normalize(mul(input.Normal, skinTransform));

This will give you the skinned vertex position and normal in world space.

##### Share on other sites
Icebone1000    1958
Very straightforward, I get it, thanks.

Im curious with one thing..Its comomn to find resources saying that when you work with quaternions you need to convert it to matrix because its how apis(opengl and d3d) works.. This isnt true anymore right? Theres any problem with making quaternion multiplication on the shader? Whats preferable?