What can we help you with?

< All Topics
Print

Lightmap Baking

Computers have the ability to create extremely realistic images. One of the reasons for this is a process called rendering, wherein the paths a light ray takes from light source, around the room and to  the camera are calculated down to the millimeter. There’s a lot of light rays and often a lot of light sources so this can take quite awhile – in fact many feature films take hours or even days to render a single frame of a 24 frame per second digital movie.

This obviously would not work for real time rendering but we can still use the process to create realistic results. This is done through baking or rendering the output of these calculations to a texture instead of an image. When you use this texture as a lightmap it modifies how a model is displayed to make it look like it is lit in a really accurate way. The only downside is that the lighting is static, meaning it cannot change – but this is perfect for an environment or game level.

Lightmap for the Small Shop on SPACE Metaverse.

Making a Lightmap

NOTE: Not mentioned in the video (whoops!) is that for every model you want to bake, before you bake it, you also have to click on the Lightmap UV map in the UVMap list!

  1. Create the object and light your scene using Cycles.
  2. Create a second UV channel by pressing the (+) sign to the right of the UV window.
  3. Name it something you’ll remember – this will be the Lightmap UV.
  4. In the second UV channel, make sure the entire model is unwrapped to the extent of the UV space. You can use Blender’s “Lightmap UV” function to do this. Just make sure you add a margin (gap between different UV islands).
  5. In the material that you have assigned to the object, create a new image texture.
  6. Create a UV map node. Set it to the Lightmap UV set and plug it into the Vector port of the texture map.
  7. Repeat this process for every material that will use this lightmap image.
  8. In every material, click on the lightmap image so it is highlighted with a white border. The bake output will go to whatever image is selected in the material so you want to make sure it’s your lightmap!
  9. Do this for all objects that you are baking. When you are finished, shift-select the objects that you want to bake if you are baking multiple.

    Note: if you are baking multiple objects to the same Lightmap then all of those objects must have a UV map with the same name and be unwrapped in the same UV space. Select all the objects, enter edit mode and then UV unwrap them all at once into the same UV map.
  10. Go to the Render tab.
  11. Make sure the render engine is set to “Cycles”. You will not see a Bake button unless you have set the engine to Cycles.
  12. Scroll down to find the “Bake” dropdown. Open it.
  13. Change the Bake Type to “Diffuse”.
  14. Uncheck “Color”. We only want the Direct and Indirect lighting.
  15. Under the Render settings, change how many samples you want to use. More samples = more better but also more longer.
  16. Under “Output” (below “Bake”) make sure your margin is set to between 2 and 5, generally. This is the amount of distance the lightmap will spread outside of the UV island. Too much and it will overlap with other islands.
  17. When you’re ready, click “Bake”.
  18. You should see a small taskbar on the bottom with the bake progress. It will go from 0-100% for every object so don’t be surprised if you see it go to 100 then drop back down.
  19. Once the bake is complete you can view it in any Image Viewer window by selecting the image texture from the dropdown list. You can also check them by dropping them into the Diffuse slot of the material.

Denoising

  1. Your render will still probably have a lot of noise. We can remove it by using Blender’s Denoise feature in the Compositor.
  2. Go to the Compositor window and make sure to check “Use Nodes” at the top.
  3. Create a Viewer node. This will let us view the results.
  4. Create an Image Texture node and plug it into the viewer node. Set the Image Texture node to your lightmap and it should appear in the background of the Compositor.
  5. Create a Denoise node and drag it between the Image Texture and the Viewer node. It will begin Denoising and you will see a progress bar at the bottom of the screen.
  6. Once it’s complete the denoised texture will appear in the Compositor.
  7. Go to any Image Viewer window and select “Viewer” from the dropdown list.
  8. Once your denoised image appears, go to Image -> Save As and save the file. Go into the Shader editor and switch your Lightmap to use this new file. Do this for all the materials and you’re done!

Using the Lightmap in SPACE

In order to use the Lightmap you will need the Mozilla Hubs Blender Plugin. In each material that you baked the lightmap for, create a MOZ_lightmap node. Plug the lightmap into it – and you’re done!

Previous Going from Blender to SPACE
Next Ambient Occlusion for GLTF
Table of Contents