What's the best way to optimize draw calls with 100,000+ bjects?

I’m working on a data visualization program with Unity that requires the creation of thousands of objects with their own unique size and color. Each object is a primitive shape such as a cube and is also static.

Right now I’m instantiating a prefab for each object necessary. However, because each object has its own color, these objects will not batch and will render slowly.

Any suggestions for a way to get these objects to batch or perhaps a different approach that doesn’t require many game objects?

You could create a texture atlas that contains a pixel of all the colors you are using. If you have millions of colors to choose from, you might have to create several.

Because you can then assign an atlas to one material, and only different materials cause draw calls, you will effectively cut down the amount of draw calls from the amount of objects to the amount of texture atlases you are using.

For each object, you will just have to choose the right pixel from the atlas and use that as the texture for the object.

The hardest part is creating your atlases so that you can programmatically choose the correct pixel. If you manage to use only one atlas, this shouldn’t be a problem.