Search Unity

Discussion single static batch using TextureArrays vs multiple batches using several Single Texture Materials

Discussion in 'Shaders' started by Manuel_H, Mar 15, 2023.

  1. Manuel_H

    Manuel_H

    Joined:
    Aug 3, 2017
    Posts:
    16
    While planning a static batching solution for a new project, it occured to me that I should be able to combine all textures of equal sizes of mesh renderers as well as their lightmaps into two texture arrays. The texture indices could then be supplied to the shader using the vertex data of the static combined mesh, e.g. by using uv1.zw, where unity uses .xy for lightmap uvs anyway. This should theoretically allow for drawing the whole lightmapped scene in a single batch, as long as all textures have the same dimensions and all renderers use the same shading (vertex limit for static meshes shouldn't be an issue).

    So now I'm wondering why static batching doesn't already work this way, especially for lightmapping. Instead of using a texture array for lightmaps, unity seemingly creates material instances for all renderers using a different lightmap, which, of course, breaks batching. Is there something I'm missing? Was the potential performance gain not worth it to implement it this way, or is there maybe even a performance loss due to using texture arrays instead of 2d textures? If there's someone who already tried this approach or at least thought about it, I'd be happy to hear your thoughts before I implement my own solution :)