Search Unity

Lightmap Support in DrawMeshInstancedIndirect using Buffers

Discussion in 'Shaders' started by LukasBigitec, Sep 28, 2020.

  1. LukasBigitec

    LukasBigitec

    Joined:
    Aug 19, 2020
    Posts:
    8
    I'm currently working on a system using DrawMeshInstancedIndirect to render any meshes to improve performance, as there are a LOT of the same object in the scene (they are static).
    I already get get quite a performance boost, but i realized, that every object that get's instance-rendered now has no lightmaps, so the lighting get's calculated in realtime(, also i didn't add any lightmapping code into the shader, so i should have noticed immediately :D).

    Anyway, i can added some lightmapping code to my shader and set the offset and scale of
    unity_LightmapST to the values of the initial Mesh Renderer, so this works fine, every mesh has his needed lightmap uv's, but the problem is, how do i fill unity_Lightmap? The mesh renderer has an index to define this, so i thought maybe add a texture array with every lightmap into the shader and sample the right one with the index inside the material, but this seems to be a bit overkill, i could also set it directly as a texture, but there are some of the same objects that are on a different lightmap, so this would devide the objects that get put into a single batch.

    I though maybe some of you had an idea on how to do it, or a completely different solution.

    Thanks a lot in advance!
    And have a productive day!
    - Lukas
     
  2. imaginalis

    imaginalis

    Joined:
    Feb 20, 2015
    Posts:
    29
    Have you managed to find a solution to this?