Hello,
I try to move from CPU skinning to GPU skinning.
So far I managed to load the model and animation files without any problems.
I`ve rendered the bones and the model on the CPU to make sure that everything moves as supposed.
But when I`m passing the bone matrix, weights and indices to the shader everything gets messed up.
I think the problem is the way I have build the bone Matrix…
I use a std:vector that contains mat4`s (I can access the elements of the matrix by their “elements[0 - 15]” parameter).
While passing single matrices works like a charm, passing a vector of matrices might not work as I think it does.
This is how I pass the matrix (my matrices are row major so I have to transpose them):
GLuint boneLoc = glGetUniformLocation(m_Effect.getProgram(), "boneMatrix");
glUniformMatrix4fv(boneLoc, m_boneMatrix.size(), GL_TRUE, &m_boneMatrix[0].elements[0]);
Then I`m trying to use the bone matrices in the shader to calculate the final positions…
( this part is following the tutorial at www.3Dgep.com )
#version 410 core
layout(location = 0) in vec3 position;
layout(location = 1) in vec3 normal;
layout(location = 2) in vec2 texCoords;
layout(location = 3) in vec4 weight;
layout(location = 4) in ivec4 boneIndex;
out vec2 outTexCoords;
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
uniform mat4 boneMatrix[100]; //a fixed size for testing.. will be dynamic as soon as the rest works
void main(void)
{
mat4 matTransform = boneMatrix[boneIndex.x] * weight.x;
matTransform += boneMatrix[boneIndex.y] * weight.y;
matTransform += boneMatrix[boneIndex.z] * weight.z;
float finalWeight = 1.0f - ( weight.x + weight.y + weight.z );
matTransform += boneMatrix[boneIndex.w] * finalWeight;
vec4 objPos = matTransform * vec4( position, 1.0 );
vec4 objNormal = matTransform * vec4( normal, 0.0 ) ;
gl_Position = projection * view * model * objPos;
outTexCoords = texCoords;
(.. normals, lightning etc...)
}
Is it the way I store and pass the matrices? Or is there something obviously wrong with my shader?
~BobbyLeChimp