Jump to content
  • Advertisement
Sign in to follow this  

vertex structure for skinned mesh

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

struct vposnormaltexskin{

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 this post

Link to post
Share on other sites
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 this post

Link to post
Share on other sites
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?

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!