From f355d6f1db7d39b983d3a3fa06f9d29447dcc382 Mon Sep 17 00:00:00 2001 From: Jeffery Myers Date: Sat, 28 Dec 2024 16:07:52 -0800 Subject: [PATCH] Transform the vertex normals by the animated matrix (#4646) --- .../models/resources/shaders/glsl330/skinning.vs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/examples/models/resources/shaders/glsl330/skinning.vs b/examples/models/resources/shaders/glsl330/skinning.vs index 73ecca51e9c2..43bbca76c18e 100644 --- a/examples/models/resources/shaders/glsl330/skinning.vs +++ b/examples/models/resources/shaders/glsl330/skinning.vs @@ -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() { @@ -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; } \ No newline at end of file