I’m creating a mesh painting system that is supposed to allow you to paint different textures into each instance of an object. So I can have a single rock prefab but apply different amounts moss or snow to different instances of it around the scene, by painting vertex colors (and UVs) and applying them with additional vertex streams.
But then when searching about additional vertex streams, I come across this, which right away mentions them as potential causes for breaking batches. So I go in the static batching docs and I read this:
- Meshes you want to batch together use the same vertex attributes. For example Unity can batch meshes that use vertex position, vertex normal, and one UV with one another, but not with meshes that use vertex position, vertex normal, UV0, UV1, and vertex tangent.
I have no idea what they meant to say, but it sounds bad. So I search online and see a few posts saying that additional vertex streams and altering vertex colors will break batching. Ok. Then I found a tutorial that encourages you to save draw calls by batching different objects with vertex streams! Ok, this is getting weird.
Now, let’s just think for a second. Static batching can batch different objects that use the same material - they can have any shape, UV layout, or whatever else. So why would additional vertex streams create any issues? How does VFX Graph even batch then, since we can change vertex color? Hell, shuriken literally works by feeding dynamic values into the UV channels as vertex streams, where the system feeds values to the meshes UVs so the shader can have animations.
But then I can’t have two sets of the same mesh with the same material, but with different vertex colors? That doesn’t sound right. So I quickly set up a test scene in unity, painting custom vertex colors with polybrush and voilà! Static batching is working just fine.
I’d really love if someone could clear this up for me. Are they actually being batched correctly, is this all ok? Is the entire internet wrong? Or is this all an illusion and the batching will break as soon as I make a build?
Thanks a lot in advance.
Edit: Just realized there’s a little problem with the way I tested the batching. I’m actually getting a problem with Polybrush Mesh’s additional vertex stream setting. It’s throwing me a little error and reverting to the default behaviour, which is to overwrite the mesh. Apparently forcefully overwriting the mesh data works, then? But I’ll also try to test AVS in some other way.
Edit2: Wrote a little script to manually set AVS with custom vert color, and yes, batching is still working really well!