Best practice to change vertex color on a large amount of quads?

Hi there!
For a project of mine I need to change the vertex colors of a large amount of quad meshes (900+) individually. What I want to achieve is that every quad has it’s own time offset saved in myAlphaOffset that determines when the alpha change for that quad begins (since I subtract that offset from the current progress in my lerp). When ‘progress’ has reached 1f, every quad, regardless of its offset should end up with a alpha of 0.

My code atm is something like this:

   public override IEnumerator ChangeQuadAlphas ()
    	{
    	
    		Color transColor = Color.white;
    		
    		while(changingAlpha){
    			
    			for(int r=0;r<rows;r++){
    				for(int c=0;c<cols;c++){			
    					transColor.a = Mathf.Lerp(0f,1f,(progress-myAlphaOffset[c+r*cols])/duration);
    					
    					quads[c+r*cols].mesh.colors = new Color[]{
    						transColor,
    						transColor,
    						transColor,
    						transColor
    				 	};
    				}
    			}
    			yield return null;
    		}
    	
    		yield return null;
    	}

This code so far works fine but strains the cpu very much.
I tried easing the load on the cpu by yielding after each row of the loop but then the alpha changes occur spread over multiple frames. This way I would end up with a lot of half visible quads when progress reaches 1f since there weren’t enough frames for changing.

Now I don’t know how to optimise that further. Would loop unrolling have much of an impact here? Would it be better to give each quadobject a lerptarget so that the mesh alpha would be changed in the quadobject’s Update()? This is what I mean:

//Script attached to each quad
...
Color myColor = Color.white;
float myOffset = someValue;

void Update(){
  myColor.a = Mathf.Lerp(0f, 1f, (progress-myOffset)/duration;
  this.mesh.colors = new Color[]{
        myColor,
        myColor,
        myColor,
        myColor

  }
}

I would guess that the overhead of 900+ Update()-functions might outweigh the benefits.

Maybe there is another approach that I might be unaware of so - what is the best (fastest) way of updating the mesh colors of a large amount of meshes individually?

Thanks in advance,

delstrega

There is no fast way to update the colors for a ton of meshes. Combine the meshes. The rest of the stuff you’re mentioning, like loop unrolling, is not the problem at all.