Making An Audio Visualizer In Unity With Blend Shapes & Audio API - Part 1

Audio Visualizer with Unity Audio API & Blend Shapes

This tutorial is going to be split into two parts, The first part (this one) we are going to be covering Blendshapes, what they are, what it's used for and how to use them in Unity and in Part 2 we will cover integrating that with Unity's audio API to get the desired result.
So now you got a feel as to what we will be making.
audio visualizer made in unity
Audio Visualizer We Will Be Making
Blendshapes are just like transitions that the vertices go through to go from being in one position in space to another with the help of a transition value. All the major 3d modelling software from Blender to Maya has it.
Shape keys (blend shapes) in blender
As you can see that the model has 2 shape keys, one called MinValue and another called MaxValue, these names don't carry over into unity but the index of the shape key( blend shape ) matters.
We will be manipulating the MaxValue to make changes to the mesh.
This is how the model looks when it has it's MaxValue set at zero.
You may have guessed now that it is just a basic linear interpolation between these two values.

You can get the blend file I have used from HERE.
The .blend file can be directly imported into unity.
When imported into unity and dragged into the scene you may have noticed something odd about the components that the game object has. Instead of the usual Mesh Renderer we now have a Skinned Mesh Renderer.
We need a Skinned Mesh Renderer when dealing with meshes that can be animated with bones or Blend shapes.
We can also see that the MaxValue blend shape came in the inspector and that it's value is set at 1.
MinValue is not there because that's the basis for which this blend shape was defined with.
Lets look at the Skinned Mesh Renderer API that Unity provides.
 skinnedMeshRenderer.SetBlendShapeWeight(0,100.0f)  
It takes in two parameters the index of blend shape and it's weight ( the amount of strength for that shape ) values for the weight go from 0 to 100.
 skinnedMeshRenderer.GetBlendShapeWeight(0);  
It returns a float value of the weight of the blend shape at that index (int).
Now on to Part 2.
For more Unity development tutorials go HERE.
Support Bitshift Programmer by leaving a like on Bitshift Programmer Facebook Page and be updated as soon as there is a new blog post.
If you have any questions that you might have about shaders or unity development in general don't be shy and leave a message on my facebook page or down in the comments.