- Edited
Hi.
After days and weeks struggling with BakeLightmap issues, I got baking light working pretty well.
Problems I found:
- Denoising consumes huge amount of memory. The bigger size of lightmap texture is created, the denoiser needs more memory
- Meshes rasterization also slows down, when lightmap texture size increases. Overall baking time can be slow, regardless of the quality settings.
- In case where multiple BakeLightmaps shares same mesh, the last baked will take over the mesh and bind the lightmap to it.
- Godot editor is not always refreshing the baked lightmap.
My conclusions:
- To avoid "fighting" for the shared mesh, use just one BakedLightmap per scene.
- High resoultion of the lightmap is not needed. Reducing the texture size will speed up baking and avoiding out-of-mem crashes while denoising.
How to reduce the lightmap texture size? There are two possibilities in Godot:
- setting up lightmap_size_hint on each MeshInstance
- reducing default_texels_per_unit on BakedLightmap node.
The problem is that "default_texels_per_unit" are overridden by lightmap_size_hint and in most cases gives nothing, so you must adjust lightmap_size_hint manually for each mesh. This is problematic when the scene is composed of many meshes or imported via tools like Qodot.
I solved the issue by introducing an experimental parameter to BakedLightmap: force_lighmap_scale. It scales down or up the lightmap texture size.
Setting it to 0.1 or 0.2 results in very fast light baking and solves crashing issues during denoising, also for high quality settings. Downscaling the lightmap about 5x times gives still very good results. For my scene sized about 300 x 60 x 200 units, setting lightmap_scale to 0.2 gives final exr texture of 1024x2048 size, and short baking time (about 1-2 minutes for all lights direct+indirect+shadows, HDR, color).
Now I can do light baking in Godot. The one thing I'm missing now is ambient occlusion baking.
Final recommendations for Godot developers:
- Please consider adding "lightmap scale" property to BakedLightmap, maybe together with min an max props to limit the maximum and avoid too small sizes. This will give a handy possibility of fine tuning the light quality, baking times, memory consumption, and will give easy way of avoiding crashes.
- Please consider upgrading OIDS (denoiser) to the recent version. Some memory and performance issues were already addressed.
- Please consider adding ambient occlusion baking. That would give best quality results without using slow and not best SSAO.
Kind Regards,
Marcin