Search Unity

Creating an 'audio-reactive' mesh

Discussion in 'Shaders' started by eco_bach, Feb 9, 2016.

  1. eco_bach

    eco_bach

    Joined:
    Jul 8, 2013
    Posts:
    1,601
    Really inspired by this example



    All it says in the comments is that the mesh was transformed using a vertex shader. I've written some very basic shaders and gone thru some tutorials but this is somewhat beyond my abilities. How would I get the audio data into the shader? Can anyone point me to sample code or tutorials that deal with mesh manipulation using shaders?
     
    moogil likes this.
  2. smd863

    smd863

    Joined:
    Jan 26, 2014
    Posts:
    292
    The surface shader examples has exactly what you are looking for. Find the one called "Normal Extrusion with Vertex Modifier".

    Every frame you would calculate the volume of your audio, and use it to set the "_Amount" shader property.

    To get the spiky look, you simply assign each vertex a random number from 0 to 1, and put it into one of the vertex properties. Typically, you'd use one of the unused color channels or UV set. Most 3D modeling packages would have tools to do this, or you could process the mesh in Unity.

    If you put the random value in the alpha channel, then you'd have something like this in the vertex shader:
    Code (csharp):
    1. v.vertex.xyz += v.normal * _Amount * v.color.a;
    So some parts of the mesh would deform a lot with volume, and some would stay completely static. You could use this same technique to get different parts of the mesh to react to different audio frequencies to generate any type of audio visualization you wanted.
     
    yaffa, LastMonopoly and solkar like this.