Implementing GPU-based skinning
The huge advantage of GPU-based calculations is the sheer amount of parallel execution achieved using shaders. We usually use only one CPU core to calculate the vertex position because multi-threading in code is complex and not easy to implement. In contrast, a GPU can run dozens or hundreds of shader instances in parallel, depending on the model and driver. The shader units are also specialized to do vertex and matrix operations, generating even more speed in the vertex position calculation.
Moving the joints and weights to the vertex shader
To move the calculation to the vertex shader, a new shader pair needs to be created. We can use the gltf.vert
vertex shader and the gltf.frag
fragment shader as the basis and copy the files to new files called gltf_gpu.vert
and gltf_gpu.frag
.
While the fragment shader can be used without changes, the vertex shader needs a couple of additions:
layout (location = 3) in vec4 aJointNum;
layout (location...