Implementing GPU skinning
You created some basic shaders in Chapter 6, Building an Abstract Renderer and OpenGL—the static.vert
shader and the lit.frag
shader. The static.vert
shader can be used to display a static, unskinned mesh, which is loaded with the LoadMeshes
function. The static.vert
shader can even display a CPU skinned mesh.
Create a new file, skinned.vert
. Follow these steps to implement a vertex shader that can perform matrix palette skinning. The code is very similar to the one used for static.vert
; the differences are highlighted:
- Each vertex gets two new components—the joint indices that affect the vertex and the weight of each joint. These new components can be stored in
ivec4
andvec4
:#version 330 core uniform mat4 model; uniform mat4 view; uniform mat4 projection; in vec3 position; in vec3 normal; in vec2 texCoord; in vec4 weights; in ivec4 joints;
- Next, add two matrix arrays to the shader—each array is
120
in length. This length...