I want to bake a lightmap and create a second UV channel between all my game assets without combining them then i want to use it in Blender Game Engine.


UV Mapping

Unfold your meshes that will generate your first UV Channel, it will be used for your texture and normal map. Make sure that the seams aren't facing the player too much. You can see your UV Map in the Data tab in the property menu represented by a face with three vertices.

You will need to create a second UV Channel that contains the UVs of every meshes for the lighting information but be careful make sure to apply any mirror modifiers.

To create the second UV Channel enable the Addon called "Texture Atlas", select every assets, in the Render tab scroll to the bottom you will see Texture Atlas, click on the "+" icon and name it this will be the name of the second UV Channel. The resolution option isn't needed you will set it with the image you will create. Then choose the type of Unfold between Smart_UV and Lightmap:

_ The Smart_UV splits the UV based of their angle of orientation.

_ The Lightmap split every faces for the highest texel density (cover as much space/pixel as possible) but could create visible seams.

Then click on Auto Unwrap, at the right you can set the margin (space between UVs) by default 0.01 is too low, the seams will be visible, use 0.1 instead.

If you select an asset and hasn't renamed anything you will see in two UV map, the first called UVMap and the second TextureAtlas.

enter image description here


Use Blender Cycles, prepare your lighting, apply a material, use Ctrl + L to link it to all your asset. Do not use a texture use the default white diffuse with RGB at 0.8 each. A tip is to use a create several diffuse called for example: wood, stone, grass, etc. with the same color, change the color to see them then reapply the 0.8 color. This will allow later to directly import your textures on them and have the materials split. You can use some emissive material if you want to create area lights in your scene.

You will need to create an image to bake your lightmap, open the UV/Image Editor, create a new image, name it for example "lightmap" and set your image with a 2048 or 4096 image, if you want to work with Filmic color management you will need a 32 bit Float image, see this post: How can i use Filmic with Blender Cycles bake

In the node editor add an image texture node with the image you have just created and do not connected it to anything to use the image for baking. Use the same image for your emissive materials.

With all your assets selected go in Samples and adjust the render value, an higher value reduce the noise but increases the speed. You can set a low value like 10 to test if the baking works correctly.

Then go in the bake menu, for the bake type use Diffuse and enable Direct and Indirect you don't need color (to make the baking slightly faster). Adjust the margin, to know what value to use divide the resolution by 256, for example for 4096 we need 16 px.

Click on bake, to see the result switch in texture mode in the 3d view and in the "n" menu use Shadeless in Shading and Only Render in Display. Don't forget to save your lightmap.

Note: if you get a weird baking that mean that the bug haven't been fixed yet, you will need to duplicate and join all your assets to bake the lighting because the bakes overlaps each other.

Using the lightmap

Duplicate and move your assets to another layer, the duplicated assets will use Blender Render materials.

Switch to Blender Render or Blender Game mode. In the "n" menu of the viewport use GLSL and the Textured mode. For each material uncheck the button Use Node (the icon represent two node attached) near the name an check Shadless in the settings. In the texture tab import the lightmap in the second slot and use the second UV channel in the Mapping menu.

Here is what my scene looks like:

enter image description here

For the blend type use Overlay.

Then import your texture in the first slot and use the first UV channel, you can adjust the position and size by scaling and rotating the UVs of the first UV Channel.

To use multiple textures create a new material, select faces in edit mode and click Assign, use another texture and your lightmap for the second UV Channel.

Note: all your textures must use a middle value to have consistent lighting, you can fix that in GIMP by moving the Color > Curve to an high point in the histogram in the middle line:

enter image description here

Here i have applied multiple materials:

enter image description here

For your emissive shader just use a shadeless shader with a color, pick the color used in Cycles and apply it for the Blender Render/Game material, you wont need any texture.

You can bake a skybox switch to Blender Cycles, in the World tab in the property panel click on "Use Nodes", click on the dot on the right of Color and select Sky Texture then orient the sky. Create a sphere, invert his normal with w > Flip Normals in Edit Mode, use a Lightmap UV Unfold to cover the maximum UV space, apply a material and texture and bake in Environment bake type. You will need to bake your assets each time you change the environment to match the sky.

  • 1
    $\begingroup$ I suggest to not use lightmap unwrap : due to mipmapping of lightmaps in 3D realtime engine, this can generate artefacts (example).Smart UV or classic unwrap with seams marked on tactical places help to hide this. $\endgroup$ – Vinc3r Apr 18 '17 at 9:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.