Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Unity 2020 LTS & Unity 2021.1 have been released.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

"Lightmap Index" and Draw-Call Batching

Discussion in 'General Graphics' started by Peter77, Jun 3, 2019.

  1. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    5,579
    Looking at the Frame Debugger shows a lot of draw-calls are generated because of different lightmapIndex values in our game.

    I assumed objects with the same material, which are close to each other, would share the same lightmap(index) if there is enough space on the texture.

    However, it seems Unity does not try to assign the same lightmap to objects in close proximity, which would reduce draw-calls, because of less render state changes when rendering what's in the view.

    This is basic stuff, but I'm new to lightmaps and I must be missing something here. What can I do to achieve that Unity assigns the same lightmap to objects in close proximity?

    upload_2019-6-3_9-17-6.png

    upload_2019-6-3_9-17-56.png
     
  2. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    7,522
    Peter77 likes this.
  3. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    5,579
    Many thanks for the quick answer!
     
    AcidArrow likes this.
  4. rasmusn

    rasmusn

    Unity Technologies

    Joined:
    Nov 23, 2017
    Posts:
    86
    Hi Peter,

    Currently Unity does not handle this for you automatically. However, you can do this manually by assigning equal "Baked Tags" to objects that you want to group into same lightmaps.

    See "Baked Tag" in the docs for more info.
     

    Attached Files:

    Peter77 and Adam-Bailey like this.
  5. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    5,579
    Hi Rasmusn,

    many thanks for your answer. I was able to reduce draw-calls by 38% by using the "Baked Tag".

    Below I describe how I achieved this and would like to get some feedback on whether this is the approach you recommend, because it felt kinda odd in the way I used it.

    My initial assumption was that "Baked Tag" would be part of a Renderer. That would allow me just iterate over all renderers in a scene and assign a baked tag. However, there is no Baked Tag in a Renderer, but there is the LightmapParameters object.

    In order to assign a different Baked Tag to individual objects, I created a few hundred LightmapParameters assets in the project and assigned an unique bake tag to each of those assets.

    upload_2019-6-14_9-13-57.png

    Then I wrote an editor tool that spatially groups renderers ("world" is represented by several square cells/sectors) and assigns one of those LightmapParameters asset depending on what cell in the world-grid the renderer occupies. This makes sure all objects in a world-cell use the same baked tag.

    Before
    upload_2019-6-14_9-40-22.png

    After
    upload_2019-6-14_9-40-16.png

    A draw-call reduction of about 38%. That is great!

    However, the workflow of having those hundreds of LightmapParameters assets in the project feels like that's not the way you want your users to work with that. Specifically because it seems there is no way to only modify the baked tag. What if I want to keep all settings the same except for the baked tag?

    How would you assign the Baked Tag automatically to renderers without having to create hundreds of LightmapParameters?

    Thanks for your help!
     
    Last edited: Jun 14, 2019
    hippocoder and JamesArndt like this.
  6. rasmusn

    rasmusn

    Unity Technologies

    Joined:
    Nov 23, 2017
    Posts:
    86
    Thank you for that detailed description and nice-looking screenshots. I think what you are doing is similar to my approach. Your analysis is spot on. The problem you point out is exactly what motivates us to do automatic spatially coherent lightmaps. I am afraid there is no better way at the moment. AFAIK bake tags were not originally introduced to solve the particular problem of lightmap batching, it just happens that you can use them like this. I hope this somewhat explains the suboptimal design. Since we have many other priorities I cannot promise you when/if a solution will be released. But we are aware and this issue is definitely something that we want to solve.
     
    Peter77, hippocoder and JamesArndt like this.
  7. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,403
    Any ETA when PLM will support automatic lightmap tag grouping?
     
    leandrovtd and Peter77 like this.
  8. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    5,579
    Any progress on this?
     
  9. rasmusn

    rasmusn

    Unity Technologies

    Joined:
    Nov 23, 2017
    Posts:
    86
    No, unfortunately not. It is still on our radar and something that we want to do eventually, but I do not know currently whether and when it will happen.
     
unityunity