glUniformMatrix4fvARB(shAttr->getSkinMatricesUniformLoc(), pDm->joints.size(), GL_FALSE, skinMatrices);
glBegin(GL_TRIANGLES);
for(int j=0; j<refGroup.faces.size(); j++){
CMD5Face &face = refGroup.faces[j];
for(int k=0; k<3; k++) {
CMD5VertexInst &vertex = group.vertices[face.vertexIndices[k]];
CMD5Vertex &refVertex = refGroup.vertices[face.vertexIndices[k]];
glVertexAttrib3fvARB(shAttr->getTangentAttribLoc(), refVertex.tangent.data());
glVertexAttrib4ivARB(shAttr->getBoneIndexAttribLoc(), refVertex.boneIndices);
glVertexAttrib4fvARB(shAttr->getWeightAttribLoc(), refVertex.weights);
glTexCoord2fv(refVertex.texCoords.data());
glNormal3fv(refVertex.normal.data());
glVertex3fv(refVertex.position.data());
}
}
glEnd();
The vertex positions are in bind pose and the skinMatrices is an array of floats with size maxBones*16*sizeof(float).
The skinMatrices consist of a product of the bone transformation to skinned pose and the inverse bind pose matrix.
I have tested that the matrices, weights and so on are ok by doing the transformation on CPU.
The vertex shader part that does the skinning is following:
uniform vec3 cameraPos;
uniform vec3 lightDir;
uniform int skinned;
uniform mat4 skinMatrices[50];
varying vec3 varDiffuse;
varying vec3 varAmbient;
varying vec3 varLightDir;
varying vec3 varHalfVector;
attribute vec3 tangent;
attribute ivec4 boneIndices;
attribute vec4 weights;
void main()
{
vec4 pos = vec4(0.0);
vec3 normal = vec3(0.0);
vec3 tangent2 = vec3(0.0);
if(skinned!=0){
for(int i=0; i<4; i++){
int index = boneIndices;
if(index>-1){
pos = pos + (skinMatrices[index]*gl_Vertex)*weights;
normal = normal + skinMatrices[index]*vec4(gl_Normal,0.0)*weights;
tangent2 = tangent2 + skinMatrices[index]*vec4(tangent,0.0)*weights;
}
}
}
else{
normal = normalize(gl_Normal);
tangent2 = normalize(tangent);
pos = gl_Vertex;
}
gl_Position = gl_ModelViewProjectionMatrix*pos;
}
I get nothing rendered. Can you see any flaws in the skinning related code?
Of course not all is shown above, but it would be nice to know if you find anything wrong with
what I have shown.