• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
CppPerson

[SOLVED] Dual Quaternion Skinning failing on blend

3 posts in this topic

Hi,

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:

[CODE]
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 );
}
[/CODE]

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:

[CODE]
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 );
}
[/CODE]

Now for the interesting bit of code:

[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));
}
[/CODE]

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!
0

Share this post


Link to post
Share on other sites
So I've gone back to basics and reduced my input and output to un-optimised representations of the equations in this brilliant paper: [url="http://wscg.zcu.cz/wscg2012/cd-rom/short/A29-full.pdf"]http://wscg.zcu.cz/w...rt/A29-full.pdf[/url] (A beginner's guide to dual quaternions).

The DQ generation code is simply:

[CODE]
void iUQTtoUDQ(math::quat* dual, const math::quat& q, const math::vec3& p)
{
// Qr = r
dual[0] = q;
// Qd = 0.5(0,t)r
math::quat qp = { p.x, p.y, p.z, 0 };
dual[1] = qScale(qMultiply(qp, q), 0.5f);
}

[/CODE]

And the shader transform code is:

[CODE]
float3 Transform(float4 q, float3 p)
{
return Multiply(Conjugate(q), Multiply(float4(p, 1), q)).xyz;
}
float3 DQTransformPoint(float4 Qr, float4 Qd, float3 pt)
{
// r = Qr
// t = 2QdQr*
float3 p = Transform(Qr, pt);
float4 t = 2 * Multiply(Qd, Conjugate(Qr));
return p + t.xyz;
}

[/CODE]

This produced the same artefacts. By swapping the Multiply parameters used to generate [b]dual[1][/b] and also for generating [b]t [/b]everything is now working as expected. My multiplies concatenate right-to-left and hence didn't match any of the available source code out there for me to compare with. I guess that will teach me to test my stuff with a basic idle animation.

Now to optimise...
0

Share this post


Link to post
Share on other sites
For anybody who might have similar problems in the future, this is where I started on the optimisations:

[CODE]
float4 MultiplyPure(float3 a, float4 b)
{
// lhs is a pure quaternion, rhs is a quaternion, so a.w=0
return float4(b.w * a + cross(a, b.xyz), -dot(a, b.xyz));
}
float3 MultiplyConjugate3(float4 a, float4 b)
{
// perform conjugate on lhs before multiplying, discard result.w
return a.w * b.xyz - b.w * a.xyz + cross(-a.xyz, b.xyz);
}
float3 DQTransformPoint(float4 Qr, float4 Qd, float3 pt)
{
// Vector transform pt by rotation Qr (pvp')
float3 p = MultiplyConjugate3(Qr, MultiplyPure(pt, Qr));
// t = 2QdQr*
float3 t = 2 * MultiplyConjugate3(Qr, Qd);
return p + t;
}
[/CODE]

which reduces to:

[CODE]
float3 DQTransformPoint(float4 Qr, float4 Qd, float3 pt)
{
float3 p = pt + 2 * cross(-Qr.xyz, Qr.w * pt + cross(pt, Qr.xyz));
float3 t = 2 * (Qr.w * Qd.xyz - Qd.w * Qr.xyz + cross(-Qr.xyz, Qd.xyz));
return p + t;
}
[/CODE]

This is a subtle re-arrangement of the source paper's results which could have been achieved through guesswork. It was more fun this way [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]
1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0