SetMatrixArray, Bone Limit and Skinned Model Instancing

Started by
3 comments, last by Tispe 12 years, 1 month ago
Hello again happy.png

My game is coming along. I now have a humanoid with 120 Bones. It has 8 Mesh parts, each part is only influenced by maximum 30 Bones of the total skeleton. I do know how to animate this but I am unsure which way I should do it.

My problem is that as of now a vertex may index to bone0 and bone119, or any in between. Which means I have to map out which Bones influence each Mesh Part, copy those bones to a local Matrix Palette for that Mesh Part and THEN I have to convert the bone indices for each vertex to the new local palette.

Instead of doing this Skinned Model Instancing came to mind: http://www.ionixxgam...lInstancing.pdf

This paper describes how Textures can hold a large number of bones encoded in them.

My thought is then to code the entire animated skeleton to a texture, pass it to the shader(60 times a second), and use it as an array of many bones (120+).

Is this worth the effort, can it hurt performance? Are there a better ways?


I welcome all comments.
Advertisement
Using a dynamic texture to store bones is totally fine, as long as the GPU has good support for texturing from the vertex shader. In practice this means DX10-capable GPU's or higher, which means Nvidia 8000-series and up and AMD HD 2000 series and up.
Would it be reasonable or even possible to try it with DX9?

Here is how I imagine I would split up the Animated Skeleton the "old" way


D3DXMATRIX* pAnimatedBones = new D3DXMATRIX[120];
/*
Combine Transforms and populate pAnimatedBones
*/
struct MeshPart
{
D3DXMATRIX* pLocalBones;
};

//Another place
MeshPart Torso;
Torso.pLocalBones = new D3DXMATRIX[30];

for(int i=0;i<30;i++)
{
Torso.pLocalBones = pAnimatedBones[GetMappedIndex(i,Torso)];
}

//During init vertices will have their bone indices remapped
Would it be reasonable or even possible to try it with DX9?

Here is how I imagine I would split up the Animated Skeleton the "old" way


#define hTorso 3

D3DXMATRIX* pAnimatedBones = new D3DXMATRIX[120];
/*
Combine Transforms and populate pAnimatedBones
*/
struct MeshPart
{
D3DXMATRIX* pLocalBones;
};

//Another place
MeshPart Torso;
Torso.pLocalBones = new D3DXMATRIX[30];

for(int i=0;i<30;i++)
{
Torso.pLocalBones = pAnimatedBones[GetMappedIndex(i,hTorso)];
}

//During init vertices will have their bone indices remapped

Would it be reasonable or even possible to try it with DX9?


Yes, DX9 can do it fine as long as the hardware can handle it.
Sorry for the bump but I need some pointers. I want to implement this so it runs in DX9.0c/WinXP.

I create a texture using the D3DFMT_A8R8G8B8 flag in managed pool. 120 Bones = 480 pixels. Room for 8 bone hierarchies per row. So animated texture width is 3840 pixels, and height is 4096. This gives me room for 32768 instances on a 3840x4096 texture.

A constant register is updated with the SkeletonID before each DrawEntity.

This pseudo code demonstrates how I copy matrices into the texture:

//Once
D3DXVECTOR4 *pAnimatedMatrices = new D3DXVECTOR4[3840][4096]
//Update matrices

//Each Render Frame
hr = pAnimTex->LockRect(0,&rc,NULL,0);
if(hr==D3D_OK){
CopyMemory(rc.pBits,pAnimatedMatrices,3840*4096*4);
}
pAnimTex->UnlockRect(0);


Before drawing I set Texture:

SetTexture(D3DVERTEXTEXTURESAMPLER0, pAnimTex);



HLSL:

const uniform float2 SkeletonID;
sampler2D tex;
float4x4 Bone(tex2D(tex, SkeletonID),tex2D(tex, SkeletonID+float2(4,0)),tex2D(tex, SkeletonID+float2(8,0)),tex2D(tex, SkeletonID+float2(12,0)));
//Transform vertex



I am treading in deep waters here. Am I going in the right direction? Any shortcomings besides the huge amount of Draw Calls and DX9 instead of DX10 etc..?

This topic is closed to new replies.

Advertisement