GLSL skeletal animation

Started by
5 comments, last by Einar89 14 years, 10 months ago
Hi all. I am currently willing to start implementing character skeletal animation using glsl shaders. My problem is that I'm having trouble finding good information on how to do this... even here in the forum search (maybe I'm not being able even to figure out the words for finding it :) ). I couldn't find a good tutorial or sample of simple animation using vertex shaders. Anyone has good advice/links/samples/tutorials on this? (using glsl shaders please) Also, are vertex shaders really the best way to implement character skeletal animation? thanks in advance
Advertisement
My suggestion would be to implement skeletal animation on the CPU before you try to do it on the CPU, it's way easier to debug that way, and it's not always the easiest to debug in the first place.

It will require a good understanding of matrix math. Once you have this understanding, and prove it on the CPU, it's very easy to move it to the GPU using shaders. But the math needs to be buffed out first.

If you can find a web archive of: rsn.gamedev.net he had a sweet skeletal animation and milkshape model loading tutorials. It's a fairly straight forward concept once you get your head around it.
I agree with what bzroom said, about first implementing it on the CPU, and porting it to the GPU. The main advantage of using the vertex shader for this is that the vertex shader is rarely a bottleneck.
All you have to do is pass the three(initial, parent and animated) matrices with glVertexAttrib4f. You will basically have 3 calls per matrix. You then do the normal matrix multiplication in the vertex shader.
I usually do all my matrix multiplication for the skeleton on the CPU, and i store my mesh in bone space. That way i can pass only an array of final bone transforms to the vertex shader, with one attribute call, and only multiply the vertices by their final transform.

I dunno if this is the best way to do it. Just stating my difference.
Here's one
http://www.opengl.org/wiki/Skeletal_Animation
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);
Interesting, I also update the skeleton on the CPU. Upload the joint matrices to a uniform array and then send the weights and matrix indices as attributes per vertex to the GPU. Obviously the extra information is for skinned animation.
I feel really stupid, having just realized what I wrote. The way I described it is wrong, because you end up redoing a lot of calculations.

This topic is closed to new replies.

Advertisement