Much progress has been made, but I won’t go into all of it.
Mainly I want to talk about the performance boosts over the month.
Skinned Mesh baking is a daunting task for any who’ve tried it.
In our original plan we had one color so one material per object in the scene, our Skinned Meshes were no different, so we planned a method of combining their skeletons.
We had this process in place with a small editor script for a little over a year.
Now, baking can take a while so we found, so we set out to bake only NPCs/enemies who can’t change their gear.
Our shader system restricts a material to 10 of our color IDs to draw from the palette, since we were doing one color per mesh for most of the skinned models I grouped them by color and group the colors into collections of 10 colors to disperse, differentiating them by hard-coding a uv coordinate per vertex to a generated 10 color texture, separating team colored objects, and things like capes which have cloth on them etc.
What resulted didn’t start out beneficial…
Apparently our script for the past year wasn’t resetting the bind poses of our meshes, though they shared the same skeleton.
After a long bit of research and trial and error we do this:
For each vertex of each skinned mesh, transpose the coordinate to world space from the originating bindpose, according the originating bone weights.
Then immediately inverse transpose with the resulting bindpose, using the originating bone weights. This is the new position of each vertex.
Also we added some bones to accommodate the bone reductions we had imported from Maya, which made the renderer confused.
This wasn’t all though, we could then apply one of many versions of skinned mesh combining which we tried before resulting in re-positioning every vertex. Every version of combining skinned meshes assumed each mesh had more bones to add, so combining 16 meshes, with our 35 bone rig would result in 560 bones, and that tanks performance.
We had to do a post calculation to remap all of the boneweights to point towards 35 indices of the bones, which could be hundreds of thousands of iterations to the now larger mesh.
Once the new skinned mesh renderer is complete we save the texture asset, the material asset, assign the renderer to a gameObject, store that as a prefab, store the prefab in a scriptableObject, and mark the scriptableObject with the assetbundle of the level the character is for.
The process for how many rosters of units we have for NPCs (enemies) takes 6 – 8 hours, even after some refactoring.
If you take a look though, you can’t even tell we’re going from
209 visible Skinned meshes to 36, and this helps tremendously on lower end hardware.
Static level meshes were easier, baking those was more of a matter of how to group them for their dynamic abilities, can this get transparent when blocking a character, or is this parented to something rotating, etc.
anyway, truly a worthwhile chunk of work.