Search Unity

Unity 5: Efficiency of lightmap packing?

Discussion in 'Global Illumination' started by essimoon2, Jul 20, 2015.

  1. essimoon2

    essimoon2

    Joined:
    Nov 13, 2013
    Posts:
    193
    Hi all,

    I just looked at some of my baked lightmaps and they seem to be packed pretty inefficiently. I guess with better packing the number of the lightmaps in my example could probably be reduced from 7 to at least 5 or even without reducing size or quality of the individual patches.

    inefficient lightmap packing.PNG

    Now I'm wondering if there's somewhere a setting that lets us pack those patches more efficiently. Or if not, can we expect an update for the packing algorithm in the near future?

    Since Bake Selected is not available anymore and we still require some objects to have differently baked lighting we currently store those objects in an extra scene and transfer the objects (including ligthmaps) into the original scene.
    But this workflow requires some extra manual work for each lightmap that's generated. So, the fewer ligthmaps the better :)
     
  2. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,430
    UV packing has been improved in 5.2 beta 4.
     
    rwetzold and essimoon2 like this.
  3. essimoon2

    essimoon2

    Joined:
    Nov 13, 2013
    Posts:
    193
    Nice! Looking forward to it :D
     
  4. Kuba

    Kuba

    Unity Technologies

    Joined:
    Jan 13, 2009
    Posts:
    404
    You can expect the update to the packing algorithm in 5.2b4 (released last Friday). :)

    One issue that was fixed that has to do with taking UV bounds into account properly and is described in more detail here:
    http://issuetracker.unity3d.com/iss...irection-uv-maps-overlapping-causing-blotches

    The other thing that will improve your case is that the size of the last lightmap is now reduced to pack the instances more tightly and not waste space. So in your case, where you lightmap some objects in a separate scene and, possibly, they occupy only a part of one lightmap -- now this lightmap will be made as small as possible (while still being square though).
     
  5. Millson

    Millson

    Joined:
    Sep 24, 2015
    Posts:
    1
    Hi, I have still not been able to get the UV packing to improve with Unity 5.2 ( Installed in mid Sept). Also the Shading on my light map UV do not match in tone giving odd artifacts in the light map. Why does the Unity light map UV give such inconsistent seams? Thanks.
    upload_2015-10-5_14-22-27.png
     
  6. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    6,274
    Also, can we please PLEASE (did I say please?) switch to the tighter packing that we had back in the 3.x days? The bounding box type packing wastes SO much space, especially when you generate your lightmap UVs (which has a tendency to put the uvs in an L shape)

    I believe it was changed to work better with bake selected, but bake selected is no more, so.... why are we wasting so much lightmap space?
     
  7. Pixeldamage

    Pixeldamage

    Joined:
    Sep 6, 2010
    Posts:
    52
    This thread is a couple of months old but it seems that either the latest algorithm still needs work or I'm missing something (I'm on 5.2.3f1). My atlases have 70% wasted space and opening them in PS shows there really is nothing in those spaces.

    lightmap atlas space.png
     
    Last edited: Dec 14, 2015
  8. psycocrusher

    psycocrusher

    Joined:
    Jul 24, 2011
    Posts:
    71
    I am also experiencing this using Untiy 5.3, i am getting 13 lightmaps and 3 of them are 90% empty and some others 75% empty.

    Am i missing something?

    Lightmaps.png
     
  9. KDurzy

    KDurzy

    Joined:
    Feb 2, 2015
    Posts:
    24
    Something similar had been driving me crazy for a while in the last few months too. I had been getting a whole scene packed into one map and then ONE object getting its own one whole 1024 even though it was about 4x4 pixles, the rest 99.9% of the map black.
    It turns out the Layers you assign objects to matter in the new packing process. Correct me if I am wrong, please, but for me, making all of the objects I needed packed together be on the same layer fixed that problem.
     
  10. Wiliz

    Wiliz

    Joined:
    Feb 18, 2014
    Posts:
    20
  11. psycocrusher

    psycocrusher

    Joined:
    Jul 24, 2011
    Posts:
    71
    @KDurzy I tried your solution but it didn't work fro me.
     
  12. ArteyS

    ArteyS

    Joined:
    Dec 15, 2014
    Posts:
    16
    Alternatively if the unity Devs could tell us exactly how they want our lightmaps, we could set them up ourselves and set preserve Uvs coming from the art package? Can you give us an intermediate resolution that describes how you need them to look in order to pack them efficiently?
     
  13. brainz12345

    brainz12345

    Joined:
    Dec 10, 2012
    Posts:
    12
    This is still a problem. If I try to have all my scene in one image I get either of these two results, there's no way to utilized completely the whole area of the lightmaps.
    Is there no way to manually fix this? I'm using 5.3.4.
     

    Attached Files:

  14. Pixeldamage

    Pixeldamage

    Joined:
    Sep 6, 2010
    Posts:
    52
    Yeah Unity really needs an improved texture packing system. Still really poor packing in 5.3.4. Might be worth noting that it's sometimes possible to get better packing by switching to a different texture size (eg 2048 vs 1024). It's pot luck but might help someone else out
     
  15. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    6,274
    Packing is still pretty poor in 5.4b22

    packing.jpg
     
    GoGoGadget likes this.
  16. Firedan1176

    Firedan1176

    Joined:
    Dec 7, 2013
    Posts:
    48
    This is still a problem in 5.4, regardless of the supposedly "fix" via the bug report listed above.
     
  17. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    6,274
    BTW, I discovered that changing things in the lightmap parameters (like the "is transparent" checkbox), forces the objects that have those parameters to be on a separate lightmap.

    I don't have a complete list yet. It would be nice if these sort of things were documented.
     
  18. Adam-Bailey

    Adam-Bailey

    Joined:
    Feb 17, 2015
    Posts:
    230
    I hate to bring up direct engine to engine comparisons (since different engines usually have things going on under the hood totally differently) but I wish Unity 5 had support for user defined lightmap UV's like UE4 does. I was reading outdated documentation (not realising that things had changed since it didn't have a Unity version number on) and was under the impression I could lay out the lightmap UV's manually for a scene, so spent a day doing that in Maya, giving high resolution to areas the player would get close to while compacting areas the player wouldn't. Then imported it into Unity and discover that the UV's are rearranged anyway.
     
  19. Pixeldamage

    Pixeldamage

    Joined:
    Sep 6, 2010
    Posts:
    52
    Hey Adam. Yeah that is a nice feature in UE4. Having used both engines though I'd say there are benefits to both systems (I like being able to see an entire atlas and edit it in PS). Regarding your particular issue though - you can still use your per object UV2 layouts as well as set custom texel resolutions in Unity. Whereas in UE4 you'd set per object texture sizes; Unity lets you specify a texel ratio. It's a little more trial & error (though you can enable resolution grids in the scene view for better visualisation).

    If you want to completely control how every piece is arranged relative to one another (probably not necessary but it's an option) then you can export the entire scene from Maya (I've done the same from Max).
     
  20. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,391
    i confirm this, this one totally confused why i have another small atlas in the lightmap list.
    Turned out isTransparent object are baked in other atlas
     
  21. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    6,274
    So even after figuring out a variety of undocumented reasons for why lightmapping might generate a new atlas, the packing algorithm is still pretty poor.

    -It's still bounding box based instead of texel tight, which was changed because of bake selected back in Unity 4, which doesnt exist any more, so I don't know why it's still being done this way.

    -It's unable to rotate the UVs (I'm guessing it has something to do with directionality, but it doesn't even on non-directional mode, sooo...)

    -It's pretty poor in general. I don't know how it decides to place UVs, but it seems like it takes the smaller UVs first, place them clumsily in the bottom left corner, creating gaps, and then tries to fit the bigger ones. And it's a little too eager to create a new atlas. If something doesn't fit in the place it decided it wants to put, it creates a new atlas, even if there is space elsewhere.

    Overall, it's very poor. I'm trying to fit everything in one map and I often find myself massaging values by +-0.1 or editing the models and rotating the UVs manually, in hopes the packing algorithm decides to produce half decent results. Which again is very fragile, because the most minute change might again make it create a new atlas.
     
  22. unisip

    unisip

    Joined:
    Sep 15, 2010
    Posts:
    273
    It's 2020, and Unity's lightmap packing still looks like a joke.

    I've heard some explanations as to why objects end up in separate lightmaps while each of those lightmaps has around 70 to 80% of free space (some stuff related to LOD levels being assigned to separate lightmaps god knows why, specific lightmap parameter assets ending up rooting object ot separated lightmaps again).

    I understand Unity has a lot of stuff to put up with, and overall I think it's a fantastic tool ,but sometimes I just can't understand how some stuff like UV packing which has many efficient solutions documented in academia and is properly implemented in a lot of other software remains so poor in Unity... Been doing programming work for twenty years, so I know that in complex software there are often reasons why things don't get fixed quickly, but in that particular case, well... (ok, I'm done with the whining, I guess I just had to get it off my chest ;-)
     
  23. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    6,274
    In fairness it’s better than in 2016 and some of the points I mentioned specifically are addressed.

    It still isn’t very good though, yeah.
     
unityunity