Introduction
In this documentation, we will talk about what is a lightmap and how to render it the proper way to get correct results.
What is a lightmap?
Lightmaps are dedicated texture files to store baked lighting and shadows on objects.
Lightmaps are a very performance-efficient way to achieve realistic lighting, shadows, and color bleeding.
Keep in mind that lightmaps only store diffuse lights. To get specular highlights you should use either a dynamic light or Specular Env Map or their combination.
Rendering lightmaps
Rendering lightmaps is the process of baking the light information into a texture file. Each software is different in how you should render lightmaps with them.
For example in the case of Blender, you are required to have the add-on "The Lightmapper" to be able to bake correct lightmaps.
There are a few rules to look out for when rendering lightmaps:
- Lightmaps should not contain an alpha channel. Some modeling software allows for the lightmap to have an alpha channel, but the final result is usually a corrupt image.
- When you are generating lightmaps in most modeling software and the object has a black diffuse color, the lightmap will be black in that region.
In some cases, it is true per color channel bases. So for example, if the diffuse color of an object has 0 red components then the red component will be black in that region of the lightmap.
There can be cases when you don't want this. Set a small non-zero value for the diffuse color to avoid this problem. - If you are using auto unwrap to create UV mapping for the lightmaps, always check the result, because in some cases the automatic algorithm may waste a lot of space.
You can try to split or merge objects together to avoid this. - It is preferable to render the lightmaps into 16-bit half-float RGB .exr file format. Make sure not to use RGBA because this way the background will be transparent and we don't want that.
Note: Some render engines (Blender - Cycles for example) generate complete maps instead of lightmaps by default and may require the use of add-ons to be able to generate correct lightmap.
Complete maps are similar textures to lightmaps but they are colorized with albedo / diffuse and they don't work correctly with dynamic lights.
Complete map shows the outgoing light from the material with properties such as base color already factored into the texture while a lightmap contains only the incoming light. With lightmap, the outgoing light will be calculated in the shader.
Here you can see the difference:
Noisy lightmaps
When rendering lightmaps depending on many factors the final lightmaps might be too noisy.
There are a few things you can change to make it better:
- Decrease the noise threshold for the render. This option will probably increase the render time as well but could greatly improve the final result.
- Increase render time. A longer render time will reduce the amount of noise present in the final texture.
- Use a denoiser. Denoisers use specific algorithms to remove noise from an image. Most 3d software has its own denoiser function and there are also dedicated softwares for this purpose.
- Make sure that after denoising no data is lost and the file format stays the same as before.
- Increase resolution. Although not as impactful as the other two options a higher resolution might yield greater results.
You can use these lightmaps with many of our shaders, the most commonly used is [Common]:Shaders\PBR\PBR_IBL_Norm_Light.xshad
You can learn more about PBR shaders here.