I've implemented dual quaternion skinning and for some reason it just doesn't work. I'm hoping somebody will have ideas on further avenues for trying to fix this. To start with, I'm calculating all my bone transforms with quaternion rotations and position vectors. I've verified this works by converting the final result to a matrix and doing basic linear skinning.
My quat/vec to dual quaternion conversion function is:
void iUQTtoUDQ(math::quat* dual, const math::quat& q, const math::vec3& p)
{
// Straight copy of rotation
dual[0].x = q.x;
dual[0].y = q.y;
dual[0].z = q.z;
dual[0].w = q.w;
// Multiply rotation by pure quaternion position and scale by 0.5 (dual scalar)
dual[1].x = 0.5f * ( p.x * q.w + p.y * q.z - p.z * q.y );
dual[1].y = 0.5f * (-p.x * q.z + p.y * q.w + p.z * q.x );
dual[1].z = 0.5f * ( p.x * q.y - p.y * q.x + p.z * q.w );
dual[1].w = 0.5f * (-p.x * q.x - p.y * q.y - p.z * q.z );
}
This matches my quaternion multiplication function with w set to zero for converting a vector into a pure quaternion.
This is my skinning function, with debug code left in-tact:
float3 SkinPositionDualQuat(float4 pos, uint4 bone_indices, float4 bone_weights)
{
float2x4 dq0 = GetBoneDualQuat(bone_indices.x);
float2x4 dq1 = GetBoneDualQuat(bone_indices.y);
float2x4 dq2 = GetBoneDualQuat(bone_indices.z);
float2x4 dq3 = GetBoneDualQuat(bone_indices.w);
// DEBUG: Here I'm rescaling weights to test weighting by 1,2,3 and 4 bones at a time
// Weights are sorted, largest influence first
//bone_weights.y = 0;
bone_weights.z = 0;
bone_weights.w = 0;
float t = dot(bone_weights, 1);
bone_weights /= t;
// Antipodality checks
if (dot(dq0[0], dq1[0]) < 0.0) bone_weights.y *= -1.0;
if (dot(dq0[0], dq2[0]) < 0.0) bone_weights.z *= -1.0;
if (dot(dq0[0], dq3[0]) < 0.0) bone_weights.w *= -1.0;
// Weight dual quaternions
float2x4 result =
bone_weights.x * dq0 +
bone_weights.y * dq1 +
bone_weights.z * dq2 +
bone_weights.w * dq3;
// Normalise the result and transform
float normDQ = length(result[0]);
result /= normDQ;
return DQTransformPoint( result[0], result[1], pos.xyz );
}
Now for the interesting bit of code:
float3 DQTransformPoint( float4 realDQ, float4 dualDQ, float3 pt )
{
return pt + 2 * cross(realDQ.xyz, cross(realDQ.xyz, pt) - realDQ.w * pt)
+ 2 * (realDQ.w * dualDQ.xyz - dualDQ.w * realDQ.xyz + cross(realDQ.xyz, dualDQ.xyz));
}
This matches the original source from Kavan, except that I've swapped the last sign on the first line (-realDQ.w*pt used to be +realDW.w*pt). If I don't do this, it doesn't work.
So to the problem: If I weight by one bone only, this all works perfectly. However, when my character bends their arm up to their shoulder, the entire arm skews like crazy.
I can't believe that the linear interpolation of dual quats above is the source of the problem (unless dual quats are a modern version of the emperors new clothes). I'm guessing it's something to do with the fact that I've changed DQTransformPoint to work in my engine but haven't changed the encoding. Something is amiss!
Can anybody think of anywhere I can go with this?
Thanks!






