Skip to content

Instantly share code, notes, and snippets.

@alanhaugen
Created September 1, 2020 18:26
Show Gist options
  • Save alanhaugen/128b217786d310d924a9c1d5f05ed435 to your computer and use it in GitHub Desktop.
Save alanhaugen/128b217786d310d924a9c1d5f05ed435 to your computer and use it in GitHub Desktop.
#version 330 core
const int MAX_JOINTS = 120;
layout(location = 0) in vec3 vVertex; // object space vertex position
layout(location = 1) in vec4 vColor; // per-vertex colour
//layout(location = 2) in vec4 vNormal; // per-vertex normals
layout(location = 3) in vec2 vTexcoord; // per-vertex texcoord
layout(location = 4) in vec4 weights; // per-vertex weights
layout(location = 5) in ivec4 joints; // per-vertex joints
//output from the vertex shader
smooth out vec4 vSmoothColor; // smooth colour to fragment shader
smooth out vec2 vSmoothTexcoord;
//uniform
uniform mat4 MVP; // combined modelview projection matrix
uniform vec4 colorTint;
uniform mat4 animatedMatrices[MAX_JOINTS];
void main()
{
// calculate skinning matrix
mat4 skin = animatedMatrices[joints.x] * weights.x;
skin += animatedMatrices[joints.y] * weights.y;
skin += animatedMatrices[joints.z] * weights.z;
skin += animatedMatrices[joints.w] * weights.w;
/*mat4 skin = mat4(1.0f);
if (gl_VertexID < MAX_JOINTS)
{
mat4 skin = animatedMatrices[gl_VertexID];
}*/
// assign the per-vertex colour to vSmoothColor varying
vSmoothColor = vec4(vColor) * colorTint;
vSmoothTexcoord = vTexcoord;
// get the clip space position by multiplying the combined MVP matrix with the object space
// vertex position
gl_Position = MVP * skin * vec4(vVertex, 1.0);
// vNormal = vec4(model * skin * normal);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment