GPU based key frame interpolation

Started by
3 comments, last by V-man 14 years, 6 months ago
Hello community! I have a theoretical question about GPUs (with which I unfortunately am not very familiar). I know that vertex programs work on a per-vertex basis. So, if I want to animate a model using keyframing, is there a way to let the GPU handle the interpolation process? My problem is that I am not sure how to hand both keyframes to the GPU at the same time. As far as i understand the whole process, I render the model in keypose A and could interpolate every vertex with its destination in another keypose B. So for me the question is, how do I get the target positions into the shader? Best regards, Mike.
Advertisement
You bind two streams of vertex shader inputs, one is the vertices, normals etc. of the first keyframe, and the same for the second. Then you pass the current tween factor in as a uniform float, and write your vertex shader to interpolate between the two streams before transforming the result.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

You need a vertex format that looks something like this

struct MyVertex
{
float x1, y1, z1; //Vertex
float x2, y2, z2; //The next keyframe's vertex
float nx1, ny1, nz1; //Normal
float nx2, ny2, nz2; //The next keyframe's normal
float s, t; //Texcoord
};

and you need to prepare your VBO accordinly.
In the vertex shader, you will thus have the vertices from 2 keyframes.
Then you pass some tween factor as a uniform float. The tween factor would be a value from 0.0 to 1.0. You also need some code that decides what part of the VBO needs to be uploaded since when you reach 1.0, then it is time to bind the next keyframe and use tween factor 0.0
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
First of all, thanks for your comments.

Unfortunately, I still have a few questions. As for the first proposed method, this is exactly what I have in mind. Can you point me towards what to google for (since my searches are still relatively fruiteless)?

Regard V-Man's answer: This kind of looks like a lot of overhead. If I wanted to tween between arbitrary keyframes, doesn't that mean I have to keep track of a quadratic number of keyframes?

- Mike.
Quote:Original post by pollux070282
Regard V-Man's answer: This kind of looks like a lot of overhead. If I wanted to tween between arbitrary keyframes, doesn't that mean I have to keep track of a quadratic number of keyframes?


Yes, keyframes consume a lot of space compared to skeletal animation.
If you want to tween between arbitrary keyframes, then perhaps interleaving is not a good idea.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

This topic is closed to new replies.

Advertisement