Vertex Skinning Issues

Hey all,
I’ve been working on a 3d project involving Source Engine models and have gotten stuck with vertex skinning in GLSL.
I’ve tried a few approaches based on resources I’ve seen - examples from Khronos, Nvidia, even other projects with a similar aim, which don’t seem to have problems, and yet here I am, and I can’t get it to work.
It seems that for no real reason, most vertices have their position set to (0, 0, 0) when I try to render them despite nothing really appearing to be the cause - I’ve even tried passing identity matrices through to the shader and it still doesn’t work right.
Currently the code I’ve landed on is this:

#version 330

const int MAX_JOINTS = 150;

attribute vec3 aPosition;
attribute vec3 aNormal;
attribute vec2 aTexCoord0;
attribute vec2 aTexCoord1;
attribute vec3 aTangent;
attribute vec3 aBoneWeights;
attribute ivec4 aBoneIDs;

uniform mat4 projectionMatrix;
uniform mat4 viewMatrix;
uniform mat4 modelMatrix;
uniform vec3 viewPos;
uniform mat4 jointMatrices[MAX_JOINTS];

out VS_OUT{
    vec2 texCoord0;
    vec2 texCoord1;
    vec3 fragPos;
    vec3 viewPos;
    vec3 normal;
} vs_out;

mat4 getBoneMatrix(int boneID){    
    return jointMatrices[boneID];
}
mat4 accumulateSkinMatrix(){
    mat4 result;
    vec3 boneWeights = aBoneWeights;
    result = boneWeights.x * getBoneMatrix(int(aBoneIDs.x));
    result = result + boneWeights.y * getBoneMatrix(int(aBoneIDs.y));
    result = result + boneWeights.z * getBoneMatrix(int(aBoneIDs.z));
    return result;
}

void main(){ 
    vec4 newVertex = vec4(0.0);
    vec4 newNormal = vec4(0.0);
    
    mat4 skinMatrix = accumulateSkinMatrix();
    newVertex = skinMatrix * vec4(aPosition, 1.0);
    newNormal = skinMatrix * vec4(aNormal, 0.0);

    vs_out.fragPos = vec3(modelMatrix * newVertex);

    vs_out.texCoord0 = aTexCoord0;
    vs_out.texCoord1 = aTexCoord1;

    vs_out.normal = mat3(transpose(inverse(modelMatrix))) * newNormal.xyz;
    vs_out.viewPos = viewPos;

    gl_Position = projectionMatrix * viewMatrix * modelMatrix * newVertex;
}

I won’t bother including the fragment shader as it’s very simplistic and only really renders the texture at the given TexCoords, which aren’t causing issues.

The result I get with passing data from the file itself is:

And when I set all vertex weights to be 1.0 (by changing boneWeights to be equal to vec3(1.0) instead of aBoneWeights, I get a mostly working but still obviously broken render:

Debugging in RenderDoc hasn’t given me too much of a hint either. I know that I’m correctly calculating the bone positions as the lines beneath the model are being rendered after the model itself for debugging and are in the right place. It shows that I’m passing matrices correctly for the bones each time but for some inexplicable reason the vertex position is being set to 0.

I’ve made the most progress on it today after weeks of scratching my head and doing other things but I’d really like to get this right and move onto other things. Any insights would be greatly appreciated.

Nothing strikes me as obviously wrong with the shader code you’ve provided. Given that you have some vertices outputting as a zeroed vector, it’s probably that for those verticies either [icode]skinMatrix[/icode] is a zeroed matrix or [icode]aPosition[/icode] is a zeroed vector. As a sanity check I’d start by setting [icode]skinMatrix[/icode] to the identity matrix to make sure [icode]aPosition[/icode] is what you expect. If it’s still distorted, there’s an issue with the vertex data you’re passing in. Otherwise, I’d try and output your skinning data as the fragment colour to see if that data is being passed in correctly. It seems likely that the issue would be there.