Skip to content

Commit

Permalink
Update light map tutorial (gazebosim#346)
Browse files Browse the repository at this point in the history
* apply changes

Signed-off-by: Ian Chen <[email protected]>

* remove line

Signed-off-by: Ian Chen <[email protected]>
  • Loading branch information
iche033 authored Jun 18, 2021
1 parent 8bca5b2 commit 76aa471
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions tutorials/04_lightmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ To import a model go to `file` > `import` > (choose file type of model)

The next step is to create UV unwraps for your model. In Blender usually the first UVmap for any mesh created is for PBR textures and the second UV channel is for light map information. This secondary UV set is different from the UVs used to map things like color maps or normal maps because each polygon surface is receiving different lighting from all other polygons so each UV coordinate also needs to be unique.

For a fast automatic light map unwrap hit F3 and then search for “Lightmap pack”
For a fast automatic light map unwrap hit F3 and then search for “Lightmap pack”.
Make sure to the “margin” is set to 1 for max distance between faces (reduces shadow bleeding during bake)

@image html img/lightmap_unwrap.png
Expand All @@ -41,9 +41,9 @@ If the texture is black use the color picker and select the UV island and it sho

@image html img/lightmap_new_texture.png

### Step 4: Material shader
### Step 4: Material setup / Baking

In order to have the texture show we must assign it to a new material. With your model selected open the Shader tab and select `Add` > `Image` > `Image texture`. This will create a new image texture node.
In order to have the texture show the baked lighting we must assign it to a new material. With your model selected open the Shader tab and select `Add` > `Image` > `Image texture`. This will create a new image texture node.
* Add an image texture
* Connect the color from the image node to the base color of the material color (principled BSDF)

Expand All @@ -52,29 +52,38 @@ After this step add another image texture in the shader editor

@image html img/lightmap_material_shader.png

### Step 5: Render/Bake

When baking we have the option to either bake in all the lighting, both indirect and direct, or just the indirect lighting, also known as global illumination or bounced lighting, and use realtime lights in Ignition for the direct lighting and shadows. With the latter method we get sharper lighting and shadow detail as well as more accurate lighting on our dynamic objects however performance will be impacted by having more real time lights. Even with all the lighting baked it’s still a good idea to have one realtime light such as a large point light or directional light works particularly well in order to enhance the effects of the physically based materials.
@image html img/lightmap_bake.jpg

Now that the material node is set up, open the render properties and make sure that the cycles renderer active in the render engines drop down.
Scroll down to where it says bake, and then with the second image node selected (MeshLightBake step 4) hit bake. Blender should now start baking the light map for the model.
Scroll down to where it says bake, and then with the second image node selected (MeshLightBake) hit bake. Blender should now start baking the light map for the model.

@image html img/lightmap_new_texture.png
### Step 5: Show Baked Lighting

After the bake is finished you should have a separate light map of your model.
* To see it applied real time in your scene, go back to the hypershade / materials editor. Click on the Image texture that has the baked light map information and connect it to the base color.

@image html img/lightmap_material_connection.jpg

The above image shows the model with baked in lighting (Blender Viewport Shading turned on).
Model with baked in lighting (Blender Viewport Shading turned on):

@image html img/lightmap_rendered.png

### Step 6: Test/Export

Light maps are great for working with bigger scenes. With baked-in lighting, complex meshes can show realistic lighting without using heavy computation (the [Depot](https://app.ignitionrobotics.org/OpenRobotics/fuel/models/Depot) model below is a good example of complex scene with a baked light map).

To export light map image go to `UV editor` > `Image` > `Save as`

Lightmap baking applied to a more complex scene:
@image html img/lightmap_depot_saved.jpg

Light map baking applied to a more complex scene:

@image html img/lightmap_depot_render.png

## Using the light map in Ignition

When baking we have the option to either bake in all the lighting, both indirect and direct, or just the indirect lighting, also known as global illumination or bounced lighting, and use real time lights in Ignition for the direct lighting and shadows. With the latter method we get sharper lighting and shadow detail as well as more accurate lighting on our dynamic objects however performance will be impacted by having more real time lights. Even with all the lighting baked it’s still a good idea to have one real time light such as a large point light or directional light works particularly well in order to enhance the effects of the physically based materials.

Lightmaps can be applied to a mesh in Ignition the same way as other texture maps. Create an `ignition::rendering::Material` and specify a light map texture by calling
[SetLightMap](https://ignitionrobotics.org/api/rendering/5.0/classignition_1_1rendering_1_1Material.html#addc6eb6206e0a17ab82aeaea543e8c71). Recall that when creating the light map UV texture in Step 2, we typically use a secondary UV set for light maps. Make sure to specify the index of the light map UV set as the second argument to this function.

Expand Down
Binary file added tutorials/img/lightmap_bake.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tutorials/img/lightmap_depot_saved.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tutorials/img/lightmap_material_connection.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tutorials/img/lightmap_rendered.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 76aa471

Please sign in to comment.