Search Unity

Draw call not batching (dynamic) because of different materials when in a different location??

Discussion in 'General Graphics' started by andrew_ES, Sep 25, 2020.

  1. andrew_ES

    andrew_ES

    Joined:
    Apr 19, 2016
    Posts:
    20
    I was hoping someone might have a clue as to why some of my draw calls are not batching together. Here is the scenario:

    I have two materials that are identical except for the texture they use. Both use the Unlit/Transparent shader. The only real difference is that one texture is 833x118 and the other is 858x122 (not in a texture atlas). Let's call these material A and B.

    In an empty scene, I'm then creating new game objects that are 3D->Quad's. I remove the mesh collider and then change the material to either have material A or B (and they are not instanced). All objects have the same scale and are just placed so they appear in the camera without overlapping. There is no lights in the scene other than the directional light.

    If all objects in view have just material A or just B, they all batch together in one draw call. If I have some with A and some with B, then there are more that two draw calls and, depending on the location of the object, the amount of draw calls vary.

    EDIT: I also tried marking the objects as static and had the same results.

    Any ideas? Is the batching have trouble distinguishing between materials A and B?

    BatchingIssue.jpg
     
    Last edited: Sep 25, 2020
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,348
    The reason for why they aren't batched together is because they have different materials, as the frame debugger shows.

    If they have different textures, they’re different materials. Even two materials with identical properties won’t be batched, because they're different materials.

    When they say different materials they really do mean different materials. It'll also not batch of you use the same material, then modify the properties of one object with an animation or script, because it'll again not be the same material once you do. Even then there's no guarantee of batching if you're using dynamic lights, shadows, or light probes, as those can all break batching, even on unlit objects.
     
    Last edited: Sep 25, 2020
  3. andrew_ES

    andrew_ES

    Joined:
    Apr 19, 2016
    Posts:
    20
    @bgolus Thanks for the response. Yes you were correct. We fixed the issue by moving all of the textures into a texture atlas.