Jump to content

  • Log In with Google      Sign In   
  • Create Account


SetMatrixArray, Bone Limit and Skinned Model Instancing


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 Tispe   Members   -  Reputation: 982

Like
0Likes
Like

Posted 27 February 2012 - 04:28 AM

Hello again Posted Image

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.

Sponsor:

#2 MJP   Moderators   -  Reputation: 10619

Like
0Likes
Like

Posted 27 February 2012 - 04:18 PM

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.

#3 Tispe   Members   -  Reputation: 982

Like
0Likes
Like

Posted 28 February 2012 - 02:07 AM

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[i] = pAnimatedBones[GetMappedIndex(i,hTorso)];
}

//During init vertices will have their bone indices remapped


#4 MJP   Moderators   -  Reputation: 10619

Like
0Likes
Like

Posted 28 February 2012 - 02:09 AM

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.

#5 Tispe   Members   -  Reputation: 982

Like
0Likes
Like

Posted 07 March 2012 - 06:58 AM

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..?




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS