Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Lightmap UVs stretched

Discussion in 'Global Illumination' started by Bravo_cr, Mar 24, 2015.

  1. Bravo_cr

    Bravo_cr

    Joined:
    Jul 19, 2012
    Posts:
    148
    Hi there,

    We are migrating our project to Unity 5. The code it's already working and no we are converting our scenes. We have a not to complex scene (around 40k poly) and the lightmapping is taking way to much time compared to the "old" Unity 4. Well, thats not the reason of this post. We are seeing that unity stretches the UV when generating them for lightmaps, even if you create them in the 3d package. There was an old post about this: :http://forum.unity3d.com/threads/enlighten-and-preserving-uvs.281102/

    It's seems that it keeps happening. Unity is stretching the lightmap UVs even if you just use the default Unity cube.
     
    newmonuments likes this.
  2. KEngelstoft

    KEngelstoft

    Unity Technologies

    Joined:
    Aug 13, 2013
    Posts:
    1,059
    Are you supplying the UVs yourself or are you letting Unity generate the lightmap UVs (done by enabling "Generate Lightmap UVs" in the model import settings)?
     
  3. Bravo_cr

    Bravo_cr

    Joined:
    Jul 19, 2012
    Posts:
    148
    Hi KEngelsoft,

    If you try with the default unity cube you will see that the lightmap UVs are stretched. I have been studying the issue when you provide the UV2 using 3DMAX, it seems that if you don't fill the whole UV space two things happens:
    1. The UVs are stretched
    2. The remaining free space is no used by any other object
    I have attached two images as reference, one produces stretched UV and the other doesn't.

    Thanks for your interest.

    Stretched
    UV-Streched.jpg

    No Stretched
    UV-Nostreched.jpg
     
  4. KEngelstoft

    KEngelstoft

    Unity Technologies

    Joined:
    Aug 13, 2013
    Posts:
    1,059
    Hi! I can't figure out what is going on in your screenshots, would you mind filing a bug report so I can have a look at it in Unity?
     
  5. Bravo_cr

    Bravo_cr

    Joined:
    Jul 19, 2012
    Posts:
    148
    Sorry I have explained me wrong. The images provided are the UV2 of the mesh as they are setup in Max. The first one "Streched" has UVs only in the lower part of the full UV layout, this causes stretching when using in lightmapping, more precisely the UV are vertical stretched. The other image (No stretched) has UV coordinates in all the limits of the UV layout ( In (0,0) , (1,0) , (0,1), (1,1)), this makes the lightmapping use the UV as provided without stretching. Hoe it helps
     
  6. KEngelstoft

    KEngelstoft

    Unity Technologies

    Joined:
    Aug 13, 2013
    Posts:
    1,059
    I am not seeing any stretching with the Unity default cube, my UVs look like this:
    2015-04-09_12-56-55.png
    If you please submit a small project with your cube attached, it will be way easier to solve your problem.
     
  7. Bravo_cr

    Bravo_cr

    Joined:
    Jul 19, 2012
    Posts:
    148
    I' don't understand well what you say because the image you just posted has the UV stretched. The default UVs for a cube should have all the faces like perfect squares and in the posted images they are rectangles. This is really weird, maybe I missing something?
     
  8. KEngelstoft

    KEngelstoft

    Unity Technologies

    Joined:
    Aug 13, 2013
    Posts:
    1,059
    I think we are talking about different things or maybe I misunderstood what you meant. Can you send me your cube in a small scene, so I can have a look?
     
  9. Bravo_cr

    Bravo_cr

    Joined:
    Jul 19, 2012
    Posts:
    148
    Probably we are talking different things. The default Unity's cube also shows stretched UVs (In the image you posted I see that the UVs are stretched). If I just add the default Unity's cube and calculate de lightmap I can see the UV stretching. Take a look at the following image. There I try to explain the current UVs and how I think the UVs should be for a cube.
    StretchedUV-example.jpg
     
  10. rorydriscoll

    rorydriscoll

    Joined:
    Apr 14, 2015
    Posts:
    23
    I'm a little mystified by this too, and would appreciate an update. The chart view in the scene window shows perfectly square uvs. Looking at the texture-space charts in the object tab, it's pretty clear that the uvs are stretched.

    Incorrect.PNG

    The baked lightmap also has stretched uvs. I'm guessing that the untouched uvs for the cube are indeed square when generated, and that Unity is scaling them when packing them into the lightmap.

    Interestingly, you can actually see this happen... If you uncheck (or check) 'preserve uvs' while the object window is open, you can see the correct uvs generated. When baking finishes, they are moved into different locations.

    Correct.png
     
  11. drumonman

    drumonman

    Joined:
    Nov 25, 2013
    Posts:
    5
    After seeing this thread I went and checked on some objects in scene I'm working on and also noticed weird things.

    The object is a section piece of a couch, I laid out the lightmap UV's in Maya, and the charting preview shows those UV's seem to be a bit stretched and also flipped for some reason. ChairChartingIssue_01.jpg
    ChairChartingIssue_02.jpg
    Lightmap UV's from Maya

    ChairChartingIssue_03.jpg
     
    minhdaubu2 likes this.
  12. Futurerobot

    Futurerobot

    Joined:
    Jul 13, 2011
    Posts:
    179
    I'm, probably, having the same issue. An object with lightmap UVs generated by unity, get squashed in the lightmap atlas. It seems like it squashes the whole uv sheet for the object, into an area that would normally fit the lone uv island in the sheet. Here's a picture with the difference from 4.6 to 5.1, packing the same scene. In the unity 4.6 atlas, the highlighted object has the same proportions in the atlas as in the scene. In unity 5.1, it's squashed with empty space left above it.

    unity46-51_lightmapdifference.jpg
     
    Last edited: Jun 5, 2015
  13. Futurerobot

    Futurerobot

    Joined:
    Jul 13, 2011
    Posts:
    179
    Tested this some more.
    Square plane, Rectangular plane, Boxes. Created in modeling program, and with UV lightmap unwrapping turned on.
    Baked the same setup in 4.6 and 5.1 (wrong version number in picture), at 50 resolution.
    * In unity 4.6 the shadows stay sharp on both planes.
    * In unity 5.1 they become distorted on the rectangular plane that is squashed in the uv layout.
    * In both versions, the rectangular plane get a different amount of texels per unit than the square one for some reason. Even with lots of space to spare.
    * PS: A lot of texture atlas space is wasted. Didn't the lightmapper use to drop atlas size down if it could fit on less? I have a vague memory of getting for instance 1x1024, 1x512. etc. Now it's always 1024 (or whatever is set)
    shadowquality.jpg
     
    Last edited: Jun 5, 2015
    Bravo_cr likes this.
  14. Futurerobot

    Futurerobot

    Joined:
    Jul 13, 2011
    Posts:
    179
    Unity 5.1
    The difference becomes even more apparent at lower lightmapping resolution. This is 21 texels per unit. The shadow on the right square plane looks ok. The Shadow on the left rectangular plane gets a much worse quality.
    shadowsUnity52.png
    Unity 4.6
    Left rectangular plane still gets a bit lower texel per unit, but not as bad.
    shadowsUnity46.png
     
    Last edited: Jun 5, 2015
    Bravo_cr likes this.
  15. newmonuments

    newmonuments

    Joined:
    Oct 21, 2014
    Posts:
    12
    I am having the same issues. Perfect lightmaps created in Maya that work perfectly in Unreal Engine (for instance) have ugly seams and distortions in unity

    to see it clearly illustrated just switch to baked view in the scene window.
     
    minhdaubu2 likes this.
  16. Bravo_cr

    Bravo_cr

    Joined:
    Jul 19, 2012
    Posts:
    148
    I can conform that it still happens in Unity 5.1
     
  17. Kuba

    Kuba

    Unity Technologies

    Joined:
    Jan 13, 2009
    Posts:
    402
    This issue is very much related to:
    http://forum.unity3d.com/threads/gi-baked-point-light-blotching-black-spots.319940/
    http://issuetracker.unity3d.com/iss...irection-uv-maps-overlapping-causing-blotches

    For your convenience:
    "UVs not filling the entire 0-1 space, either smaller or bigger (as in this case), would cause the packing to go haywire. It would manifest itself in UV islands overlapping (causing black blotches), in resolution being calculated incorrectly (hence the object would get too low or too high amount of texels) and the UVs being stretched. It is now fixed in 5.2 and the fix will be backported to 5.1."

    Cheers!
     
  18. Kuba

    Kuba

    Unity Technologies

    Joined:
    Jan 13, 2009
    Posts:
    402
    This stopped happening when Bake Selected was introduced back in the day, as the packing changed completely back then. We will bring it back in 5.2.
     
    AcidArrow and essimoon2 like this.
  19. Kuba

    Kuba

    Unity Technologies

    Joined:
    Jan 13, 2009
    Posts:
    402
    The view that you're showing (Charting) is for UVs used for realtime GI and those are adjusted lightmapping UVs.
    There was a bug where the plain lightmapping UVs would be shown in that view at times, but it should have been fixed by now.

    To debug baked lightmaps please use the Baked Intensity and Baked Direction views.
     
  20. essimoon2

    essimoon2

    Joined:
    Nov 13, 2013
    Posts:
    191
    OMG Kuba, you just made my day! <3
    So we'll get Bake Selected back with 5.2?
     
    Last edited: Jul 2, 2015
  21. MrEsquire

    MrEsquire

    Joined:
    Nov 5, 2013
    Posts:
    2,712
    What release is the bug fix included in?
     
  22. Kuba

    Kuba

    Unity Technologies

    Joined:
    Jan 13, 2009
    Posts:
    402
    No. You asked if the "lightmapper used to drop atlas size down if it could fit on less" and yes, it used to do that.
    In 5.2 we will bring back the behaviour of "dropping the atlas size".

    Bake Selected was only mentioned because it was the reason why we changed from Beast's atlasing to our own back in the day. In 5.2 we will improve our atlasing.
     
  23. essimoon2

    essimoon2

    Joined:
    Nov 13, 2013
    Posts:
    191
    Oh I see. Thanks for clarification :)
     
  24. essimoon2

    essimoon2

    Joined:
    Nov 13, 2013
    Posts:
    191
    Any chance we will see 'Bake selected' again in Unity 5?
     
    Meceka and Kragh like this.
  25. jimmyjamesbond

    jimmyjamesbond

    Joined:
    Mar 17, 2015
    Posts:
    14
    Any update on this getting back-ported to 5.1? Is this fixed in the 5.2 Beta?

    Cheers!

    ~J
     
  26. Bravo_cr

    Bravo_cr

    Joined:
    Jul 19, 2012
    Posts:
    148
    Nope, is still broken in 5.2.f1
     
    MrEsquire likes this.
  27. SpiriTx

    SpiriTx

    Graphics QA Unity Technologies

    Joined:
    Apr 12, 2012
    Posts:
    251
    Was that a typo? There is no 5.2f1 build yet

    I just verified the issue yesterday with 5.2 beta 4
     
  28. Bravo_cr

    Bravo_cr

    Joined:
    Jul 19, 2012
    Posts:
    148
    Wow! sorry. It was a typo. It still happens in 5.1.2f1.
     
  29. A.Killingbeck

    A.Killingbeck

    Joined:
    Feb 21, 2014
    Posts:
    483
    You verified it was fixed or verified the bug still occurs?
     
  30. SpiriTx

    SpiriTx

    Graphics QA Unity Technologies

    Joined:
    Apr 12, 2012
    Posts:
    251
    I verified that it was fixed.
    Used multiple projects, some of which were filed by people from these threads, so quite positive that it should work in most* scenarios.

    *statistical devil inside me doesn't allow me to write "all"
     
  31. A.Killingbeck

    A.Killingbeck

    Joined:
    Feb 21, 2014
    Posts:
    483
    Is there an eta on when 5.2 will be released? We really dislike developing on beta versions, we'd rather be on the cutting edge than the bleeding edge :)
     
  32. SpiriTx

    SpiriTx

    Graphics QA Unity Technologies

    Joined:
    Apr 12, 2012
    Posts:
    251
    Unity roadmap is public now, so yeah - SEPT 8, 2015
    https://unity3d.com/unity/roadmap
     
  33. A.Killingbeck

    A.Killingbeck

    Joined:
    Feb 21, 2014
    Posts:
    483
    Wow ok, is there any talks about rolling this fix into a 5.1.2f2 version? As it stands, with this bug we will need to create a second set of UVs for the lightmap for all of our objects to make sure no stretching occurs and causes artifacts. We have a lot of objects!
     
  34. A.Killingbeck

    A.Killingbeck

    Joined:
    Feb 21, 2014
    Posts:
    483
    The problem still persists in 5.2.0b4. Black blotches on some objects.

    Although I tested the auto lightmap UV of a simple unity cube and it correctly applied no stretching. So I'm unsure if it's a different problem altogether.

    I've cleaned the GI cache and all light data and rebaked, still the same result. 1 of the objects has a unique set of UVs instead of generating and still shows black blotches.

    I will try to re-create the problem in a test scene and bug it, but I have a suspicion that I won't be able to replicate it in a scene with less objects. This is incredibly annoying!
     
    MrEsquire likes this.
  35. rwetzold

    rwetzold

    Joined:
    Oct 10, 2013
    Posts:
    225
    I also have a few objects containing black blotches. This is reproducible and I will share my whole project with Unity soon and report a bug on that (and quite some others ;-) ). I have some suspicions on why this happens (UVs of different objects intersecting that are themselves also intersecting). But with 5.2b3/b4 the situation already got muuuuch better for me. Not sure if I finally fixed all UVs of my big ProBuilder mesh or if Unity simply got better. I think the latter.
     
  36. VEIVIEV

    VEIVIEV

    Joined:
    Aug 3, 2015
    Posts:
    33
    Can confirm that this issue still exists in Unity 5.1.2p2.

    It seems preserve UV's does not in fact preserve them. It will adjust them and sometimes distort them. I'm guessing this tick box should preserve UV2?

    In this example I used UVee plugin to double check that Unity does in fact properly import an fbx file with UV1 and UV2 exactly as they were generated, which it does. Unity really needs it's own internal UV viewing tool!




    As you can see in this example when Preserve UVs is checked, the UV's look similar but are adjusted, scaled and changed. There's even a section that was detached.

    On another mesh example, UV2 is completely ignored when Preserve UV's is selected and brand new UV's are generated.



    We really need to have fine control over UV2 Lightmap layouts, and need to trust that Unity will obey the UV2 layout exactly.

    Without an internal UV viewing tool, this can be tricky to double check.

    Hopefully Preserve UV's is fixed in Unity 5.2?
     
  37. IAMB4TMAN2

    IAMB4TMAN2

    Joined:
    Mar 31, 2015
    Posts:
    1
    Can you confirm if this fix has this been backported to 5.1?

    Cheers
     
  38. chrismarch

    chrismarch

    Joined:
    Jul 24, 2013
    Posts:
    318
    We're looking forward to the backport to 5.1, and I am watching this thread waiting for the 5.1 backport release version announcement.
     
  39. chrismarch

    chrismarch

    Joined:
    Jul 24, 2013
    Posts:
    318
    I see this in the release notes for 5.1.3, is this the fix?
    • (693316) - Graphics: Configurable vertex compression to fix lightmap UVs shifting.
     
  40. Kuba

    Kuba

    Unity Technologies

    Joined:
    Jan 13, 2009
    Posts:
    402
    @chrismarch: No, it's not that fix.
    @IAMB4TMAN2: The fix has been backported to 5.1 and will be available in a patch release most likely next week.
     
    minhdaubu2 likes this.
  41. jim_altvr

    jim_altvr

    Joined:
    Aug 10, 2015
    Posts:
    4
    I'm currently using Unity 5.1.3f1 and I can confirm this bug is still present.

    I'm getting stretched UVs all over my lightmaps despite using the 'Preserve UVs' function.

    Any word on when this might get fixed? The fact that I'm over a month late to this discussion is not giving me hope...
     
  42. jjejj87

    jjejj87

    Joined:
    Feb 2, 2013
    Posts:
    265
    Still present in 5.2.0f3. Really frustrating.
     
  43. essimoon2

    essimoon2

    Joined:
    Nov 13, 2013
    Posts:
    191
    I can confirm this is still present in the latest version of Unity 5.2.
     
  44. SpiriTx

    SpiriTx

    Graphics QA Unity Technologies

    Joined:
    Apr 12, 2012
    Posts:
    251
    Could you please report bugs with your scenes and post case numbers here?
     
  45. jim_altvr

    jim_altvr

    Joined:
    Aug 10, 2015
    Posts:
    4
    One thing that might help diagnose this bug:
    On meshes where I was seeing their UVs get stretched in the lightmap, I found that the UVs were only taking up a small portion of the overall UV coordinates (in Maya). So for example, a particular mesh's UVs were in only the left half of the UV space. When I explicitly moved the UVs to cover more of the UV space, Unity behaved properly when packing them into a lightmap (it didn't stretch them).
    My guess is that there's some code that 'thinks' it's being efficient when the full UV space isn't being used, but instead of cropping the space, it's scaling it.
     
  46. jjejj87

    jjejj87

    Joined:
    Feb 2, 2013
    Posts:
    265
    I just submitted a bug + repo project for this issue. I am including screenshots for reference. I tested it under fresh install of 5.2.1p4 so yep, it is definitely still there.
    Case 736439



     
  47. AndreElijah

    AndreElijah

    Joined:
    Sep 22, 2013
    Posts:
    15
    Quick question - does this plugin use the CPU or GPU to generate the lightmaps?