Download

Fill Light-map UVs with geometry VS maintaining correct aspect ratios?

As an example, say i have a rectangle plane (2x4m) and since UV channels are always square i can either maintain the correct aspect ratio and leave half
of the UV channel empty or stretch the rectangular plane into a square to fill in the gaps. Which would be best? Even lightmap pixels or stretched ones
with the benefit of having more lightmap data using the same amount of texture memory? or is that not true?

The lightmap would be the same size either way. For things like a floor or ceiling I just use planar mapping and fill the space even though it won’t be the right aspect ratio. For more complex stuff I have it try to match. If you have some really long parts in a mesh that are messing up the packing then I also put in some loops on the long part so that I can then split up the UV’s on that more so that it doesn’t waste so much UV space.

Well if you stretch a 2:1 ratio into a “2:2” ratio, you could run into detail problems. For a lightmap, it’s probably not that big of a deal though. Basically, you’d end up with 2x as much texture resolution in a single axis, of a face, than you would in it’s other axis. It could lead to weird aliasing/stepping/blurring issues in the shadows due to having to down sample it back into it’s 2:1 ratio. Now scaling a UV face up 30 or 50%, on a single axis, wouldn’t probably be that big of a deal though.

Darth is right though, that whole texture gets loaded regardless of how much of it gets used. Fun statistical fact: on average, ~30% of every single texture is wasted space in memory; due to UVing gaps and so such. I doubt this engine will see a feature like ptex any time soon, but that would pretty much do away with that loss and the hassle of UVs in general; though it has it’s own overhead in computation.

There are a lot of good guides on UVs and lightmaping in general. It’s not really engine specific topic, so you can use the information from just about any game development guide. I’d Google around and see if there are any definitive verdicts on how to handle situations like this.

Lightmaps are packed together to bigger atlas. So question is does that atlas packer take white space into account.

Yes, they atlas into a larger texture, but as far as I know, it still takes the 0->1 UV spaces from individual meshes and just lays them out in a grid next to each other to form the atlas. The sizes of the “cells” are based on LM resolution. So a 256^2 tile would be the size of 4 128^2 tiles put into a square. I don’t think it actually arranges and optimizes a “master” uv atlas where it accounts for everything in the scene and optimizes it all at once. So if you had a mesh, where half the UV space was empty, it would still appear on the lightmap atlas; within it’s little cell of the atlas.

Yeah, that lightmap atlas will be the sized by the texture rather than the UV’s of the mesh that uses them.

Interesting… thanks for all the replies :slight_smile:

Is there a reason why UE doesn’t optimize lightmaps more? For example, I have a simple and very long piece of geometry and splitting it multiple parts to fill the uv space greatly increases poly count. Also, results in lightning artifacts on seams.

For example, if only the left half of the uv space is occupied, couldn’t lightmass treat it like 2 squares of 1/2 resolution? Or it wouldn’t work because mipmapping or something like that?

The only thing it could do is crop the lightmaps to the size of the UV’s, but there’s some potential issues with bleeding. It doesn’t matter what the dimensions of a lightmap in the atlas are, since the atlas itself is going to be a power of two size.

Yes, that exactly what I mean. Crop the lightmaps then pack them into atlas. I believe it’s called “rectangle bin packing”. It’s used in UE’s “Size map” tool for example.

Capture.JPG

That packing there is just the standard packing algorithm, what it doesn’t do is shift things over if the mesh doesn’t use the full UV space.

Super interesting thread, I think if future algorithms can detect unused space and crop it accordingly there’s huge untapped potential for optimisation.

Actually, I found that there is something in UE that will pack UV textures. It’s “merge actors” command. Of course it’s not possible to use in all cases, but when you have some long pieces of architecture, like beams and pillars, combined with others, like walls, you can combine them to reduce draw calls and pack UVs.