Unity not exporting UV2s correctly with the FBX exporter

I am trying to bake my lightmaps with Unity (because I can find NO lightmapper on the entire internet, all I find is some useless lightmapper on github that only bakes AO…)

Okay, fine. Unity seems to be alright as a lightmapper… But…

I must first install a package called “FBX exporter”. Alright, fine. That’s fine. But when I export it, it somehow centers all my UV2s, instead of keeping it the same UV2s as in Unity’s lightmap preview.

Unity’s lightmap preview:


Various UV editor UV2 preview:

I have downloaded almost every UV editor software in existence, and while they are all crappy software, they at least all seem to show the exact same UV2s as each other, so I think its a Unity FBX Exporter issue.

My next step is to download a different FBX exporter for Unity, haven’t done that cause of too many aches and pains, and I ran out of energy to do that.

UPDATE: I installed a different FBX exporter (ASCII FBX exporter) and it does the same thing.

After discussing with an associate of mine, we have reached a strong theory… The lightmap UV2s displayed in the Unity lightmap preview, do not match the uv2s contained in mesh.uv2 or the exporters. (And the correct UV2s that fit the lightmap, are the ones in the lightmap preview.)

I do not know why this is, but such behavior must be overridden, if there to is be correct exported UV2s…

I’m not really familiar with the FBX export package, but I can give you a piece of information about lightmap UVs that might be pertinent:

How the lightmap is applied to an object is not only determined by the UV2 data. It is also determined by the objects “lightmap scale and offset” (Unity - Scripting API: Renderer.lightmapScaleOffset). Every properly authored mesh will have UVs in the UV2 channel that fill the entire [0; 1] range. Thus if you visualize the UV2 data of a bunch of different meshes overlaid, it will be a big overlapping mess. To figure out the real area of a lightmap that is applied to object, you need to take the UV2 data, multiply it by the lightmap scale and add the lightmap offset. In other words, the data in the UV2 channel represents the UV layout before packing - before scale and offset have been applied. One reason for this is that all objects using the same mesh can share the same UV layout, even if they exist on different parts and in different sizes on the lightmap.

The lightmap preview window shows where the object will actually sample the lightmap, so after scale and offset have been applied. It looks like the exporter is exporting the UV2 data before that scale and offset. That makes sense to me - it’s exactly the data that is stored in the mesh, after all. If you want to export UVs with that transformation baked-in, you’ll probably have to modify the UVs before export.

1 Like

Ah that would explain it. Because in Unity 6 it appears to do the same thing. I saw the Unity 6 trailer, impressive. The graphics look better than Unreal 5 tbh