Autogeneration of lightmap UVs often fails

I have written a custom importer for Alembic meshes for our studio pipeline, and everything works fine except for Lightmap UVs. When the StaticMesh is set to generate lightmap UVs, it often fails to do so. At first I thought maybe there was something wrong on my end, but then I realized that some meshes do properly get generated lightmap UVs, but most do not.

My guess is that the algorithm to generate them is simply failing due to incredibly complex and dense UVs. The meshes have upwards of 20 materials on them in order to maximize texture density, so there are tons of overlapping UVs. These are imported from a VFX pipeline that uses UDIMs, so each UDIM gets converted to a separate material and the UVs normalized to 0,1 space.

Is there anything I can do here or are we going to be stuck manually making UVs for lightmap?

Ok maybe I am being too harsh on Unreal here :slight_smile: To do some tests I opened the alembic into Modo to use Modo’s Pack feature (which is basically the same thing) to pack all the UDIM UVs into 0,1 with no overlaps and it has been running for 10 minutes and is nowhere near complete.

Hi John,

As you’re already aware Alembic support is not one of our import options, but is on the wishlist/backlog to have at some point. I would probably expect there to be some issues though because it’s not uncommon for other types of assets to have issues generating lightmap UVs in UE4.

There are a couple considerations to remember when using the generated lightmap UVs,

UE4 will not create new seams and break UV islands apart. It will only repack the existing UV. So with this in mind you will need to at least have setup your UVs in a way that can be repacked for use with this system. As an example if you have a cylinder and you do not break the side face so that it can be unwrapped as a rectangle, when the lightmap is generated in UE4 the face will result in overlapping UVs because it cannot be packed and seamed correctly.

So with that in mind, depending on the assets being used it may be better to do a rough UV just to create some UV islands and then let UE4 repack the lightmap.

Thank you!

Tim

Hi Tim,

As you’re already aware Alembic support is not one of our import options, but is on the wishlist/backlog to have at some point. I would probably expect there to be some issues though because it’s not uncommon for other types of assets to have issues generating lightmap UVs in UE4.

Well like I said we wrote our own Alembic importer and everything with the exception of lightmap UVs works just perfect. All standard UVs come in properly. However they are all overlapping because we go from a model with one material and 30 or 40 UDIMs, to a StaticMesh where each UDIM is converted to a material, and the UVs repositioned to 0,1. The end result is a mess of overlapping UVs given to Unreal. Everything looks perfect in the engine with the exception of Lightmaps.

UE4 will not create new seams and break UV islands apart. It will only repack the existing UV. So with this in mind you will need to at least have setup your UVs in a way that can be repacked for use with this system. As an example if you have a cylinder and you do not break the side face so that it can be unwrapped as a rectangle, when the lightmap is generated in UE4 the face will result in overlapping UVs because it cannot be packed and seamed correctly.

The exact same UVs given to Modo properly pack into a non overlapping 0,1 space, and all Modo does is translate, rotate, and uniformly scale the UVs. so it isn’t an issue with seams or anything. However it took like 30 minutes for Modo to do the operation.

So my guess here is that the algorithm in Unreal is designed for speed, not completeness, and after a certain number of iterations it just gives up?

I’m not completely familiar with that part of the code, but I would say that it would focus on speed.

Overall, it’s an ongoing process to improve this feature that was introduced with 4.5/4.6.

Brian laid out the plan, but no obvious timeframe for all the improvements that would need to happen. How we plan to make lightmaps awesome in UE4 - Rendering - Epic Developer Community Forums

Ok putting this here for future reference if others have this same issue.

The algorithm UE4 uses apparently takes texel resolution into account, and will fail to generate UVs if the resulting resolution would be too small. Or, well, something like that I guess.

By going into the StaticMesh build settings and increasing the “Min Lightmap Resolution” to 2048, and applying the change I was able to get proper UVs to be generated which took about as long as it does in Modo, about 30 minutes to process.

So long story short I guess, if your Lightmap UVs come out blank, try increasing your Min Lightmap Resolution.