- Home /
Why is object with 384 verts and simple shader not getting batched?
Hello!
I have a problem regarding the batching of an object (384 verts) with a simple Vertex Colored Shader and no lights. Each instance of the object adds one drawcall. I'm using the following shader:
Shader "Custom/Vertex Colored" {
Properties {
}
SubShader {
Pass {
ColorMaterial AmbientAndDiffuse
}
}
}
Why is it not getting batched? I'm far below the vertex limit and the shader is only using one pass, right?
Edit: Ok, so I reduced the vertices of the object to 300 (deleted a few faces for testing purposes) and now the instances of the object are getting batched. This means that there have to be 3 shader passes because the vertex limit for dynamic batching is 900 vertices per object, right? Why does a simple vertex color shader cause 3 passes? What can I do about it? It would be difficult for me to only have 300 vertices per object...
It's not the number of shader passes that count - it's the number of vertex attributes that must under 900. Does your mesh have, say UV coordinates or normals?
Hi, batching simply merges some meshes into 1 single mesh. There will be no additional "shader pass".
The 900 limit is on "vertex attribute" = information there is for each vertex = X, Y, Z, U, V, Color, Normal.X,Y,Z etc.... That's why you had to reduce the vertex count to 300 for your objects to be batched (I guess without vertex color, you could have more vertices in each mesh you want to batch)
I don't know if there is a limit on the number of objects that are being batched, it may be dependent on the target platform too.
Hi, batching simply merges some meshes into 1 single mesh. There will be no additional "shader pass".
The 900 limit is on "vertex attribute" = information there is for each vertex = X, Y, Z, U, V, Color, Normal.X,Y,Z etc.... That's why you had to reduce the vertex count to 300 for your objects to be batched (I guess without vertex color, you could have more vertices in each mesh you want to batch)
I don't know if there is a limit on the number of objects that are being batched, it may be dependent on the target platform too.
So in my case which are the attributes that are used? 300 x 3 = 900, so there have to be three attributes currently in use with the posted shader. Unfortunately I don't know how to program shaders so I'm a little lost here ... I'm planning to work myself into this topic though.
Can I strip my models from the attributes I don't need so that I have more "space" for plain vertices?
I created the meshes with Probuilder. I made three public Vector2/3 variables to show the UVs, Normals and Tangents of the mesh.
If you only use the vertex color in the shader, you will not need the tangents or normals, maybe even the UV if you have no texture. While you can choose different mesh/FBX import settings, you might not be able to remove all those attributes with those settings only (I don't think Unity strips unneeded attributes based on the material).
Then, I would suggest to duplicate the imported mesh with a script that will only copy what's needed, i.e. vertices, triangles and colors. This is a little more complicated to do though. You could search examples/tutorials for procedural mesh and mesh merge to get some help.