Skip to main content
gamedev.net
🔒 Locked 🎮 Unity

GPU skinning

Started by eirland 3 replies 1.3k views
Original Post
eirland
eirland
If anyone has a second to answer my question it would be much appreciated :) I've implemented skinned animation which works correctly in software and am attempting to switch it over to skinning on the GPU. The problem is that some of my vertices have 5 influences :( This means I can't easily pack all 5 into one UBYTE4. I think my main problems are: I've been using D3DVERTEXELEMENT9 SkinDecl[] = { { 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT,D3DDECLUSAGE_POSITION, 0 }, { 0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0 }, { 0, 24, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 }, { 0, 32, D3DDECLTYPE_UBYTE4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BLENDINDICES, 0 }, { 0, 36, D3DDECLTYPE_UBYTE4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1 }, { 0, 40, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BLENDWEIGHT, 0 }, { 0, 56, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 2 }, D3DDECL_END() }; I essentially need 8 influences/weights but it wouldn't let me use D3DDECLUSAGE_BLENDWEIGHT or D3DDECLUSAGE_BLENDINDICES twice. My input struct in the shader is: struct skinnedVertIn { float3 position : POSITION; float3 normal : NORMAL; float2 baseTCoord : TEXCOORD0; float4 infs : BLENDINDICES0; float4 infs1: TEXCOORD1; float4 weights : BLENDWEIGHT0; float4 weights1: TEXCOORD2; }; Lastly, here's my vertex as declared in my program: struct SKINVERT { D3DXVECTOR3 pos; D3DXVECTOR3 normal; float u,v; unsigned char infs[8]; float weights[8]; }; Also I'm a little confused about how to transform my vert in the shader. Should I combine my joint's bind pose inverse matrix with it's current pose matrix in software and then just pass that to my shader? Thanks in advance :) Erik
Hatori
Hatori
What I do for 5 vertex influences is renormalize them to a maximum of 4 and tell the artists to not use a maximum of 4 influences per vertex. The Maya exporter will warn them that it is renormalizing the vertex influences.


As to the second part of your question, yes the skinning matrices are built on the CPU. I've heard that it is possible to do this on the GPU through the use of a vertex texture but I have not researched it fully and it requires Shader Model 3.0 to work properly. And even then ATI supports this in some weird hacky way that is different than nVidias..... So for the time being I do it on the CPU.
eirland
eirland
How exactly do you renormalize the weights? Do you throw out the smallest ones until you get to 4 and then force the remaining 4 to sum to 1 (using a ratio)?
Hatori
Hatori
Here is what I do....

I find like you said the 4 weights with the greatest influence. And drop the ones with least influence.

Then I find the sum of the total 4 remaining weights. And divide each weight by this sum. So now they add up to one.

Of course this will not be as accurate as when you had more than 4 influences on the vertex, but in practice I have not noticed any noticeable difference.

I've done this on Doom3 models which have had 5-6 influences per vertex with success.
eirland
eirland
Yeah, Thanks Hatori. I did exactly what you said and I can't notice a difference at all.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.