# Morphing

#### <a class="anchor" id="bkmrk--5"></a>Description

This chapter briefly describes the morphing technique supported by [Candera](http://dev.doc.cgistudio.at/APILINK/namespace_candera.html "[DataBinding_RefTypeSample]").

**See also:**

<div class="contents" id="bkmrk-morphing-mesh-in-sce"><div class="contents"><div class="textblock">- <span style="color: rgb(230, 126, 35);">[Morphing Mesh](https://doc316en.candera.eu/link/130#bkmrk-shape-morphing)</span> in SceneComposer User Manual

</div></div></div>#### <a class="anchor" id="bkmrk--7"></a>Example Solutions

Refer to following solutions in folder *cgi\_studio\_player/content/Tutorials/08\_SpecialRenderTechniques/0801\_Special3DRenderTechniques*

<div class="contents" id="bkmrk-morphsolution-multim"><div class="textblock">- MorphSolution
- MultiMorphing\_MultiMorphShader
- MultiMorphing\_AnimationGroup

</div></div>#### **Introduction** 

##### <a class="anchor" id="bkmrk--8"></a>Morphing

Morphing means transforming the 3D geometry of an object smoothly from one shape into another.

Morphing itself (smooth interpolation between vertices) is done in a shader (not on the CPU).

<div drawio-diagram="2422"><img src="https://doc316en.candera.eu/uploads/images/drawio/2023-02/drawing-4-1677221269.png" alt=""/></div>

<div class="contents" id="bkmrk--0"><div class="contents"><div class="textblock"><center></center>  
</div></div></div>##### <a class="anchor" id="bkmrk--10"></a>What you need for Morphing

**Suitable content**: "Morph targets" are different geometric states of the same object. The input vertices must correspond one-to-one between morph targets. This means, to morph between two shapes, you need **two [VertexBuffer](http://dev.doc.cgistudio.at/APILINK/class_candera_1_1_vertex_buffer.html "The VertexBuffer encapsulates the attributes of an uploaded VertexGeometry. It holds the actual handl...")** with exactly the **same number of vertices**.

**An instance of [MorphingMesh](http://dev.doc.cgistudio.at/APILINK/class_candera_1_1_morphing_mesh.html "MorphingMesh is a Mesh that stores weight values for morphing, and activates them as uniforms at rend...")**: This is a [Mesh](http://dev.doc.cgistudio.at/APILINK/class_candera_1_1_mesh.html "The class Mesh represents a three-dimensional rigid body object defined by polygons. The Mesh's polygonal surface is defined by its VertexBuffer. Each Mesh must have exactly one Appearance set, in order to specify how the Mesh geometry is rendered.") that stores

<div class="contents" id="bkmrk-the-spliced-vertex-b"><div class="contents"><div class="textblock">- the spliced vertex buffer created from the vertex buffers to be morphed (see [MorphingMesh::CreateSplicedVertexBuffer](http://dev.doc.cgistudio.at/APILINK/class_candera_1_1_morphing_mesh.html#a0a238d9060703803343a130616afb2c1))
- weight values for each of the shapes, which are activated as shader uniforms at render time (see [MorphingMesh::SetMorphWeight](http://dev.doc.cgistudio.at/APILINK/class_candera_1_1_morphing_mesh.html#a6aaa490ea43613163e9e69a9aa5f94e9))
- The appearance of the [MorphingMesh](http://dev.doc.cgistudio.at/APILINK/class_candera_1_1_morphing_mesh.html "MorphingMesh is a Mesh that stores weight values for morphing, and activates them as uniforms at rend...") must define a suitable morphing shader, which matches the number of shapes to be morphed (see **RefTransLight1Morph** vertex shader for morphing two shapes)

</div></div></div>**Dynamics**: Morphing is about change, so an application will have to set some morphing parameters (often depending on time). Use [Animation::AllMorphWeightsPropertySetter](http://dev.doc.cgistudio.at/APILINK/class_candera_1_1_animation_1_1_all_morph_weights_property_setter.html "A PropertySetter that sets all morph weights of a MorphingMesh.") to animation all the weight values of the [MorphingMesh](http://dev.doc.cgistudio.at/APILINK/class_candera_1_1_morphing_mesh.html "MorphingMesh is a Mesh that stores weight values for morphing, and activates them as uniforms at rend...").

#### **Morphing Examples** 

##### <a class="anchor" id="bkmrk--11"></a>Morphing between 2 Morph Items

In below example solution, the reference shader **RefTransLight1Morph\_RefColor** is used to morph between two morph items, by default having weight value 1,00 on the logo.

<div class="contents" id="bkmrk-morphsolution-from-f"><div class="contents"><div class="contents"><div class="textblock">- *MorphSolution* from folder *cgi\_studio\_player/content/Tutorials/08\_SpecialRenderTechniques/0801\_Special3DRenderTechniques*

</div></div></div></div><div drawio-diagram="2423"><img src="https://doc316en.candera.eu/uploads/images/drawio/2023-02/drawing-4-1677221366.png" alt=""/></div>

<div class="contents" id="bkmrk--2"><div class="contents"><div class="textblock">  
</div></div></div>The animation part of this solution animates both weight values and also adds a rotation animation.

##### <a class="anchor" id="bkmrk--13"></a>Morphing between Multiple Shapes using Shader

Since a MorphingMesh is capable of handling up to 8 different vertex buffers, a special morphing shader must be used for more than 2 shapes. A morphing shader handling 5 shapes is used in the example below:

<div class="contents" id="bkmrk-multimorphing_multim"><div class="contents"><div class="contents"><div class="textblock">- *MultiMorphing\_MultiMorphShader* from folder *cgi\_studio\_player/content/Tutorials/08\_SpecialRenderTechniques/0801\_Special3DRenderTechniques*

</div></div></div></div><div drawio-diagram="2425"><img src="https://doc316en.candera.eu/uploads/images/drawio/2023-02/drawing-4-1677221435.png" alt=""/></div>

<div class="contents" id="bkmrk--4"><div class="contents"><div class="textblock"><center></center>  
</div></div></div>##### <a class="anchor" id="bkmrk--15"></a>Morphing between Multiple Shapes using AnimationGroup

As an alternative to using a multi morph shader, multi-step morphing can also be realized by using an AnimationGroup, chaining separate morphing animations for each morphing shape pair. This approach is useful in case a specific target shader compiler has some restrictions regarding the maximum number of shader parameters.

<div class="contents" id="bkmrk-multimorphing_animat"><div class="textblock">- *MultiMorphing\_AnimationGroup* from folder *cgi\_studio\_player/content/Tutorials/08\_SpecialRenderTechniques/0801\_Special3DRenderTechniques*

</div></div>