Skip to content

Commit

Permalink
REVIEWED: skinning shader for GLSL 100 #4412
Browse files Browse the repository at this point in the history
  • Loading branch information
raysan5 committed Oct 22, 2024
1 parent fe66bfb commit b2dca72
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
15 changes: 9 additions & 6 deletions examples/models/resources/shaders/glsl100/skinning.fs
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
#version 100

// Input vertex attributes (from vertex shader)
in vec2 fragTexCoord;
in vec4 fragColor;
precision mediump float;

// Output fragment color
out vec4 finalColor;
// Input vertex attributes (from vertex shader)
varying vec2 fragTexCoord;
varying vec4 fragColor;

// Input uniform values
uniform sampler2D texture0;
uniform vec4 colDiffuse;

void main()
{
// Fetch color from texture sampler
vec4 texelColor = texture(texture0, fragTexCoord);
finalColor = texelColor*colDiffuse*fragColor;

// Calculate final fragment color
gl_FragColor = texelColor*colDiffuse*fragColor;
}
31 changes: 17 additions & 14 deletions examples/models/resources/shaders/glsl100/skinning.vs
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
#version 100

in vec3 vertexPosition;
in vec2 vertexTexCoord;
in vec4 vertexColor;
in vec4 vertexBoneIds;
in vec4 vertexBoneWeights;
#define MAX_BONE_NUM 64

#define MAX_BONE_NUM 128
uniform mat4 boneMatrices[MAX_BONE_NUM];
// Input vertex attributes
attribute vec3 vertexPosition;
attribute vec2 vertexTexCoord;
attribute vec4 vertexColor;
attribute vec4 vertexBoneIds;
attribute vec4 vertexBoneWeights;

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

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

void main()
{
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.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));

fragTexCoord = vertexTexCoord;
fragColor = vertexColor;

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

0 comments on commit b2dca72

Please sign in to comment.