• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
kgstation

Questions about offset matrix in skinned mesh

8 posts in this topic

I'm working on a skinned mesh demo.

And I have successfully export my own mesh from 3ds max.

But in my meshviewer program,only first frame is correct.

 

Like this,the right image is the correct animation, the cube in left image means the bone

temp.png

I have got all bone matrix saved in mBoneTransforms[m][n].The m indicate m-th bone, the n means the n-th frame, each data in  mBoneTransforms is a matrix

 

following is my code:

The drawCube(float4x4 world) method is used to drawing bones.And this completely represent the animation correctly.

So my bone animation is correctly, skinned animation is wrong

static int frameCount = 0;
for (int i = 0; i < mYHMMesh.boneInfo.BoneCount; i++)
{
	XMFLOAT4X4 boneInv = floatToXMFLOAT(mBoneTransforms[i][0]);
	XMStoreFloat4x4(&boneInv, XMMatrixInverse(NULL, XMLoadFloat4x4(&boneInv)));
	//boneInv is what I think offset matrix, is it wrong?
	m_constantBufferData.boneTransform[i] = mul(mBoneTransforms[i][frameCount % 120], XMFLOATTofloat4x4(boneInv));
	//drawBone(mBoneTransforms[i][frameCount % 120);
}
frameCount++;
//Draw mesh
//HLSL Code
PixelShaderInput SimpleVertexShader(VertexShaderInput input)
{
    PixelShaderInput vertexShaderOutput;

    float weights[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
    weights[0] = input.Weights.x;
    weights[1] = input.Weights.y;
    weights[2] = input.Weights.z;
    weights[3] = 1.0f - weights[0] - weights[1] - weights[2];
	
    float4 pos = float4(input.pos, 1.0f);
    float4 norm = float4(normalize(input.norm), 0.0f);
    for (int i = 0; i < 4; ++i)
    {
        pos += weights[i] * mul(pos, gBoneTransform[input.BoneIndices[i]]);
	norm += weights[i] * mul(norm, gBoneTransform[input.BoneIndices[i]]);
    }

    pos = mul(pos, model);
    pos = mul(pos, view);
    pos = mul(pos, projection);
    norm = mul(norm, model);

    vertexShaderOutput.pos = pos;
    vertexShaderOutput.tex = input.tex;
    vertexShaderOutput.norm = normalize(norm.xyz);
    return vertexShaderOutput;
}
Can anyone help me?
Any help would be appreciated.
Thank you!
Edited by kgs
0

Share this post


Link to post
Share on other sites

Can you show us some images of what you are seeing?  That might help to diagnose the problem...

 

What are you seeing on the incorrect frames?  Have you tried to debug the issue in PIX/Graphics Debugger yet?

0

Share this post


Link to post
Share on other sites

Can you show us some images of what you are seeing?  That might help to diagnose the problem...

 

What are you seeing on the incorrect frames?  Have you tried to debug the issue in PIX/Graphics Debugger yet?

Thanks for your reply, I have add compare image to my post.

0

Share this post


Link to post
Share on other sites

How many bones per vertex are you working with?  In your code you are declaring 5 weights (where the fifth one is the remaining weight left over from the others) but when you apply the weights you are only applying the first 4 weights (looping from 0 to less than 4).  Is this correct?

 

If not, it could explain why the skeleton is correct but the vertices don't seem to be following them.

0

Share this post


Link to post
Share on other sites

How many bones per vertex are you working with?  In your code you are declaring 5 weights (where the fifth one is the remaining weight left over from the others) but when you apply the weights you are only applying the first 4 weights (looping from 0 to less than 4).  Is this correct?

 

If not, it could explain why the skeleton is correct but the vertices don't seem to be following them.

My mistake, and now I have fixed the bug in hlsl code, but it seem not effect what I have seem.Is it could be possible that the bone number per vertex working with is not enough?

0

Share this post


Link to post
Share on other sites

 
float4 pos = float4(input.pos, 1.0f);
float4 norm = float4(normalize(input.norm), 0.0f);
for (int i = 0; i < 4; ++i)
{
    pos += weights[i] * mul(pos, gBoneTransform[input.BoneIndices[i]]);
    norm += weights[i] * mul(norm, gBoneTransform[input.BoneIndices[i]]);
}

This doesn't look correct to me either - you are modifying the pos variable in the same line that it is being used to update the current position.  Instead, you do something more like this:

float4 pos = float4(input.pos, 1.0f);
float4 skinnedPos = float4( 0.0f, 0.0f, 0.0f, 0.0f );
float4 norm = float4(normalize(input.norm), 0.0f);
for (int i = 0; i < 4; ++i)
{
    skinnedPos += weights[i] * mul(pos, gBoneTransform[input.BoneIndices[i]]);
    norm += weights[i] * mul(norm, gBoneTransform[input.BoneIndices[i]]);
}

skinnedPos.w = 1.0f;

The way you have it now, you would be starting with a different position as the input to each of the weighted transformed positions, which isn't correct.  Instead you should retain the input position and accumulate the transformed positions into another variable.

Edited by Jason Z
0

Share this post


Link to post
Share on other sites

 


 
float4 pos = float4(input.pos, 1.0f);
float4 norm = float4(normalize(input.norm), 0.0f);
for (int i = 0; i < 4; ++i)
{
    pos += weights[i] * mul(pos, gBoneTransform[input.BoneIndices[i]]);
    norm += weights[i] * mul(norm, gBoneTransform[input.BoneIndices[i]]);
}

This doesn't look correct to me either - you are modifying the pos variable in the same line that it is being used to update the current position.  Instead, you do something more like this:

float4 pos = float4(input.pos, 1.0f);
float4 skinnedPos = float4( 0.0f, 0.0f, 0.0f, 0.0f );
float4 norm = float4(normalize(input.norm), 0.0f);
for (int i = 0; i < 4; ++i)
{
    skinnedPos += weights[i] * mul(pos, gBoneTransform[input.BoneIndices[i]]);
    norm += weights[i] * mul(norm, gBoneTransform[input.BoneIndices[i]]);
}

skinnedPos.w = 1.0f;

The way you have it now, you would be starting with a different position as the input to each of the weighted transformed positions, which isn't correct.  Instead you should retain the input position and accumulate the transformed positions into another variable.

 

You are right,thank you very much.Now my skinned animation demo is almost done.

0

Share this post


Link to post
Share on other sites

Sorry for bother you again, I met a problem when I add rotation matrix to my skin.

This is my file shows the translation,rotation and scale data:

 

Time:0 Trans:22.721792 0.512012 -0.000000 Qart:1.000000 -0.000000 -0.000000 1.570796 Scale:1.000000 1.000000 1.000000
Time:1 Trans:0.092348 23.141449 -0.000000 Qart:-0.577350 -0.577350 0.577350 4.188790 Scale:1.000000 1.000000 1.000000
Time:2 Trans:-22.537085 0.512007 -0.000000 Qart:0.000000 -0.707107 0.707107 3.141593 Scale:1.000000 1.000000 1.000000
Time:3 Trans:0.092356 -22.117428 -0.000000 Qart:-0.577350 0.577350 -0.577350 4.188790 Scale:1.000000 1.000000 1.000000
 
And it's a simple animation to a bone, this animation is a bone around z-axis rotate 90 degree, 180 degree, 270 degree and 360 degree
 
I read the data like this
mYHMMesh.boneInfo.yhmBone[m].frame[n] contains transform data above
for (int i = 0; i < mYHMMesh.boneInfo.BoneCount; i++)
{
     for (int j = 0; j < 120; j++)
     {
	  float4x4 cubeTrans = translation(mYHMMesh.boneInfo.yhmBone[i].frame[j].trans.x, mYHMMesh.boneInfo.yhmBone[i].frame[j].trans.y, mYHMMesh.boneInfo.yhmBone[i].frame[j].trans.z);
	  float4x4 cubeRot = rotationArbitrary(float3(mYHMMesh.boneInfo.yhmBone[i].frame[j].rot.x, mYHMMesh.boneInfo.yhmBone[i].frame[j].rot.y, mYHMMesh.boneInfo.yhmBone[i].frame[j].rot.z), mYHMMesh.boneInfo.yhmBone[i].frame[j].rot.w / 3.1415926 * 180);
	  float4x4 cubeScale = scale(mYHMMesh.boneInfo.yhmBone[i].frame[j].scale.x, mYHMMesh.boneInfo.yhmBone[i].frame[j].scale.y, mYHMMesh.boneInfo.yhmBone[i].frame[j].scale.z);
	  mBoneTransforms[i][j] = mul(mul(cubeScale, cubeRot), cubeTrans);
          //mBoneTransforms[i][j] = mul(cubeScale, cubeTrans);
          //If I use only scale and trans data, I would see the animation is on the right way except for rotation animation
     }
     //Here I calculate the offset matrix
     XMFLOAT4X4 tempOffset = floatToXMFLOAT(mBoneTransforms[i][0]);
     XMStoreFloat4x4(&tempOffset, XMMatrixInverse(NULL, XMLoadFloat4x4(&tempOffset)));
     mBoneOffset[i] = XMFLOATTofloat4x4(tempOffset);
}

and then I draw it with the matrix mul(mBoneOffset[i], mBoneTransform[i][frameCount % 120])

Is there any thing wrong?The some vertex didn't follow the bone.

What I saw is this

3tb_131116161317ac1w512293.png

Edited by kgs
0

Share this post


Link to post
Share on other sites

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  
Followers 0