Get the maximum scale in lightmap for any renderer!

Hey,

I’m trying to create an editor script to set the ‘scale in lightmap’ value to its maximum for any selected game object with a mesh renderer on it. So as a result each object that I do this to, will get a full light map allocated only for that particular object. I have noticed in the editor that, if we increase the scale above the max possible scale, it shows a warning that says ‘Object’s size in lightmap has reached the max atlas size’. Is there a way to see how they are actually calculating that limit in the mesh renderer component?? . I have tried pretty much everything else I can think of. If anyone is interested I can post my half done solution.

Thanks

3152653--239662--Capture.PNG

Bumping this question. Any have any ideas??

Bumping, this should really be a thing

Hi,

The number of texels (light pixels) of a renderer must be lower than the number of texels in a single lightmap.

Capture2

Number of texels in a single lightmap: Max Lightmap Size * Max Lightmap Size = 1024 * 1024

In the simple case of a basic cube like the following:

Number of texels for (the area of) a cube (length of side: 1 unit): Scale X * Scale Y * 2 + Scale X * Scale Z * 2 + Scale Y * Scale Z * 2 * Lightmap Resolution = ((1600 * 1300 * 2) + (1600 * 1000 * 2) + (1300 * 1000 * 2)) * 1

Number of texels for (the area of) a cube < Number of texels in a single lightmap

The “Scale In Lightmap” parameter allows to respect that constraint and it seems to be squared, so that the constraints becomes:

Number of texels for (the area of) a cube * (Scale In Lightmap*Scale In Lightmap) < Number of texels in a single lightmap

In the example above:

Scale In Lightmap < sqrt(1024 * 1024 / ((1600 * 1300 * 2) + (1600 * 1000 * 2) + (1300 * 1000 * 2))) = 0.3245

In case a custom mesh, the area seems to be calculated/evaluated by Unity but I didn’t invest much. I guess we can discover more by looking at the sources: UnityCsReference/Editor/Mono/Inspector/RendererLightingSettings.cs at master · Unity-Technologies/UnityCsReference · GitHub