Jump to content
• Advertisement

# Shader Skinning Questions

This topic is 2121 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'm creating my shader skinning for animation and although I've got the basic stuff up, I don't know how to get the values required to actually test it out.

I've got this in my vertex shader:

layout (location = 1) in vec3 vertexPosition;
layout (location = 2) in vec3 vertexNormal;
layout (location = 3) in vec2 vertexUV;
layout (location = 4) in vec4 boneIndexes;
layout (location = 5) in vec4 boneWeights;

uniform mat4 transformationMatrix;
uniform mat4 skeletonMatrix[64];

void main()
{
gl_Position = transformationMatrix * (skeletonMatrix[int(boneIndexes.x)] * boneWeights.x) * vertexPosition;
}


My questions are:

1. Is there anywhere that I can learn how to produce the bones matrices? For now I'm passing an identity matrix but it obviously doesn't do anything, and I don't understand the concept of it yet.

For example, I have two Quads with two bones, and the middle vertex in the middle have a 50% weight for each bone. What I don't understand is, I have the bone's position, rotation as a quaternion, and what kind of matrix should I set to get the proper transformation? Applying it as I apply my regular transformation matrix makes the vertex transform around the center origin, and not my bone's, so rotations/translations everything is messed.

2. Is there a way I can use this shader as a "general" model shader? I'm worried that, if I make a shader for some special effect for models, I'll have to duplicate it just because this one is used for animated models. Something that wouldn't affect performance (much) and would be ignored if boneIndexes/boneWeights aren't passed by.

3. Could you suggest any sources on this topic that you consider good? I've found some but either they're too advanced for me (and briefly speaks about stuff which I'm supposed to understand already, but I don't, so I get lost) or they're very abstract ("you pass the bone matrix, multiply it by the weight and that's it").

Any tips/infos for someone beginning this topic are very appreciated!

#### Share this post

##### Share on other sites
Advertisement
1. Bones matrices need to be transformed along the the tree structure they're in so every childbonematrix needs to be multiplied with its parentbonematrix
2. Nope
3. Concept:
http://http.developer.nvidia.com/GPUGems/gpugems_ch04.html
Implementation details and further links
http://www.gamedev.net/topic/647691-collada-bone-matrix-baked-transform-matrix/

Hope that helps

#### Share this post

##### Share on other sites

1- there are multiple construct towards the matricies. Most viable is to not traverse bone matricies for parents (as this is viable only for procedural inverse IK animations- pointless in reality, just use jointed physical body in must case), but instead have a raw model space matrix for every bone at every frame, this way you do not have to worry about what/where it rotates about and you can just add right away 4 influencing bone matricies together, each matrix multiplied by its weight. It is more complex to provide yourself with the matricies, but, if you have your mesh in 3ds max for example, the bone identities matricies will result in the very mesh, but, selecting a simple bone and applying transformation operations on it (move-rotate-bla bla) will simply result in the very model space transformation steaming from identity matrix- pick the tranformation in model space, not the bone local one.

2- you should use separate shader for unskinned meshes (just as you use separate vertex declaration and vx streams), for the if-else branching in shaders is terrible thing towards performance.

3- cannot think of any, but googling the right way will get you to the best of all tuts, though you are using opengl, I would google for "HLSL skinning on gpu" as well, since opengl tutorials come quite expensive :(

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Now

• 13
• 18
• 29
• 11
• 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!