Search Unity

Packing continues to be horrible, please fix

Discussion in 'Global Illumination' started by AcidArrow, Jan 25, 2017.

  1. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,735
    Packing for lightmaps was great in Unity 3. It got a bit worse in Unity 4 (it packed by bounding box instead of tighter packing, but still good). It is horrible in Unity 5 (it fails to pack very simple cases).

    I am trying to fit everything in one 1k map.

    So I have this lightmap.

    lm1.png

    Plenty of wasted space I think. I could try bumping up the resolution a bit.

    So I take it from 42 to 44 and...

    lm2.png

    Did you notice some islands missing? They are in a second lightmap now. Even though the first one still has all that free space. And they definitely fit inside the first.

    I mean...

    lm3.png

    I haven't seen any other Unity feature regress this much. And I'm including baking with Enlighten vs baking with Beast in that. It has gotten THAT bad.

    I mean, the logical next step for Unity 2017 is to just not do any packing, and create separate maps for each mesh.

    Please... Please fix it.
     
  2. mh114

    mh114

    Joined:
    Nov 17, 2013
    Posts:
    295
    I've noticed this as well, very annoying. Do you happen to know if the progressive lightmapper has better packing?
     
  3. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,735
    I don't know, but I'm also not sure if it's related. Packing is a different process and I don't think it matters which lightmapper you are using afterwards.

    I'm hoping they plan on doing improvements though.
     
  4. mh114

    mh114

    Joined:
    Nov 17, 2013
    Posts:
    295
    That's what I fear, I was hoping they'd do a better packing method for the new lightmapper but likely isn't the case. Have to wait and see. At least iterating trying to find the "bad-but-not-the-worst" packing will be faster with the new lightmapper..
     
  5. iamthwee

    iamthwee

    Joined:
    Nov 27, 2015
    Posts:
    2,149
    Offtopic the progressive lightmapper won't match the full GI glory of enlighten anyway.
     
  6. mh114

    mh114

    Joined:
    Nov 17, 2013
    Posts:
    295
    I am hoping it won't match Enlighten in terms of being pre-alpha quality, slow and fragile mess when baking lighting. I'm hoping it's more like Beast in terms of output & robustness.
     
  7. mh114

    mh114

    Joined:
    Nov 17, 2013
    Posts:
    295
    Now it's good time to check if the packing is any better; the new lightmapper is in 5.6 beta 6!
     
  8. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,735
    I did check very quickly.

    I believe it's a bit... worse as far as packing goes.
     
  9. mh114

    mh114

    Joined:
    Nov 17, 2013
    Posts:
    295
    At least it was nice knowing the resulting lightmap sizes very quickly when changing things. Helps quickly adjusting if things are on the verge of splitting into too many lightmaps.
     
  10. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,735
    I still can't get the over that the packing in Unity 3 was so much better.

    Also can't get over the fact that originally they were going to have a mode where you would pick how many light maps and what resolutions you want, and the packer would try to maximize the resolution without creating more lms. But they scrapped it because apparently "people don't want that".

    *sigh*

    Sometimes Unity makes me really sad.
     
  11. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,735
    Can we at the very least get some info on this?

    It seems to me, that older versions of Unity packed the UVs from bigger to smaller. Which makes sense. You fit the biggest first, so you can then potentially place the smaller ones in weird gaps so you can fill space more efficiently.

    Unity 5 and 2017 don't do that. I have no idea why. I don't know if there's any logic, it looks random. But what happens is since it fills the space somewhat hap-hazardly with small and medium UVs and then there isn't enough continuous free space to fit the bigger ones.

    Look at this:

    packing.jpg

    The top one is Unity 4, the bottom one is Unity 2017. (it's not 100% the same, since I have tweaked the UVs since then a bit, but it's the same scene).

    You will firstly notice that Unity 4 has much more efficient use of the space.

    And that's because of it fits the largest islands first.

    I can't increase the resolution at all in the Unity 2017 version since this island:

    chunk.jpg

    Gets packed last. Not sure why. And since it's packed last and it's a big square area, it really can't fit anywhere if I increase the resolution.

    Placing the big UVs first and fitting everything else around them makes sense and it works. Placing smaller ones first and then trying to fit the big ones in the remaining fragmented space, does not.

    I don't know why it was changed and I don't know why they won't change it back. If there is a logic to this madness, please let me know.
     
  12. mh114

    mh114

    Joined:
    Nov 17, 2013
    Posts:
    295
    I too would be very interested in hearing more info about the packing. @Jesper-Mortensen might know about it with progressive lightmapper..?

    I haven't used Unity 3, but with 4 and above lightmap workflow of specifying resolution first has always felt backwards to me. I would like to set a limit on how many lightmaps to use and what their maximum resolution should be -> lightmapper / packing would figure out the correct resolution to give me that (or at least give something that is close to what is requested).

    Now, and this is especially problematic with wasteful packing there is currently, you have to guess a resolution and tweak it down (+ adjusting lightmap scale on objects) until you get close to what you want. Granted, it's faster to iterate with progressive LM and I'm grateful for that, but still the other way would make a lot more sense to me (mobile development). Thoughts?
     
    AcidArrow likes this.
  13. mh114

    mh114

    Joined:
    Nov 17, 2013
    Posts:
    295
    Seriously, nobody considers wasteful packing a problem? Pfft, you PC devs! (;))
     
    Shorely, Martin_H and JamesArndt like this.
  14. JamesArndt

    JamesArndt

    Joined:
    Dec 1, 2009
    Posts:
    2,932
    You're not alone, Ive noticed this as well and I dont see better packing using the Progressive Lightmapper. I end up experimenting for a long time with scale-in-lightmap values for tons of meshes and then seeing odd and random overflows into new lightmaps (with the same big empty spaces in existing maps). The packing is so bad/inefficient I've resorted to packing my own secondary UV set in 3ds Max.
     
    mh114 likes this.
  15. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,735
    I'm not sure if it's a bug.

    The way it's picking the order to pack the islands, is based on the transforms in the scene. So I'm guessing it's deliberate, but I don't know why.

    In any case, I'll do a bug report now.
     
    mh114, JamesArndt and Peter77 like this.
  16. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,735
    Case 955445

    I haven't received a reply yet on whether or not they consider this a bug. I'll update when they do.
     
    mh114, Adam-Bailey and Peter77 like this.
  17. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,735
    Still nothing, but I made this image to explain the issue for the bug report and I thought I'd post it here as well for prosperity.

    explanation2.jpg
     
  18. kemalakay

    kemalakay

    Unity Technologies

    Joined:
    Jul 12, 2016
    Posts:
    224
    Hi everyone,

    Just wanted to tell that we're aware of packing issues and that's why the roadmap for Progressive Lightmapper is being re-arranged and one of our developers will start to work on packing improvements soon.

    Main reason why it was delayed so far is because other tasks took priority. Primary goal for Progressive Lightmapper is to have feature parity with Enlighten and it is getting there (memory work is currently being addressed, also static scene dressing for lightmapped objects and importance sampling for emissive materials will be added).

    Thank you all for your understanding and raising your concerns. We hear your input and it is really valuable to us, we're simply trying to arrange the schedule based on priorities.

    Thanks!
     
  19. OwlBoy-

    OwlBoy-

    Joined:
    Dec 11, 2015
    Posts:
    24
    Any news on this packing issue?
     
    Last edited: Oct 16, 2018
  20. JamesArndt

    JamesArndt

    Joined:
    Dec 1, 2009
    Posts:
    2,932
    Wow, your graphic really makes the problem clear. So any word on the fixes yet? Looks like it's been exactly a year since they started tackling this issue.
     
    Shorely likes this.
  21. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,735
    This was actually fixed some time in the 2018 cycle (I think). It wasn't mentioned in the release notes for some reason. At least for the progressive lightmapper, not sure about enlighten.

    I am talking specifically about packing the larger islands first.

    There are still things that are worse than old Unity versions. For example, packing is still bounding box based, while older versions of Unity did a much tighter fit, but they took that out to accommodate for bake selected. But now we haven't had bake selected for years and packing is still bounding box based.
     
    OwlBoy- and mh114 like this.
  22. kwcae

    kwcae

    Joined:
    May 26, 2017
    Posts:
    34
    We're using 2018.2 and the packing algo is still horrible. On a 4K map, there's 2K of used space and the remaining space consists of two flat colors that don't appear mapped to any of the 4 meshes in our scene. (All 4 meshes using Unity's automatic unwrap setting)

    @kemalakay Any updates on the progressive packer.?
     
    Shorely likes this.
  23. JamesArndt

    JamesArndt

    Joined:
    Dec 1, 2009
    Posts:
    2,932
    Any update on packing improvements for the Automatic Lightmap UVs? I keep checking release notes on each successive release of Unity since 2017 and I don't see any notes on it, so not sure what's been worked on or improved? I still have the issue of Unity not respecting my custom-authored lightmap UVs from 3ds Max. Unity still performs it's own rotation to my UV shells, moving them onto different atlases, etc. I've set proper packing tags for geometry I want on the same atlas, but it doesn't respect these because of very poor packing of atlases...so it shifts UV shells onto atlases with massive amounts of empty texture space.
     
  24. rasmusn

    rasmusn

    Unity Technologies

    Joined:
    Nov 23, 2017
    Posts:
    103
    Thanks for all the feedback guys! As clear from the above, the packing algorithm used in the progressive lightmapper has a lot of issues. It needs work and over the last year this work has been postponed due to other problems that for various reasons have been deemed more important.

    Unity 2019.1 will have a minor new packing feature and that is "Limit Lightmap Count", the ability to set a max number of lightmaps to be used for a certain group of objects. This feature is currently in the polishing phase, and once it is done, I will focus on addressing the issues mentioned in this thread.

    I cannot guarantee anything, but on my radar right now is:
    • Improve texture utilization (i.e. avoiding space waste).
    • Avoid texel bleeding/overlap.
    • An option to pass-through UVs unaltered (as requested by @JamesArndt ).
    • Spatially coherent packing as shown here.
    Do note that none of these changes are trivial and it will take some time to get right. Thanks!
     
    Lars-Steenhoff, mh114 and JamesArndt like this.
  25. JamesArndt

    JamesArndt

    Joined:
    Dec 1, 2009
    Posts:
    2,932
    Thank you so much for the consideration of this. The Bakery Lightmapper plugin does something similar with its "Lightmap Groups" functionality. You can assign a Lightmap Group to a set of geometry that may or may not be combined meshes. Once you've assigned this script you can drop-down select to use "Original UVs" and it will bake and preserve my 3d package authored UVs. I would highly recommend looking at this plugin as it produces lightmap bakes that are cleaner than anything I've seen come out of Unity in years.
     
    rasmusn and fguinier like this.
  26. Goatogrammetry

    Goatogrammetry

    Joined:
    Apr 27, 2017
    Posts:
    197
    I say they (Unity) should just buy Bakery. Over night the problems are all solved. I guess I'm going to have to buy Bakery next week. My experience with lighting in Unity lately has been frustrating-- I put a few models I've made in and bake lighting and whole UV islands are getting the wrong colors with hard seams. It has nothing to do with bad mapping on my part, since the artifact remains even if Unity does the UVs. Looking at the islands, they have plenty of space around them. I noticed the UV packing. I thought-- Jeez, if they're going to waste the space, move the islands farther apart or something to help avoid artifacts. Plus, I cant get global illumination to change no matter what buttons I push or sliders I drag. The HDRI Sky script seems to be missing from 2018.3 HDRP... Or do I have to download Unity's HDRI sky pack for half a gig to get the script? The spotlight in the demo construction scene seems to have the light map pixels drawn backwards or else some weird choppy gradient artifact is chunking up the shading-- Oh wait. I see it on the ground from the directional light too. so... Yeah. I'm gunna buy Bakery for 55 bucks and hope it works for me. I'm just an artist that wants to try making stuff for the Unity store, and I want my promo pics to look good. But dang. I feel like I have to be a Technical Artist who can code and knows engines and video cards in depth just to set up a nice looking test scene :(
     
    salex1, Shorely and JamesArndt like this.
  27. JamesArndt

    JamesArndt

    Joined:
    Dec 1, 2009
    Posts:
    2,932
    I would highly recommend this plugin. I've used to great success to lightmap large racetracks on a project of mine. It's for mobile so I don't need a lot of the fancy realtime GI stuff. For Beast-style lightmapping that looks even better than Beast this is the plugin that does it!
     
  28. Devil_Inside

    Devil_Inside

    Joined:
    Nov 19, 2012
    Posts:
    1,119
    Packing is still ridiculous in 2020, 3 years later.
    Here's a lightmap for a couple barrels and a stake wall:

    Unity clearly creates a uv layout for each fbx on import and just moves it around inside the final lightmap.
    I've added another barrel to the scene, and since you "clearly can't fit" another "barrel layout" inside this lightmap, it generated a separate one for just that one barrel.

    I mean, isn't there a way to actually pack all islands more tightly, independent on the fbx they come from?
     
    Last edited: Apr 27, 2020
    angiemon, mh114 and JamesArndt like this.
  29. JamesArndt

    JamesArndt

    Joined:
    Dec 1, 2009
    Posts:
    2,932
    Ha ha yeah that is a bit ridiculous, but it's a symptom of a larger problem. The system they have in place for auto generating UVs for both real-time lighting and for baked lighting is like a platform held up by a bunch of rickety poles. Each of these tiny, interdependent systems that affect one another in ways you wouldn't expect. It's simply not intuitive to understand or work with these inter-dependencies. So it becomes a time sink, money wasted spending all of this unecessary time trying to reverse engineer these settings. The UVs and lightmaps do not bake well out of the box or rather by default. Unity 5 has been out for around 5 or 6 years I do believe and I would have thought they would have dramatically improved the packing algorithms by now.
     
    mh114 and OwlBoy- like this.
  30. Devil_Inside

    Devil_Inside

    Joined:
    Nov 19, 2012
    Posts:
    1,119
    This is so frustrating. I work with my brother, who's doing the art for the game. We constantly discuss various aspects of the development and decide whether he should do something(level design, lightmaps, etc) using Unity tools or 3rd party tools. Every time he says he will do it faster in 3rd party app, and every time I convince him that he should use Unity, because "Hey, in all the videos Unity features look so well made, and EVERYONE uses them!". We start using the Unity tool and it turns out that basic functionality is half-baked, missing or absolutely not usable for production. How can ANYONE use these tools for production?

    Like this example right here... Yeah, you can bake a lightmap and the scene would look cool in a Unite presentation. But then you check the actual lightmap files, and realize that there are 5 half-empty textures, eating your entire space budget for a scene.

    When will this be fixed for real?
     
    Last edited: Apr 28, 2020
    mh114 and JamesArndt like this.
  31. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,735
    The workflow is like this:

    Create your own UV2 for lightmaps by hand and then pack each one with something like RizomUV or a similar good packing tool. Then massage: scale in lightmap and overal texel resolution until you have decent coverage. You might need to repack some of your UVs if they end up much bigger (so they waste space), or much smaller (so you get overlaps) than you thought. Then massage again.

    Keep repeating this loop until you get decent coverage. Around *0.7 of the theoretical maximum is pretty good.

    It is a ton of manual work, but this is how my lightmaps look these days:

    upload_2020-4-27_22-16-42.png

    Stupid things can still happen, but by doing a lot more manual work, you minimize the packing silliness.
     
    Last edited: Apr 28, 2020
  32. JamesArndt

    JamesArndt

    Joined:
    Dec 1, 2009
    Posts:
    2,932
    And this exposes yet another shortcoming. If you've authored lightmap UVs in your 3D package, there is zero massaging that you should have to do to those UVs in Unity. They should pass through unaltered. Hopefully they do implement this, as I've been told they likely will.
     
    OwlBoy- and Bordeaux_Fox like this.
  33. Sotalo

    Sotalo

    Joined:
    May 3, 2014
    Posts:
    3
    Any updates on this?
     
  34. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,735
  35. angiemon

    angiemon

    Joined:
    Mar 26, 2018
    Posts:
    37
    Yeah nah, this is getting ridiculous...



    That is freaking unacceptable.
    Let me guess, greedy Unity shareholders forcing you guys to work on completely nonsensical "features" because they heard some buzzword on Wall Street about the newest cool thing in tech instead of working and improving existing things that are actually important?
     
  36. rasmusn

    rasmusn

    Unity Technologies

    Joined:
    Nov 23, 2017
    Posts:
    103
    Unfortunately, I cannot see the image you posted. Can you please try re-posting?

    We have one minor update on this. Spatially coherent packing landed in 2023.3.0a4 (thanks to @Pema-Malling). It works somewhat similar to what I showed here.

    I won't comment on your guess, except to say that we know the packing is bad and that we (still) want to improve it. There has just been (even) higher priorities for us, e.g. ensuring GPU baking still works on MacOS even after OpenCL is removed (Apple deprecated OpenCL some years ago).
     
    AcidArrow likes this.
  37. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,409
    it was image like this (saw it before it expired)
    upload_2024-4-7_19-40-56.jpeg
     
  38. rasmusn

    rasmusn

    Unity Technologies

    Joined:
    Nov 23, 2017
    Posts:
    103
    Thanks mgear! This is a classic example and there's a reason for this shape.

    The packing algorithm will reduce the size of the lightmap if it can. However, these reductions happen by halving each dimension so each potential reduction step will give you 1/4 of the original number of pixel. This means that in order for a reduction to happen, all charts needs to be able to fit into a single quadrant (i.e. 1/4 of the pixels). In the example shown, this is quite clearly not possible, even if you rearrange them. Therefore Unity doesn't shrink the atlas in this case.

    That said, the utilitization is still awful. We need something better and this is on our roadmap but actually finding time to work on this has proven difficult (see my comment just above).
     
    mgear likes this.