Skip to content

Commit

Permalink
Reviewed skinning shaders #4412
Browse files Browse the repository at this point in the history
  • Loading branch information
raysan5 committed Oct 22, 2024
1 parent 53f7da2 commit 79e2be6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
8 changes: 4 additions & 4 deletions examples/models/resources/shaders/glsl100/skinning.vs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ void main()
int boneIndex3 = int(vertexBoneIds.w);

vec4 skinnedPosition =
vertexBoneWeights.x*(boneMatrices[boneIndex0]*vec4(vertexPosition, 1.0f)) +
vertexBoneWeights.y*(boneMatrices[boneIndex1]*vec4(vertexPosition, 1.0f)) +
vertexBoneWeights.z*(boneMatrices[boneIndex2]*vec4(vertexPosition, 1.0f)) +
vertexBoneWeights.w*(boneMatrices[boneIndex3]*vec4(vertexPosition, 1.0f));
vertexBoneWeights.x*(boneMatrices[boneIndex0]*vec4(vertexPosition, 1.0)) +
vertexBoneWeights.y*(boneMatrices[boneIndex1]*vec4(vertexPosition, 1.0)) +
vertexBoneWeights.z*(boneMatrices[boneIndex2]*vec4(vertexPosition, 1.0)) +
vertexBoneWeights.w*(boneMatrices[boneIndex3]*vec4(vertexPosition, 1.0));

fragTexCoord = vertexTexCoord;
fragColor = vertexColor;
Expand Down
19 changes: 11 additions & 8 deletions examples/models/resources/shaders/glsl330/skinning.vs
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
#version 330

#define MAX_BONE_NUM 128

// Input vertex attributes
in vec3 vertexPosition;
in vec2 vertexTexCoord;
in vec4 vertexColor;
in vec4 vertexBoneIds;
in vec4 vertexBoneWeights;

#define MAX_BONE_NUM 128
uniform mat4 boneMatrices[MAX_BONE_NUM];

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

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

Expand All @@ -22,13 +25,13 @@ void main()
int boneIndex3 = int(vertexBoneIds.w);

vec4 skinnedPosition =
vertexBoneWeights.x * (boneMatrices[boneIndex0] * vec4(vertexPosition, 1.0f)) +
vertexBoneWeights.y * (boneMatrices[boneIndex1] * vec4(vertexPosition, 1.0f)) +
vertexBoneWeights.z * (boneMatrices[boneIndex2] * vec4(vertexPosition, 1.0f)) +
vertexBoneWeights.w * (boneMatrices[boneIndex3] * vec4(vertexPosition, 1.0f));
vertexBoneWeights.x*(boneMatrices[boneIndex0]*vec4(vertexPosition, 1.0)) +
vertexBoneWeights.y*(boneMatrices[boneIndex1]*vec4(vertexPosition, 1.0)) +
vertexBoneWeights.z*(boneMatrices[boneIndex2]*vec4(vertexPosition, 1.0)) +
vertexBoneWeights.w*(boneMatrices[boneIndex3]*vec4(vertexPosition, 1.0));

fragTexCoord = vertexTexCoord;
fragColor = vertexColor;

gl_Position = mvp * skinnedPosition;
gl_Position = mvp*skinnedPosition;
}

0 comments on commit 79e2be6

Please sign in to comment.