Hi,
I'm trying to optimize my drawcalls on an iPhone project, and it's my understanding that changing the material color generates a new material instance and hence another drawcall.
I read in the forums that using a VertexLit shader and modifying vertex colors will let you change the color of an object and still keep it dynamically batched.
I don't know much about shaders, but in my code I am modifying the "material.color" property, thinking thats how you change the Vertex colors. It's still creating a new material though, so I must be doing something wrong.
So given two objects that share the same material, object A and object B. How can I make: A = red B = blue and still keep batching?
here is a code snippet of how i'm currently doing it
function Start()
{
thisMaterial = renderer.material;
origColor = thisMaterial.color;
fadeToColor = origColor;
if (unitType > 0)
fadeToColor.b = 1;
else if (unitType < 0)
fadeToColor.r = 1;
}
function Update()
{
if (unitType != 0)
thisMaterial.color = Color.Lerp(origColor, fadeToColor, Mathf.PingPong(Time.time, 1));
}