Lightmap UVs stretched

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: :Enlighten and Preserving UV's - Unity Engine - Unity Discussions

It’s seems that it keeps happening. Unity is stretching the lightmap UVs even if you just use the default Unity cube.

1 Like

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)?

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:

  • The UVs are stretched
  • 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

No Stretched

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?

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

I am not seeing any stretching with the Unity default cube, my UVs look like this:
2060898--134241--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.

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?

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?

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.

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.

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.

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.2105093--137961--ChairChartingIssue_01.jpg


Lightmap UV’s from Maya

2105093--137963--ChairChartingIssue_03.jpg

1 Like

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.

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)
1 Like

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.


Unity 4.6
Left rectangular plane still gets a bit lower texel per unit, but not as bad.

1 Like

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.

1 Like

I can conform that it still happens in Unity 5.1

This issue is very much related to:

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!

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.

2 Likes

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.

OMG Kuba, you just made my day! <3
So we’ll get Bake Selected back with 5.2?