SLERP issues

Started by
9 comments, last by keym 11 years, 1 month ago

So I implemented (finally) my GPU skinning and it works well when I iterate through all frames. It even works when I interpolate between frames of the same animation but I wanted to push it forward and make a simple weight based blending between animations. Here's the problem... Check out the video:

">

For this particular test I'm "slerping" current frame with bind pose frame at ratio 0%-50% (weight increases as I continue to play walk animation, I capped it to 50% because here is where the weird stuff is most noticable). When I SLERP between frameN and frameN+1 accordingly to the elapsed time, animation looks alright. The problem occurs when I try to blend two animations or animation with bind pose (as shown in the video). Ideas?

Advertisement

From the video it kinda looks like you're simply lerping euler values? (and then converting to quat?). Or converting to eulers from quat, and then lerping those? I'm a bit confused as to what your problem is? (since you haven't actually stated it). You seem to have some really dodgy animation cycles with a lot of popping in them? Those 'pops' you keep having seem to be there at the start (when you're at 100% anim?). Just looks like dodgy source data to me. Are you getting the values from fbx by any chance?

Generally blended anims looks best when they are relatively similar - so a bind pose + walk is never going to look that good. I'd probably recommend using nlerp instead of slerp when actually blending the anims themselves (it's fine to keep slerping between keys, but when blending multiple anims, nlerp is easier). When nlerping a bunch of anims, sum the weighted quats, and normalise as a final step. Beyond that, more info needed.....

No, I'm using slerp on quaternions and lerp on bone position vectors. Model is loaded from id tech4 format (md5mesh+md5anim format). All works good when I interpolate between frames of the same animation. It start's to act strangely when I try to interpolate between frames of two different animations (or for instance with bind pose, it doesn't really matter if it's bind pose or not, believe me, I get similar "pops" when I use other animation instead of bind pose).

I'm a bit confused as to what your problem is? (since you haven't actually stated it).

For this particular test I'm "slerping" current frame with bind pose frame at ratio 0%-50% (weight increases as I continue to play walk animation, I capped it to 50% because here is where the weird stuff is most noticable). When I SLERP between frameN and frameN+1 accordingly to the elapsed time, animation looks alright. The problem occurs when I try to blend two animations or animation with bind pose (as shown in the video). Ideas?

Now assuming what you've said is correct, if at the start of the video you are just displaying the animation (100% anim, 0% bind pose), then to me, it looks like your source animation is crap (because at the very start of the video it's popping way too much). The other alternative is that you're using a very ropey slerp function? Have you tried using nlerp (with shortest path correction)? At least then you can maybe *start* to rule out some possible causes? Slerping key frames to create a walk cycle, and then slerping that with a bind pose, will not, in of itself, produce any popping (although it will never look very good).

FWIW, I've been an animation programmer in the industry for over a decade. When I say you've failed to state the problem, I literally mean just that. Subjective terms such as "wierd stuff" is not a very useful way to describe any problem, especially not when dealing with animation blending - for all I know, the animator could have intentionally made the anims look like that! (You'd be surprised what some of the animations animators create!).

First of all I doubt that the animation is wrong - it's directly ripped (for educational purposes only!) from Doom3 (directly meaning from the pk4 file, not downloaded from some crappy site). Walk cycle looks ok when played itself.

As I have written, that blending is capped to 0-50%, meaning at max we have 50%-50% of animation-bindpose mix and at min we have 0-100% proportion (no animation, just plain bind pose - parts of the vid where the model is not moving). I did it to emphasise where the problem occurs. If I would do 100%-0%, most of the time you would just see the original walk animation without popping. At the beginning of the video you see roughly 50%-50%.

I tried with Nlerp but it looks even worse - body is completely dismembered and limbs are spinning in various directions and I'm like WTF.

No, I'm using slerp on quaternions and lerp on bone position vectors.

Are you lerping the bone positions in world space? If so, then that's the problem, you should be constructing bone positions at the end based on your skeleton hierarchy, bone offsets, and bone quaternions.

I'm interpolating in object space. Does this require rebuilding bone positions from hierarchy as well?

And my SLERP looks like this:


quaternion quaternion::slerp(quaternion q1, quaternion q2, float percent)
{
    quaternion result;

    float dot = q1.dotProduct(q2);              //Dot product - the cosine of the angle between 2 quats
    if(dot < -1) dot = -1;                      //Clamp value to [-1,1], just to be sure
    if(dot > 1) dot = 1;
    
    if(dot < 0)                                  //If cos(angle) is <0 we negate the quaternion and dotp.
    {                                            //(Go with smaller rotation)
        q2=-q2;
        dot=-dot;
    }

    if(dot > 0.99 && dot < 1.01)                 //If dotp is close to 1, do Lerp
    {
        result = q1 + ((q2 - q1) * percent);
        result.normalize();
        return result;
    }

    if(percent < 0.01)                           //If percent is close to 0, return quat1
    {
        result = q1;
        return result;
    }

    if(percent > 0.99)                           //If percent is close to 1, return quat2
    {
        result=q2;
        return result;
    }

    float a = acos(dot);                         //Get angle between quats
    result = (q1 * (sin((1.0 - percent) * a) / sin(a))) +  ((q2 * sin(percent * a)) / sin(a));
    return result;
} 

You need to normalise the result.

Also... since I'm writing - your variable "percent" is named very confusingly. One would expect anything called percent to range (typically) from 0-100.

Unfortunately normalising doesn't make a diffrence. I guess it only matters with (n)lerp anyway. I'm starting to think that maybe I should rebuild the positions, as C0lumbo suggested (even though I'm lerping in object space...), but not sure where to start with that.

This topic is closed to new replies.

Advertisement