Linear Interpolation in 3D Animation

(DynAsm and DynC Practices in OpenGL Projects)

Moderator: Mike Lobanovsky

Linear Interpolation in 3D Animation

Unread postby Mike Lobanovsky » Sat Sep 04, 2010 1:16 am

This is an OpenGL sample of using mathematical interpolation in animated model viewer code. Please note that this sample is runnable only with the recent releases of Fbsl.exe dated later than September 3, 2010 whereby dynamic allocation of assembler opcode strings has been provided.

To reduce the amount of data in an animated model file, the animation sequence stores only certain key positions of mesh vertices at selected time intervals usually called "keyframes". The number of keyframes in the sequence is normally rather limited, and if we display only the keyframes as they are, the resulting movement will be rather jerky. An example of this may be seen in the accompanying sample if we run it in its "Interpolation Off" mode irrespective of the rendering speed which itself is dependent on the language chosen for the dynamic recalculation of vertex positions (FBSL, Asm, or both). In order to avoid this, a mathematical workaround called "interpolation" is usually used.

Interpolation is a method of constructing new data points within the range of a discrete set of known data points. There are various approaches to interpolation, among which "linear" and "Hermite" interpolation are most commonly used in 3D applications. Both are relatively fast computation-wise, though alongside some merits each one has its own drawbacks.

The accompanying sample uses linear interpolation to smooth out the model's movements. Positive effects of using interpolation are most clearly seen at high frame rates with pure Asm being chosen for vertex position calculations. Toggle the interpolation on/off with the "I" key to see the difference.

You will probably notice the somewhat unnatural positions the model's head and neck acquire as the model does its morning exercises :). This is where the drawbacks of "linear" interpolation reveal themselves.

Suppose some vertex should move from position A stored in the model file's animation sequence as a keyframe to position B also stored there in the second keyframe that immediately follows the first one. In reality, the vertex is supposed to move along the sine wave path as depicted in the graph immediately following this text.

In order to follow that path precisely without interpolation, a much larger number of keyframes should seemingly be stored in the model file which will thus become impractically large in size. Instead, a linear interpolation method is used in the code to calculate the exact coordinates of the vertex along the straight line A-B (blue) whenever the time comes to display the model at an arbitrary position C at the current frame rate. The method is fast and it generally yields good results for very simple models. In our case, however, it introduces a displacement error.

In fact, the linearly interpolated keyframe C does not lie exactly on the sine wave path as it is expected to do. It is the displacement error depicted in green which is the very cause of the unnatural positions of the model's head and neck. Evidently, the head and neck displacement errors which we see in the appended sample have a cumulative nature. They accumulated at the time the model's movements were designed using simple model animation software, and they are aggravated still further by our simplistic interpolation techniques.

Those who'd like to have some additional reading on various mathematical interpolation methods may find it here.

FYI: Chris' model renderers used in his XANDREALE projects and also in my Quake III Arena model viewer utilize Hermite interpolation which produces much better visual results for medium- to high-poly bone-animated 3D models of various formats. :)

Enjoy! :)

[EDIT] While Gerome takes his time to recompile a completely new FBSL release, I append the Fbsl binary that'll be able to run the accompanying sample script.
Attachments
FbslSept7.zip
(216.06 KiB) Downloaded 187 times
Sin.jpg
Sin.jpg (9.96 KiB) Viewed 4664 times
Threat.zip
(586.35 KiB) Downloaded 191 times
Mike
"Я старый солдат, мадам, и не знаю слов любви."
"I am an old soldier, ma'am, and I don't know the words of love."
"Je suis un vieux soldat, madame, et je ne connais pas les mots d'amour."
"Ich bin ein alter Soldat, gnädige Frau, und ich weiß nicht die Worte der Liebe."

__________________________________________________________________________________________________________________________________________________
(3.2GHz i5 Core Quad, 8GB RAM / 2 x nVidia GTX 550Ti SLI-bridged, 2GB VRAM)
(x86 Win XP Pro Russian Sp3/x86 Win Vista Ultimate Sp2/x64 Win 7 Ultimate Sp1/Wine in x64 elementaryOS Luna)
User avatar
Mike Lobanovsky
FBSL Administrator
FBSL Administrator
 
Posts: 1824
Joined: Tue Apr 19, 2005 8:22 am
Location: Republic of Belarus

Re: Linear Interpolation in 3D Animation

Unread postby Gerome » Sat Sep 04, 2010 1:38 am

Hello !

Mike is a GENIUS !!!!
Congratulations Mike and thanks a lot for the mods, I'll make a 32 and a 64 bits build for people that are interested in a 64 bits version... ! :)
Yours,

(¯`·._.·[Gerome GUILLEMIN]·._.·´¯)
:: Full SETUP w. HELP 05th of December 2011 ::
http://www.fbsl.net/setup/FBSLv3.exe [full v3.4.10 installation pack]
http://www.fbsl.net/setup/FBSLv3bin.zip [minimal upgrade to v3.4.10]
Laissons les jolies femmes aux hommes sans imagination. / Let us leave pretty women to men without imagination.(M.Proust)
The success is a defeat for the one who does not want to dance any more! (H.F. Thiefaine)
User avatar
Gerome
FBSL Administrator
FBSL Administrator
 
Posts: 3149
Joined: Sat Mar 12, 2005 9:06 pm
Location: Paris -- France

Re: Linear Interpolation in 3D Animation

Unread postby Mike Lobanovsky » Sat Sep 04, 2010 2:19 am

Thanks for the appreciation Gerome, but I am still afraid that at least the Dynamic Assembler layer itself is not yet ready for the native 64-bit compilation, mainly because of the 32-bit-only address restrictions. Neither are the assembler intrinsics of FBSL function-call engine, nor its function parameter transfer methods, etc. Neither is there any support for long-long integers or floats... Skeptical? Well, yes... :?
Mike
"Я старый солдат, мадам, и не знаю слов любви."
"I am an old soldier, ma'am, and I don't know the words of love."
"Je suis un vieux soldat, madame, et je ne connais pas les mots d'amour."
"Ich bin ein alter Soldat, gnädige Frau, und ich weiß nicht die Worte der Liebe."

__________________________________________________________________________________________________________________________________________________
(3.2GHz i5 Core Quad, 8GB RAM / 2 x nVidia GTX 550Ti SLI-bridged, 2GB VRAM)
(x86 Win XP Pro Russian Sp3/x86 Win Vista Ultimate Sp2/x64 Win 7 Ultimate Sp1/Wine in x64 elementaryOS Luna)
User avatar
Mike Lobanovsky
FBSL Administrator
FBSL Administrator
 
Posts: 1824
Joined: Tue Apr 19, 2005 8:22 am
Location: Republic of Belarus

Re: Linear Interpolation in 3D Animation

Unread postby Codeman » Tue Nov 11, 2014 8:34 am

mike> can you fix this script to run with latest fbsl exe ?
i got an error on the asm newframe function

Edit: fixed it and also ported it to openglapp 1.1
i will try to add a one option to use the new core math functions then i will post it here.
_-=<(¯`·._.·[ CodeMan ]·._.·´¯)>=-_
Your only limit : Your imagination

FBSL V3 TESTED On :
Image

Chris 1 (Corei5-4460S 2.9 GHZ w/ 16GB RAM, GeForce GTX 745 w/ 4GB VRAM, Windows 8 x64 Fr)
Chris 2 (2.0GHz AMD Atlon 64 X2 3800+ w/ 4GB RAM, GeForce 9600GT w/ 1GB VRAM, Windows 7 x64 Fr)
Chris 3 (Tablet pc : ASUS Transformer Book T100)
User avatar
Codeman
FBSL Administrator
FBSL Administrator
 
Posts: 497
Joined: Sat Nov 24, 2007 4:33 pm
Location: France

Re: Linear Interpolation in 3D Animation

Unread postby Mike Lobanovsky » Tue Nov 11, 2014 12:47 pm

Hi Chris,

This will be very valuable because we really didn't have much chance to test the correctness and usability of our matrix math layer.

Just FYI: FBSL's matrix math functions are an indie implementation of a subset of Microsoft's DirectXMath library. I think its reference in the MSDN can help you out some in your work.

I'm looking forward to your submission.
Mike
"Я старый солдат, мадам, и не знаю слов любви."
"I am an old soldier, ma'am, and I don't know the words of love."
"Je suis un vieux soldat, madame, et je ne connais pas les mots d'amour."
"Ich bin ein alter Soldat, gnädige Frau, und ich weiß nicht die Worte der Liebe."

__________________________________________________________________________________________________________________________________________________
(3.2GHz i5 Core Quad, 8GB RAM / 2 x nVidia GTX 550Ti SLI-bridged, 2GB VRAM)
(x86 Win XP Pro Russian Sp3/x86 Win Vista Ultimate Sp2/x64 Win 7 Ultimate Sp1/Wine in x64 elementaryOS Luna)
User avatar
Mike Lobanovsky
FBSL Administrator
FBSL Administrator
 
Posts: 1824
Joined: Tue Apr 19, 2005 8:22 am
Location: Republic of Belarus

Re: Linear Interpolation in 3D Animation

Unread postby Codeman » Tue Nov 11, 2014 7:53 pm

i figurated the matrix must be transposed to work.


seems there is a problem with vec3substract, i got corrupted animations just by using it instead of the 3 lines of code of substraction. (no problem with vec3add )
tried to use the quaternion lerp and vec4lerp functions instead of the fbsl script version but also got deformed mesh (in interpolation mode).
still investigating ...

yup they are mostly directx replacement functions so there may be differences in the order of data and so on...
_-=<(¯`·._.·[ CodeMan ]·._.·´¯)>=-_
Your only limit : Your imagination

FBSL V3 TESTED On :
Image

Chris 1 (Corei5-4460S 2.9 GHZ w/ 16GB RAM, GeForce GTX 745 w/ 4GB VRAM, Windows 8 x64 Fr)
Chris 2 (2.0GHz AMD Atlon 64 X2 3800+ w/ 4GB RAM, GeForce 9600GT w/ 1GB VRAM, Windows 7 x64 Fr)
Chris 3 (Tablet pc : ASUS Transformer Book T100)
User avatar
Codeman
FBSL Administrator
FBSL Administrator
 
Posts: 497
Joined: Sat Nov 24, 2007 4:33 pm
Location: France

Re: Linear Interpolation in 3D Animation

Unread postby Mike Lobanovsky » Tue Nov 11, 2014 9:39 pm

Hi Chris,

There are no problems with Vector3Subtract(). Its source code is elementary and there can't be any typos or other mistakes in it. Moreover, I used those simple vector functions in my own scripts and they worked OK for me.

Don't forget to pass all point, vector, plane, quaternion, and matrix parameters by their @ pointers! Also note that all quaternion and matrix functions that are described in the RC2 PDF file as "build and ..." do not transform the existing quat or mtx, but rather build (i.e. create from their input) a new identity quat or mtx and then transform it as described in the function specification!

Please see your PM box for the latest RC3 binary that hasn't been publicly released yet.
Mike
"Я старый солдат, мадам, и не знаю слов любви."
"I am an old soldier, ma'am, and I don't know the words of love."
"Je suis un vieux soldat, madame, et je ne connais pas les mots d'amour."
"Ich bin ein alter Soldat, gnädige Frau, und ich weiß nicht die Worte der Liebe."

__________________________________________________________________________________________________________________________________________________
(3.2GHz i5 Core Quad, 8GB RAM / 2 x nVidia GTX 550Ti SLI-bridged, 2GB VRAM)
(x86 Win XP Pro Russian Sp3/x86 Win Vista Ultimate Sp2/x64 Win 7 Ultimate Sp1/Wine in x64 elementaryOS Luna)
User avatar
Mike Lobanovsky
FBSL Administrator
FBSL Administrator
 
Posts: 1824
Joined: Tue Apr 19, 2005 8:22 am
Location: Republic of Belarus


Return to Applied Dynamic Assembler & Dynamic C in OpenGL

Who is online

Users browsing this forum: No registered users and 1 guest

cron