Skinning problem using fx file

Started by
20 comments, last by Saad Manzur 10 years, 1 month ago

Buck I read your article not the IceBreaker's one. The one you wrote about skeleton and skinning. Yes I have weighted each vertex. But there is a tad bit problem. Not every vertex have bone influencing it less than 4. That may be the problem I guess.

As for your article I came to understand this . I will have toParent matrix from the file I imported. I have to multiply it by gradually to get toRoot transformation. And then I have to import a new matrix of transformation from each key frame for each bone and store it in the transformation matrix . Am I correct ? I did not multiply 3 matrices as you can see. I only traversed using the matrix I got from the imported file. So the local is equivalent to toParent ?

toParent = a matrix in reference with the parent

toRoot = a matrix in reference with the root

transformation = ... I am still confused what it does actually

And also each vertex has variable length bones. How do I set the input layout according to that. I mean some have only 2 bones influencing it and some have 6.

Advertisement

First: it appears you have the concept of the "toParent" and "toRoot" matrices correct. The TransformationMatrix is primarily just a handy storage place. However, depending on how you import data, TransformationMatrix often starts out initialized as the "toParent" matrix. In that case, be sure to calculate the "toRoot" matrices before you use the TransformationMatrix for any other purpose. That is, "use it before you lose it." Once the "toRoot" and offset matrix calcs have been done, you won't need the "toParent" matrix any more.

Second: You have to decide on some maximum number of influence bones. I can't remember where I read it, but 4 influences per-vertex is usually more than enough. Your shader code (which is a very common implementation BTW) assumes a maximum of 4 influence bones.

Third: Assume you set a maximum vertex influence at 4 bones. When you set up the vertices (probably during loading or shortly thereafter), make sure each vertex has at least one influence bone, and no more than 4.

If your model has more than 4 influence bones, the best approach is to go back to the modeling program and redo the bone-weighting. At this point, I really don't think you want to get into adding code to your import routine to handle more than 4. Alternatively, when you import, you can simply ignore any bone influences greater than 4. However, depending on how the model was weighted, you won't know what you're throwing away.

In any case:

Also, when setting up the vertices, make sure the indices and weights for "unused" bones are set to 0.

For instance, assume a vertex has 2 influence bones, indexed as A and B. The vertex structure requires 4 bone indices and weights be defined.

For that vertex:

bone index 0: A

bone index 1: B

bone index 2: 0

bone index 3: 0

bone weight 0: A's weight factor

bone weight 1: B's weight factor

bone weight 2: 0

bone weight 3: 0

That should keep you busy for a little while.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

I had already imported the weights but did not initialize the unused ones as 0. If I decide to keep maximum of 6 bone influences what would be the input layout for that ? Just curious...


If I decide to keep maximum of 6 bone influences what would be the input layout for that ?


You should write your own code. Besides, I personally wouldn't know a good way to do that. But if you use something other than 4 influences, remember to revise the shader.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

Hi.
Try loading your mesh in a viewer program.
And when first writting skinning shader make sure you have a skinned mesh that works.
And some time the scale of the mesh is so small you can't see it or it's behind the camera.

Hi.
Try loading your mesh in a viewer program.
And when first writting skinning shader make sure you have a skinned mesh that works.
And some time the scale of the mesh is so small you can't see it or it's behind the camera.

I have tried using Assimp viewer to view the file. In the viewer I can see the mesh , material and skeleton just fine

Hey Buck,

What can you make of this output for weights ?


0.030172, 0.969828, 0, -1.07374e+008, 
0.030955, 0.969045, 0, -1.07374e+008, 
0.03023, 0.96977, 0, -1.07374e+008, 
0.03023, 0.96977, 0, -1.07374e+008, 
0.029477, 0.970523, 0, -1.07374e+008, 
0.030172, 0.969828, 0, -1.07374e+008, 
0.030955, 0.969045, 0, -1.07374e+008, 
0.031927, 0.968073, 0, -1.07374e+008, 
0.031205, 0.968795, 0, -1.07374e+008, 
0.031205, 0.968795, 0, -1.07374e+008, 
0.03023, 0.96977, 0, -1.07374e+008, 
0.030955, 0.969045, 0, -1.07374e+008, 
0.029477, 0.970523, 0, -1.07374e+008, 
0.03023, 0.96977, 0, -1.07374e+008, 
0.029685, 0.970315, 0, -1.07374e+008, 
0.029685, 0.970315, 0, -1.07374e+008, 
0.029, 0.971, 0, -1.07374e+008, 
0.029477, 0.970523, 0, -1.07374e+008, 
0.03023, 0.96977, 0, -1.07374e+008, 
0.031205, 0.968795, 0, -1.07374e+008, 
0.030684, 0.969316, 0, -1.07374e+008, 
0.030684, 0.969316, 0, -1.07374e+008, 
0.029685, 0.970315, 0, -1.07374e+008, 
0.03023, 0.96977, 0, -1.07374e+008, 

Something definitely is going wrong I think. This prints the weight for each vertex. The fourth weight remains constant as you can see. I set them initially to zero.

Looks pretty good. You don't say what "output" is from, but looks like those vertices all have 2 bone weights which sum to 1 (which should be fine). The other weights are 0. Looks as one might expect for vertices with 2 influence bones, but can take up to 4 influence bones. I wouldn't worry about the 4th weight looking "constant." It's close enough to 0 as makes no difference.

The last value might just be the normal process of using the first 3 weights and setting the last weight to 1.0 - weight1 - weight2 - weight3.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

Buckeye, it's e+ not e- wink.png

A float value of -1.07374e+008 gives me raw hex of 0xCCCCCCB6, which almost looks like the magic number for bad memory. Anyway, a weight of -107 millions sounds bad.

Buckeye, it's e+ not e- wink.png

A float value of -1.07374e+008 gives me raw hex of 0xCCCCCCB6, which almost looks like the magic number for bad memory. Anyway, a weight of -107 millions sounds bad.

Hokey Smokes, Rockie! Wow. Missed that one. Good catch, unbird. However, I suspect it's immaterial.

@Saad: Where are you getting the data you posted? From what point in your code? If it's coming from the input to the shader, and you're using the shader you posted in this topic, there's only 3 weights being input to the shader (which is fine), and you only need to look at 3.

Does your vertex format support 3 weights or 4? If it supports 3 weights and you're setting 4, you may be trashing some memory somewhere.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

This topic is closed to new replies.

Advertisement