Custom Unity Morphing including Skeletal Animation with Mecanim and LOD

The character feature customization scripts enable multiple characters to be created from a base character, using morph targets exported from Max. This system now includes enabling facial animation and LOD.

The system already allows for different accessories like hair, facial hair and their morph targets for facial and customization animation, but now includes calculating tangents to enable bump mapped shaders, as well as heavily optimized vertex and tangent caches.

The models now also include eyes and teeth, that also morph along with the characters customized features, and facial expressions.

This document describes the development workflow.

Skinned meshes are no longer instanced within Unity, and had to be cloned, because as the vertices are morphed, they do not influence other skinned meshes from the same original skinned mesh. Customizations are persisted using File IO, files are about 3K in size, currently, and are reloaded to create a character, that will contain the custom LOD system.

The LOD system uses custom LOD ranges, and can be configured to change the actual character mesh to a lower LOD if within certain range from the camera, as well as LOD for accessories, including culling after a certain distance, and even changes the bumped material, of the character, to a normal diffuse after a certain distance, all configurable. This keeps the framerates very acceptable with the only lag happening as the character loads, and requests it’s caches from the global cache.

Vertices of the meshes are cached, and morph targets, so when asked for again, not read from the GPU/CPU shared memory, but rather from a cache, morph target vertices are culled to only contain the vertices that actually influence the base, as well as their indices, in the case of the target influencing all vertices, the original cache is re-used.

The character customization screen was used to create 4 unique characters from the base ‘Joe’ character, and their customizations persisted, and loaded over 20 odd characters.

Each performing their own blinking, smiling and frowning custom morphing, and usual random skeletal animation tests using Mecanim.

Including looking at the camera when it is within 5 meters, using Mecanim and IK.

There are about 12 characters in this demo, with the LOD 0, at about +12K, and the LOD 1, at about +2K. (triangles). All 12 were created from 4 unique characters, using the customization scripts and morph targets, once a customization is completed, the customization memory is eligible for GC *except for globally cached, and re-usable vertex caches, their references are only set to null. Accessories like Hair, beard, brows moustache, eyes and teeth are also culled from a certain distance. Eyes and teeth are culled before hair, and hair before material change to diffuse, from bump mapped. Yielding excellent FPS results.

The second last piece of this puzzle is the visemes, for facial animation and expressions. But will reuse the custom morphing system as is.

 

Leave a Reply