Skip to content

Commit

Permalink
Transform the vertex normals by the animated matrix (#4646)
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffM2501 authored Dec 29, 2024
1 parent c0f2067 commit f355d6f
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion examples/models/resources/shaders/glsl330/skinning.vs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@
in vec3 vertexPosition;
in vec2 vertexTexCoord;
in vec4 vertexColor;
in vec3 vertexNormal;
in vec4 vertexBoneIds;
in vec4 vertexBoneWeights;

// Input uniform values
uniform mat4 mvp;
uniform mat4 matNormal;
uniform mat4 boneMatrices[MAX_BONE_NUM];

// Output vertex attributes (to fragment shader)
out vec2 fragTexCoord;
out vec4 fragColor;
out vec3 fragNormal;

void main()
{
Expand All @@ -29,9 +32,18 @@ void main()
vertexBoneWeights.y*(boneMatrices[boneIndex1]*vec4(vertexPosition, 1.0)) +
vertexBoneWeights.z*(boneMatrices[boneIndex2]*vec4(vertexPosition, 1.0)) +
vertexBoneWeights.w*(boneMatrices[boneIndex3]*vec4(vertexPosition, 1.0));


vec4 skinnedNormal =
vertexBoneWeights.x*(boneMatrices[boneIndex0]*vec4(vertexNormal, 0.0)) +
vertexBoneWeights.y*(boneMatrices[boneIndex1]*vec4(vertexNormal, 0.0)) +
vertexBoneWeights.z*(boneMatrices[boneIndex2]*vec4(vertexNormal, 0.0)) +
vertexBoneWeights.w*(boneMatrices[boneIndex3]*vec4(vertexNormal, 0.0));
skinnedNormal.w = 0.0;

fragTexCoord = vertexTexCoord;
fragColor = vertexColor;

fragNormal = normalize(vec3(matNormal*skinnedNormal));

gl_Position = mvp*skinnedPosition;
}

0 comments on commit f355d6f

Please sign in to comment.