There is this MeshMorpher: http://wiki.unity3d.com/index.php/MeshMorpher
which interpolates between two meshes with the same number of vertices.
However, each frame it modifies the vertices property of a Mesh on the CPU side which results in bad performance - especially when there are many objects animated with MeshMorpher. I’ve written a GPU accelerated mesh morpher, and I’ve felt like sharing, so here it is. ![]()
It is capable of interpolating between 2 meshes, each of which must have the same number of vertices. I am using the tangents array of a Mesh to store the second set of vertices. Blending between the two meshes is done in the shader. There are two shaders included: VertexAnimationDiffuse.shader, and VertexAnimationSpecular.shader.
I’ve experienced a huge performance gain, animating > 100 models compared to MeshMorpher.
The whole thing isn’t rocket science, but rather simple. Anyways, maybe it is helpful for someone.
What do you think of it?
Feedback is most welcome.
Since I’m not very experienced with Mechanim, I’ve wondered if there is some Mechanim feature which could do the same. Or is Mechanim only working with Rigs? I want to avoid, having to rig all my simple models which I can animate using VertexAnimation, because for some of my models it is sufficient for me, to just interpolate between two keyframes. In such cases, I guess, VertexAnimation is the fastest solution since it doesn’t have to calculate bone matrices compared to Mechanim. (Unless Mechanim has some fancy optimizations, I am not aware of) Any thoughts on that?
UPDATE:
I’ve updated the attached unitypackage. Now it should also work on mobile devices.
Basically, I’ve only added the following #pragma statement to the shaders:
#pragma glsl_no_auto_normalization
UPDATE 2:
Normals are now also interpolated correctly. The normals of the other keyframe are stored in a mesh’s color attribute.