I am currently developing a framework that allows me to conveniently render a larger number of animated models.
A model is organized as a simple hierarchy of bones, with the root being the torso/pelvis, generally:
So, as pseudo code, I am currently rendering a model like this:
RenderBone(Bone b, Mat4x4 currentTransform){
Mat4x4 pos = currentTransform * b.boneTransform;
SetUniform("transformation", pos);
Draw(bone.mesh);
for each Bone bc in b.children do{
RenderBone(bc, pos);
}
}
So for a single actor that uses a model with n bones I need n SetUniform (not counting stuff like setting textures) and n draw calls.
Trying to reduce that overhead, and render all actors using the same model at once, I thought about switching to instanced rendering.
However, all information and tutorials I could find are about drawing cubes, spheres or similar simple objects. Nowhere I could see some simple, comprehensible information about how to use instanced drawing to render models where each part (bone) requires a different transformation matrix to be given to the shader.
So, the problem:
Using glVertexAttribDivisor
or gl_InstanceID
I can only specify an instance-related matrix, not a bone-realted matrix. How do I apply my bone transformations then?
The only feasible solution I could think of is - instead of instancing the entire model - I can instance each bone. Thus drawing all instances of one bone type, then another one, etc. But then I would still have to update the buffer with the transformation matrices relatively often, and it's more housekeeping code.
So is this best best option? Or, more generally, are there better not-too-complicated ways of rendering? Or does instanced rendering only really shine when using it with static geometry?