# Optimising by shared material / reducing draw calls

I’m trying to find the optimal design path for my project. Currently it is chugging on my iPad 1.

I’ve got 12 identical meshes arranged in a circle, say at the 12 hour-positions on a clock face.

Each must be a different colour.

Also there must be a glow parameter between 0 (not glowing) and 1 (full glow). However, most likely only one or two will be glowing at any moment so I could render the inert items first.

I will be using my own custom shader.

Currently I’m making 12 clones from an original, giving each clone a different material.color and material.glow. So this is creating 12 materials, and I think 12 meshes, resulting in 12 draw calls.

I’m looking at restructuring to get it down to one draw call.

If I do:

``````void Update( )
{
for( int i=0; i < 12; i++ )
{
MaterialPropertyBlock materialProperty = new MaterialPropertyBlock( );

materialProperty.Clear( );

Graphics.DrawMesh( theMesh, pos[ i ], Quaternion.identity, theMaterial, 0, null, 0, materialProperty );
}
}
``````

… is this actually going to give any optimisation?

can I use a single mesh? Or do I need to create 12 identical meshes?

and it looks like this is going to result in 12 draw calls… is this correct?

I can’t see that this is an improvement over what I have at the moment.

The only possible benefit I can see is that maybe it is loading one shader into the GPU and then performing 12 draws using it, whereas with my first method maybe that isn’t guaranteed (although I would be surprised if it wasn’t doing that anyway)

I’m wondering whether there is another way; if I rewrite my shader to take per-vertex-COLOR, then I could use 12 meshes, and for each, do:

``````        Mesh mesh = ...
int N = mesh.vertices.Length;
Color [ ] C = new Color[ N ];
for( int j=0; j < N; j++ )
C[ j ] = ...; // color for this mesh
mesh.colors = colors;
``````

Maybe I could use the Alpha component of the color to pass the glow_01 float into the shader…?

But is this still going to require 12 draw-calls?

Maybe I should be combining my 12 objects into a single mesh…?

Once the materials differ, it will result in a new draw call. You can’t have one large mesh with separate colors and glows for parts of the mesh. I think the only way to reduce that down to one draw call would be to do it in the shader, but it would be pretty tricky I would imagine.

Do they need to all have individual colors and glows? If you have say 4 different colors and glows, i.e. 4 materials, then spread that across the 12 objects and combine their meshes, it will result in four draw calls. Note that when you combine the meshes, they are one solid mesh, so they cannot be separately animated.

Trying to figure out how I can get the drawing of turning wheels on a car down to 2 draw calls per vehicle, instead of the current 5! Similar problem