PDA

View Full Version : skin animation and no translate model



giuseppe500
09-15-2010, 06:38 AM
Hello.
I made a simple skin animation from COLLADA files with opengl.
Leaving aside the import, this is my simple cg shader:



uniform float4 skinnedMatricesVS20[80*3];
uniform float4 CameraModelPosition;
uniform float4x4 WMatrix;
uniform float4x4 WVPMatrix;
uniform float4x4 VPMatrix;


struct VS_IN
{
float3 pos : POSITION;
float3 blendWeights : TEXCOORD0;
float3 blendIndices : TEXCOORD1;
float3 normalL : NORMAL;
float2 TC :TEXCOORD2;

};

struct VS_OUT
{
float3 posH : POSITION;
float3 posW ;
float3 normalW ;
float2 texC : TEXCOORD;

};

float4x4 RebuildSkinMatrix(float index)
{
float4x4 mx;
float4 a = skinnedMatricesVS20[index*3+0];
float4 b = skinnedMatricesVS20[index*3+1];
float4 c = skinnedMatricesVS20[index*3+2];

mx = float4x4(
a,
b,
c,
float4(0, 0, 0, 1));
return mx;
}

VS_OUT v_Skin3(VS_IN vIn)
{
VS_OUT vOut ;

// First transform position with bones that affect this vertex
// Use the 3 indices and blend weights we have precalculated.
float4x4 skinMatrix =
RebuildSkinMatrix(vIn.blendIndices.x) * vIn.blendWeights.x +
RebuildSkinMatrix(vIn.blendIndices.y)* vIn.blendWeights.y +
RebuildSkinMatrix(vIn.blendIndices.z)* vIn.blendWeights.z ;

// Calculate local world matrix with help of the skinning matrix
float4x4 localWorld = mul(WMatrix, skinMatrix);
// Now calculate final screen position with world and viewProj matrices.
float4 worldPos = mul(localWorld, float4(vIn.pos, 1));
vOut.posH = mul(worldPos, VPMatrix);
vOut.posW = mul(worldPos, VPMatrix);
vOut.texC = vIn.TC;
return vOut;
}
uniform sampler2D BaseSampler;

float4 p_Skin3(VS_OUT pIn) :COLOR
{
float4 kBaseColor = tex2D(BaseSampler, pIn.texC);
return kBaseColor;
};




The model is imported correctly and also the trasformations of the bones are ok.
I can not understand why if I use this shader, wm4 do not translate the geometry (not the internal bones trasformation , but the location of the skinned mesh)with model-> LocalCoord->Translate (x, y, z), while the model it is rotated correctly.
I Add that the imported model from a collada have a translation inherent in the animation.

Each frame the animation matrixes of bones are updated to the current frame and the frame is increased.
may be that the matrixes influencing the translation?
I repeat, I can not understand why the model with thýs shader not translate.
Thank you.

DmitryM
09-15-2010, 09:26 AM
Your skinning matrices are constructed from 3 vec4, supplying (0,0,0,1) as the translation part (look at RebuildSkinMatrix routine).