Pre-generating the skin matrix
One of the bigger problems with Vertex Shader Skinning is the number of uniforms that the system takes up. One mat4
object takes up four uniform slots and the skinned vertex shader currently has two matrix arrays that have 120 elements each. That comes to a total of 960 uniform slots, which is excessive.
What happens with those two matrix arrays in the vertex shader? They get multiplied together, as follows:
mat4 skin=(pose[joints.x]*invBindPose[joints.x])*weights.x; skin += (pose[joints.y]*invBindPose[joints.y])*weights.y; skin += (pose[joints.z]*invBindPose[joints.z])*weights.z; skin += (pose[joints.w]*invBindPose[joints.w])*weights.w;
One easy optimization here is to combine the pose * invBindPose
multiplication so that the shader only needs one array. This does mean that some of the skinning process is moved back to the CPU, but this change clears up 480 uniform slots.
Generating the skin matrix
Generating...