Unity | Lightmaps with Unity Lightmapper 

Overview

  • Make sure the imported models have Generate Lightmap UVs (if you want Unity to take care of that)

  • Set any object you want to bake into the lightmap to Static

  • Set any lights you want to bake onto the objects to Baked

  • Set up the Lightmap settings and generate the lightmap

 

Generating Lightmap UVs

For lightmaps to bake the information your objects need a second layer of UVs to bake onto. You can do this yourself in an external application like Blender etc. But if you are putting the scene together in Unity it is somewhat easier and faster to let Unity do this for you at the expense of using the texture space as efficiently.

 

  1. If you want Unity to unwrap your objects for lightmapping, select your model file in the Project window and then go to Inspector / model tab > Generate Lightmap UVs. Then select Apply. A window may popup asking if you want to apply the change to the children objects as well. 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

NB : If you bake and your lightmaps look terrible (overlapped UVs, large dark blocks for no reason, etc.) then not having correct second UVs is probably the reason.

 

Static Objects

  1. Select objects to be lightmapped in the scene or Hierarchy and set it to Static in the top right of the objects Inspector. If this is not set, the lightmapping will not see it.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Light Settings

  1. Set any lights to be used for lightmapping to Baked, not realtime, using Light / Inspector > Mode. If this is not set the lightmapping will not use this light. If you use Mixed the light will be both a real time and a baked light. As noted it is not recommended to use more than one realtime light unless you know your space runs well on low end systems.



































     

  2. As an example moving forward, this scene has one real time directional light (the one that comes with the template), an area light (which has to be baked), a spotlight, and a point light. All lights (apart from the realtime light) will be set to Baked. One object with emissive materials (see the materials tutorial for details) will also be added.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Lightmapping settings

  1. Open the Lighting Tab from Window / Rendering / Lighting to access the lightmapping Settings if it hasn’t been already. Drag and drop it according to your preferred layout location.


















     

 

 

 

  1. Turn down most of the default settings in the Lightmapping tab in order to speed up renders and make sure to set the Directional Mode is set to Non-Directional.







































     

 

 

 

  1. You can use Progressive GPU (Preview) (in the Aqua box above) for faster, but less accurate lightmaps, or change to Progressive CPU for more accurate but slower lightmaps. It is recommended to use Progressive CPU for final bakes. 

  2. Note that turning off Ambient Occlusion is optional as this does add a lot to the result at the expense of baking time. So adjust these settings depending on your CPU/GPU.

 

Baking the Lightmaps

  1. Once the objects are set to static, the lights are set to Baked, and the settings are set to something more reasonable, you can generate the lightmap by Pressing the Generate Lightmaps at the bottom of the lighting Tab. Depending on your scene complexity, lightmap settings and computer this can take anywhere from 10 seconds to 10 minutes (or more).

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Note the quality will be low due to the settings. This stage is more like a guide for how the lighting will appear, and you can adjust the settings as needed. Spend a little time with the lightmapping settings and get a feel for the differences each one does and how long that affects the baking time.

 

  1. Once baked, you can check the resulting Lightmap textures in the Baked Lightmaps section in the Lighting Tab. You can use this to visually see the result of the unwrapping process, and can sometimes guide you with trouble shooting (overlapping second UVs or sections of your space that don’t require baking (polygons that are never seen such as the other side of a ceiling or floor).

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Refining the results

 

  1. Modify Lighting / Scene / Lightmapping Settings > Lightmap resolution to adjust how much space the polygons take up on the lightmap. Increasing this will (potentially) increase the amount of Lightmaps you have (and therefore resulting file size) when the previous lightmap is ‘full’, but it increases the amount of space the polygons take up on the lightmap texture (eg. better quality). Finding the sweet spot between quality and number of lightmaps is half the fun.






















    Lightmap resolution = 20, Total Bake Time = 9 seconds






















    Lightmap resolution = 65, Total Bake time = 44 seconds. This is a very high resolution, but there isn’t much in the scene). These renders are done on a Ryzen 5950X, 32Gb RAM, 2070RTX.
     

  2. The Samples options will increase the quality of the lightmap at the expense of time to bake. So once you have a good feeling about your lightmap, turn these up before your final build. That said, the difference in results get harder and harder to see at the higher levels.




     

  3. Setting Lighting / Scene > Max lightmap size to 2048 is a good starting point, you can of course adjust this depending on the needs of your space. It is not recommended to go to 4096 or above however as that increases the texture size significantly.

  4. Isolate the results of your baked lights, by turning down/off your real time light/s and the environment/ambient lighting under Lighting / Environment / Environment Lighting > Source and/or Intensity multiplier. Your scene will look different when you turn these back on, but it’s a good way to understand the effect of each light…so bounce between the two (or three) states. 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Optimising results

  1. Artifacts should not have Static applied as they will affect, and be affected by, the environment and they might not be there forever (as artifacts can be modified or turned off). So a safe bet is just to turn all Artifacts’ Static to off. Portals are fine however as they cannot be edited in the space.





























     

  2. Make sure that the Lightmap resolution is set to the level that fills up the last lightmap. Check what your lightmaps look like in the Lighting Tab / Baked Lightmaps section. If there is any blank space on the final map, then turn up the Lightmap resolution (even by a decimal level) until there isn’t. Make sure that it doesn’t spill over into a new lightmap, and have most of it blank. Lightmaps will take up considerable file size, so keep this in mind when you are choosing how many you create. 2-3 at 2048 should be plenty. However this could be more or less depending on the complexity of your space.





























    Lightmap Resolution = 50. This lightmap has nearly half the space wasted
     

  3. It is possible to make an object take more texture space in the lightmap. Select the static object and increase/decrease the Mesh Renderer / Lightmapping > Scale under Lightmapping. Putting that higher will mean it takes more space in the lightmap, less and it will be smaller.

 

 

 













Troubleshooting

  1. Unity Lightmapper sometimes has issues with light leaking between separate objects (eg. a box for a wall and a box for the floor). You can try to mitigate this by :

    1. Create smaller polygons. A huge single polygon floor will probably look bad as the area will be too ‘big’ for precision baking, in this case you could make a gridded plane instead.

    2. Make the objects that overlap into one object (in blender etc) and join them at the transition. Light can’t leak if there's nowhere to leak.
       

  2. As noted, if many/all of your objects look like the lightmapping is messed up, there is a reasonable chance those objects have not been set to Generate Lightmap UVs correctly and the lightmaps are overlapping. Check out Generating Lightmap UVs at the beginning of this tutorial for more information.

1_SetGenerateLightmapUVs.gif
2_SetToStatic.gif
3_LightToBaked.gif
3_LightExamples.gif
4_OpenLightingTab.gif
5_LightmapSettings.png
7_GenerateLightmaps.gif
8_CheckLightmaps.gif
6_LowQualityLightmaps.png
8_ResolutionSettings_High.png
7_SamplesSettings.png
6_TurnOfAmbientLighting.gif
9_ArtifactsStaticless.gif
9_WastedLightmap.png
10_ScaleInLightmap.png