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 Reprojecting a 2D image onto a 3D model. U and V refer to the axis of the 2D coordinate system. map in the UVMap list!
- Create the object and light your scene using Cycles.
- Create a second UV channel by pressing the (+) sign to the right of the UV window.
- Name it something you’ll remember – this will be the Lightmap UV.
- 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).
- In the material that you have assigned to the object, create a new image texture.
- Create a UV map node. Set it to the Lightmap UV set and plug it into the Vector port of the texture map.
- Repeat this process for every material that will use this lightmap image.
- 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!
- 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.
- Go to the Render tab.
- Make sure the render engine is set to “Cycles”. You will not see a Bake button unless you have set the engine to Cycles.
- Scroll down to find the “Bake” dropdown. Open it.
- Change the Bake Type to “Diffuse”.
- Uncheck “Color”. We only want the Direct and Indirect lighting.
- Under the Render settings, change how many samples you want to use. More samples = more better but also more longer.
- 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.
- When you’re ready, click “Bake”.
- 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.
- 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.
- Your render will still probably have a lot of noise. We can remove it by using Blender’s Denoise feature in the Compositor.
- Go to the Compositor window and make sure to check “Use Nodes” at the top.
- Create a Viewer node. This will let us view the results.
- 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.
- 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.
- Once it’s complete the denoised texture will appear in the Compositor.
- Go to any Image Viewer window and select “Viewer” from the dropdown list.
- Once your denoised image appears, go to Image -> Save As and save the file. Go into the A small program that runs on the GPU to inform it how to shade a polygon in 3D space. 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!