Mesh Triangles Partially Colored

Hi everyone, I have a question about shading a mesh I created procedurally and I’m not sure if this is the place to post it.

I created a circular piece of mesh where the inside vertices move based on a spectrum analyzer. I apply colors to the vertices through the script and assigned a custom vertex shader so the colors show up. I also had to change my main camera’s rendering path to 'Legacy Deferred (light prepass) for the colors to show up. As of now the outside of my triangles light up the correct color but the end vertices all are void of color. I’ve tried changing the normals but that doesn’t help.

Any help would be greatly appreciated! I’m also open to suggestions on how to achieve this effect in a more efficient way. Here are the two scripts I assume would be the cause of this problem, let me know if you need to see anything else.

using UnityEngine;
using System.Collections;

public class CreatePlaneMesh : MonoBehaviour {

    private int triVert = 0;
    private int triCount = 0;
    private float depth = 100f;
    public float amp = 10f;

    private AudioVars levels;

    // Initialization
    void Start () {
        MeshFilter mf = GetComponent<MeshFilter>();
        Mesh mesh = new Mesh();
        mf.mesh = mesh;

        levels = GameObject.Find("AudioVarsObject").GetComponent<AudioVars>();
       
        Vector3[] vertices = new Vector3[25];
        for (int i=0; i<=24; i+=2) {
            vertices[i]= new Vector3(4*Mathf.Cos(i*Mathf.PI/12),4*Mathf.Sin(i*Mathf.PI/12),0f+depth);
        }
        for (int i=1; i<24; i+=2) {
            vertices[i]= new Vector3(1.5f*Mathf.Cos(i*Mathf.PI/12),1.5f*Mathf.Sin(i*Mathf.PI/12),6f+depth);
        }
       
        //Triangles
        int[] tri = new int[36];
        for (int i=0; i<36; i++)
        {
            tri[i] = triVert;
            triVert++;
            triCount++;
            if (triCount>2) {
                triVert--;
                triCount=0;
            }
        }
       
        Color32[] colors32 = new Color32[25];
        for (int i=0; i<=24; i++) {
            colors32[i] = Color32.Lerp(Color.red, Color.green, vertices[i].z);
            i++;
        }

        //Assign Arrays
        mesh.vertices = vertices;
        mesh.colors32 = colors32;
        mesh.triangles = tri;
    }
   
    // Update is called once per frame
    void Update () {
        Mesh mesh = GetComponent<MeshFilter>().mesh;
        Vector3[] vertices = new Vector3[25];
        for (int i=0; i<=24; i+=2) {
            vertices[i]= new Vector3(4*Mathf.Cos(i*Mathf.PI/12),4*Mathf.Sin(i*Mathf.PI/12),depth);
        }

        vertices[1]= new Vector3(levels.peak1*amp*Mathf.Cos(1*Mathf.PI/12),levels.peak1*amp*Mathf.Sin(1*Mathf.PI/12),6f+depth);
        vertices[3]= new Vector3(levels.peak2*amp*Mathf.Cos(3*Mathf.PI/12),levels.peak2*amp*Mathf.Sin(3*Mathf.PI/12),6f+depth);
        vertices[5]= new Vector3(levels.peak3*amp*Mathf.Cos(5*Mathf.PI/12),levels.peak3*amp*Mathf.Sin(5*Mathf.PI/12),6f+depth);
        vertices[7]= new Vector3(levels.peak4*amp*Mathf.Cos(7*Mathf.PI/12),levels.peak4*amp*Mathf.Sin(7*Mathf.PI/12),6f+depth);
        vertices[9]= new Vector3(levels.peak5*amp*Mathf.Cos(9*Mathf.PI/12),levels.peak5*amp*Mathf.Sin(9*Mathf.PI/12),6f+depth);
        vertices[11]= new Vector3(levels.peak6*amp*Mathf.Cos(11*Mathf.PI/12),levels.peak6*amp*Mathf.Sin(11*Mathf.PI/12),6f+depth);
        vertices[13]= new Vector3(levels.peak7*amp*Mathf.Cos(13*Mathf.PI/12),levels.peak7*amp*Mathf.Sin(13*Mathf.PI/12),6f+depth);
        vertices[15]= new Vector3(levels.peak8*amp*Mathf.Cos(15*Mathf.PI/12),levels.peak8*amp*Mathf.Sin(15*Mathf.PI/12),6f+depth);
        vertices[17]= new Vector3(levels.peak9*amp*Mathf.Cos(17*Mathf.PI/12),levels.peak9*amp*Mathf.Sin(17*Mathf.PI/12),6f+depth);
        vertices[19]= new Vector3(levels.peak10*amp*Mathf.Cos(19*Mathf.PI/12),levels.peak10*amp*Mathf.Sin(19*Mathf.PI/12),6f+depth);
        vertices[21]= new Vector3(levels.peak11*amp*Mathf.Cos(21*Mathf.PI/12),levels.peak11*amp*Mathf.Sin(21*Mathf.PI/12),6f+depth);
        vertices[23]= new Vector3(levels.peak12*amp*Mathf.Cos(23*Mathf.PI/12),levels.peak12*amp*Mathf.Sin(23*Mathf.PI/12),6f+depth);

        Color32[] colors32 = new Color32[25];
        for (int i=0; i<=24; i++) {
            colors32[i] = Color32.Lerp(Color.red, Color.green, vertices[i].z-20f);
            i++;
        }
       
        //Assign Arrays
        mesh.vertices = vertices;
        mesh.colors32 = colors32;

        depth -= .4f;
        if (depth < -18f) {
            depth = 100f;
        }
    }
}
Shader "Custom/Vertex Colors" {
    SubShader {
        BindChannels {
            Bind "Color", color
            Bind "Vertex", vertex
            Bind "TexCoord", texcoord
        }
        Pass {
        }
    }
}

Here is another shot of just one of the rings I’m trying to create. It’s just the inside vertices which aren’t showing color.

UPDATE: Okay I think it isn’t lighting correctly because the vertices on the outside of the circle are shared by triangles. I’m working on changing that now.

UPDATE 2: Alright I recreated the mesh shape without sharing any vertices and it actually got worse. Now some complete edges are showing up black. This seems like a problem with the normals but I’ve tried setting those so I’m not sure where to go. I would prefer to share vertices than have to use this, I’m just trying to make the mesh one solid color. Here is the updated code:

using UnityEngine;
using System.Collections;

public class CreateWaveMesh : MonoBehaviour {

    private int vertCount = 25;
    private int triVert = 0;
    private int triCount = 0;
    private float depth = 6f; //was 100
    public float amp = 10f;

    private AudioVars levels;

    // Initialization
    void Start () {
        MeshFilter mf = GetComponent<MeshFilter>();
        Mesh mesh = new Mesh();
        mf.mesh = mesh;

        levels = GameObject.Find("AudioVarsObject").GetComponent<AudioVars>();
       
        Vector3[] vertices = new Vector3[38];
        for (int i=0; i<=24; i+=2) {
            vertices[i]= new Vector3(4*Mathf.Cos(i*Mathf.PI/12),4*Mathf.Sin(i*Mathf.PI/12),0f+depth);
        }

        for (int i=1; i<24; i+=2) {
            vertices[i]= new Vector3(1.5f*Mathf.Cos(i*Mathf.PI/12),1.5f*Mathf.Sin(i*Mathf.PI/12),6f+depth);
        }

        for (int i=0; i<=24; i+=2) {
            vertices[vertCount]= new Vector3(4*Mathf.Cos(i*Mathf.PI/12),4*Mathf.Sin(i*Mathf.PI/12),0f+depth);
            vertCount++;
        }

        //Triangles
        int[] tri = new int[36];
        tri [0] = 0;
        tri [1] = 1;
        tri [2] = 26;

        tri [3] = 2;
        tri [4] = 3;
        tri [5] = 27;

        tri [6] = 4;
        tri [7] = 5;
        tri [8] = 28;
       
        tri [9] = 6;
        tri [10] = 7;
        tri [11] = 29;

        tri [12] = 8;
        tri [13] = 9;
        tri [14] = 30;
       
        tri [15] = 10;
        tri [16] = 11;
        tri [17] = 31;
       
        tri [18] = 12;
        tri [19] = 13;
        tri [20] = 32;
       
        tri [21] = 14;
        tri [22] = 15;
        tri [23] = 33;
       
        tri [24] = 16;
        tri [25] = 17;
        tri [26] = 34;
       
        tri [27] = 18;
        tri [28] = 19;
        tri [29] = 35;
       
        tri [30] = 20;
        tri [31] = 21;
        tri [32] = 36;
       
        tri [33] = 22;
        tri [34] = 23;
        tri [35] = 0;

        Color32[] colors32 = new Color32[38];
        for (int i=0; i<=37; i++) {
            colors32[i] = Color32.Lerp(Color.red, Color.green, vertices[i].z);
            i++;
        }

        //Assign Arrays
        mesh.vertices = vertices;
        mesh.colors32 = colors32;
        mesh.triangles = tri;
    }
   
    // Update is called once per frame
    void Update () {
        depth -= .4f;
        if (depth < -18f) {
            depth = 100f;
        }
    }
}

2258939--151025--unityTriangles2.png

I believe I figured it out - it was a problem with the loop assigning the colors to the vertices.