Jump to content
  • Advertisement
Sign in to follow this  
Shaarigan

OpenGL Skle Animation in OpenGL

This topic is 2407 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i looked arround on the internet to learn skeletel animation for modelling. Now i dont understand how it could be realized in
OpenGL because i dont know if either i had to split my mesh into peaces or how i could use different matrices on different parts
of my solid mesh.
I think last one is the right method but if i already said, i dont know to apply multiple matrices to a single meshs parts. Edited by Shaarigan

Share this post


Link to post
Share on other sites
Advertisement
There are almost no explanations online of skeletal animation. Really the only way to do it practically is to learn shaders.

Say I have a cube guy. His head is a cube, has a cube torso. I want to rotate his head left. What happens is, I send the rotation of the head, and the lack of rotation for the torso to the graphics card. I designate by weights (vertex attributes) which vertices are connected to the head and which are connected to the torso. The verts are in the same mesh, some just get manipulated differently. There is never an artist going in and separating each vertex by a bone into 40 separate models, they are separated by the weights (which designate the index of the bone, and how much influence that bone plays on this vertex).

Share this post


Link to post
Share on other sites
[font=arial, verdana, tahoma, sans-serif][size=2]It is not specific for OpenGL but I can show you GLSL version.
Like dpadam450 said for every vertex you will have to also assigned bone indexes and weights
So you are sending vertex, normal, uv, attributes into shader for standard mesh but if you want to do skeletal animations you will need to tell shader which bones are deforming vertex and how strong using weight
You will also need to send deforming matrices into shader as uniforms (I suppose you already know how to calculate these matrices )

so you should add something like this into your shader:

[font="Menlo"][size=2][size=2]
uniform mat4 bones[25];//if you have max 25 bones
attribute vec3 weights;//if you are using max 3 bones for single vertex
attribute vec3 boneIndexes;//if you are using max 3 bones for single vertex
...

void main()
{
...

highp vec4 position;
position = bones[boneIndexes.x] * vec4(inVertex, 1.0) * weights.x;
position += bones[boneIndexes.y] * vec4(inVertex, 1.0) * weights.y;
position += bones[boneIndexes.z] * vec4(inVertex, 1.0) * weights.z;
...

gl_Position = ViewProjMatrix * position;

}

[/font]
[font="Menlo"][size=2][size=2]
[/font]
[font="Menlo"][size=2][size=2]But don't forget that deforming position also deforms normals (and tangents if you are using normal mapping)[/font][/font]

Share this post


Link to post
Share on other sites
You do not need an shader to do the transformation. Yes it will be faster to do it in the Vertex Shader but each vertex can still be transformed directly on the CPU.

Share this post


Link to post
Share on other sites
So tell me how it would look (in code) to do the matrix stuff on a single mesh (like a small human)

I'll try both and look what is better to us.

Share this post


Link to post
Share on other sites
Split or not, this does not matter. You need to apply a final transform matrix to every single vertex whether that one belongs to a separate model part or not. This is not the complicated part, it is a simple matrix multiplication. Otherwise you'll not get anything that looks visually appealing.

Calculating that matrix usually (but not necessarily) involves walking a hierarchy of "bones" which can be represented as quaternions and offsets, matrices, or something else (dual quaternions, or maybe an ONB), and blending the matrix (or SLERPing the underlying transform) in some way according to a "weight" value attached to the vertex. This is the complicated part.

Cal3D does that kind of thing in C++. Ready to use, production code.

You can do the same in a shader too, but it's none easier. Entering the words [font="Courier New"]vertex skinning opengl[/font] in Google gives for example this nVidia code sample. Working minimal implementation, runs on NV30 and upwards. It's Cg based, but translating that to GLSL is probably a matter of minutes, if need be.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!