• Create Account

### #ActualJason Z

Posted 13 November 2013 - 08:33 PM

float4 pos = float4(input.pos, 1.0f);
float4 norm = float4(normalize(input.norm), 0.0f);
for (int i = 0; i < 4; ++i)
{
pos += weights[i] * mul(pos, gBoneTransform[input.BoneIndices[i]]);
norm += weights[i] * mul(norm, gBoneTransform[input.BoneIndices[i]]);
}


This doesn't look correct to me either - you are modifying the pos variable in the same line that it is being used to update the current position.  Instead, you do something more like this:

float4 pos = float4(input.pos, 1.0f);
float4 skinnedPos = float4( 0.0f, 0.0f, 0.0f, 0.0f );
float4 norm = float4(normalize(input.norm), 0.0f);
for (int i = 0; i < 4; ++i)
{
skinnedPos += weights[i] * mul(pos, gBoneTransform[input.BoneIndices[i]]);
norm += weights[i] * mul(norm, gBoneTransform[input.BoneIndices[i]]);
}

skinnedPos.w = 1.0f;


The way you have it now, you would be starting with a different position as the input to each of the weighted transformed positions, which isn't correct.  Instead you should retain the input position and accumulate the transformed positions into another variable.

### #1Jason Z

Posted 13 November 2013 - 08:31 PM

float4 pos = float4(input.pos, 1.0f);
float4 norm = float4(normalize(input.norm), 0.0f);
for (int i = 0; i < 4; ++i)
{
pos += weights[i] * mul(pos, gBoneTransform[input.BoneIndices[i]]);
norm += weights[i] * mul(norm, gBoneTransform[input.BoneIndices[i]]);
}


This doesn't look correct to me either - you are modifying the pos variable in the same line that it is being used to update the current position.  Instead, you do something more like this:

float4 pos = float4(input.pos, 1.0f);
float4 skinnedPos = float4( 0.0f, 0.0f, 0.0f, 0.0f );
float4 norm = float4(normalize(input.norm), 0.0f);
for (int i = 0; i < 4; ++i)
{
skinnedPos += weights[i] * mul(pos, gBoneTransform[input.BoneIndices[i]]);
norm += weights[i] * mul(norm, gBoneTransform[input.BoneIndices[i]]);
}

skinnedPos.w = 1.0f;


PARTNERS