Home Articles Tutorials Resources About

Hardware vertex morphing


By Rim van Wersch, Februari 19 2006

Vertex morphing is a technique which allows for the deformation of a base mesh by using morph targets, meshes with identical vertices to the base mesh, but with altered vertex positions. This technique is commonly used for facial expressions on 3D characters and for describing transformations that are not easily described by bones. For a more thorough overview of vertex morphing, please refer to Circlesoft's DirectMesh2 specs.


How does it work?

Vertex morphing works by interpolating a final vertex position between a base position and one or more target positions, which are typically defined in seperate meshes which are often referred to as morph targets. The process of morphing a single vertex using two morph targets is displayed below in figure 1. As a side note, our sample uses linear interpolation to calculate the final vertex position, but morphing may also benefit from sin/cubic interpolation for smoother animation.




? ?Figure 1. Morphing a single vertex to two targets


In realtime graphics though, it is not common to work with the complete morph targets at runtime (this technique is mostly used in 3D modelling packages), but rather a subset of the vertices that need to be morphed to interpolate to a specific target. The benefit of this 'sparse' technique is of course that it can be more efficient, but at the cost of having to do the morphing on the CPU. On shader model 3 hardware (NVidia 6 series, ATI 1x00 series and better) however, a sparse morph technique using vertex texture lookups may be used that can also runs fully on the GPU.

The technique introduced here does use complete morph targets though, so why would you want to use it? A simple answer would be that it will work on SM2 hardware, which is a strong argument since SM3 has not yet hit the mainstream at the time of writing. But a more solid argument is that though it may not always be as efficient as sparse morphing, it does run completely on the GPU and for models with complex morph targets (ones that affect a large portion of the mesh, like in the NVidia Dolphin demo) it probably runs faster than software morphing.

To support interpolating the full morph targets on the GPU, this technique sends the base mesh and the targets to the video card on seperate vertex streams. This also limits this technique to the number of vertex streams your target video card supports. SM2 cards typically support 8 streams, allowing for 1 base mesh and 7 morph targets. So this technqiue is mainly suited for animating models with complex yet few simultaneously active morph targets.


About the sample project

The sample project uses the technique explained above to render our Johnny fish character with 3 morph targets. To this end, it loads the Johnny base mesh and the 3 targets and sets these up on 4 seperate streams, using an appropriate vertex declaration to interleave the data on the GPU. This gives us access to the morph target vertices in the vertex shader, so we can interpolate the final vertex positions using the weights we set for each target.

The source code is thoroughly documented to describe this process, along with a number of suggestions for optimization. The overall technique is relatively simple and provides a nice example of what techniques can be implemented by using multiple vertex streams. If you have any questions, comments or suggestions on this technique or other (hardware) vertex morphing techniques in C#, we'd gladly hear from you.



Files for this tutorial

Filename Size
? hardwarevertexmorphing.zip 4.6 MB
?
MDX info is an initiative by NetForge. All content is copyright ? 2005-2006 by its respective authors | About MDX info | Terms of Use |