Sign in to follow this  

Vertex skinning - calculating transform matrix

This topic is 2593 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

I'm embarrassed to ask this, but I've had a surprisingly hard time trying
to implement basic vertex skinning. I use Ogre's mesh and skeleton (xml)
files and have assured that they are properly parsed, yet all I get when
trying to animate the model is polygon soup.

I use this working code for debug rendering the animated skeleton:
void Bone::render ( const D3DXMATRIX& top )
{
D3DXMATRIX temp = animatedMatrix *bindMatrix *top;

D3DXVECTOR3 a; a.x = top._41; a.y = top._42; a.z = top._43;
D3DXVECTOR3 b; b.x = temp._41; b.y = temp._42; b.z = temp._43;
Debug::instance->addLine ( a, b );

std::vector<Bone*>::iterator it;
for ( it = children.begin (); it != children.end (); ++it )
(*it)->render ( temp );
}





... and this is the part that I assume is wrong(?). This is where I
compute the skinMatrix that will be sent to the shader. I've tried
countless of variations but without luck and now my brain is beginning
to hurt :(
void Bone::update ( const D3DXMATRIX& top )
{
skinMatrix = inverseBindMatrix *animatedMatrix *bindMatrix *top;
D3DXMATRIX newTop = animatedMatrix *bindMatrix *top;

std::vector<Bone*>::iterator it;
for ( it = children.begin (); it != children.end (); ++it )
(*it)->update ( newTop );
}





My vertex shader
PS_INPUT vertexShader ( VS_INPUT input )
{
PS_INPUT output = (PS_INPUT)0;

// skinning
float3 pos = float4 ( input.Pos, 1 );
float3 nor = float4 ( input.Nor, 0 );
float3 P = 0.0f;
float3 N = 0.0f;

[unroll]
for ( int i = 0; i < 4; ++i )
{
// InverseBind [ input.BoneI [0] ]
P += input.BoneW[i] *mul ( pos, SkinMatrices[input.BoneI[i]] );
N += input.BoneW[i] *mul ( nor, SkinMatrices[input.BoneI[i]] );
}
N = normalize ( N );

// standard stuff
output.Pos = mul ( float4 ( P, 1 ), Combined );
output.PosW= mul ( float4 ( P, 1 ), World ).xyz;
output.Nor = mul ( float4 ( N, 0 ), World ).xyz;
output.Tex = input.Tex;

return output;
}





[Edited by - MZP on November 11, 2010 4:37:30 PM]

Share this post


Link to post
Share on other sites

This topic is 2593 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this