Search Unity

Making lightmaps in Maya (tutorial)

Discussion in 'External Tools' started by GeroldS, Feb 18, 2008.

  1. GeroldS


    Dec 30, 2007
    Since all the info on creating lightmaps is scattered through numerous threads in this forum and partially broken i decided to make a small tutorial and separate thread for all those who seek comprehensive info on the topic. So here we go:

    How to make lightmaps in Maya and bring them into Unity:

    DISCLAIMER: All the following is based on my (limited) experience and skill in both Maya and Unity. Though i still hope this small tutorial may be usefull to some. All feedback to make this guide better is ofcourse welcome.

    -- IN MAYA --

    1) Model whatever you want to light, add textures and materials to your objects as you normally would:

    2) Light the scene and render it with Mental Ray until you like it:

    3) Select and "Mesh->Combine" all geometry
    4) With the freshly combined Object still selected open the "Create UVs->Automatic Mapping" properties dialog and use these settings, then click apply:

    Code (csharp):
    1. Planes: 6
    2. Optimize for: Fewer Pieces
    3. Shell Layout: Into Square
    4. Scale Mode: Uniform // IMPORTANT to get clean maps
    5. Shell Stacking: Shape // IMPORTANT to make best use of the available resolution
    6. Percentage Space: 0.2000 // IMPORTANT to have enough room for the bleed areas
    7. Create new UV set: checked // IMPORTANT
    8. UV set name: Lightmap // IMPORTANT
    5) Open the "Window->UV Texture Editor" to check out your new UV map you're gonna use to bake lights:

    6) Switch to "Rendering" toolbars and make sure you have your object still selected
    7) Open the "Texture/Lighting->Batch Bake(mental ray)" properties dialog and use the following settings, then click "Convert and close":

    Code (csharp):
    1. Objects to bake: Selected
    2. Bake to: Texture // IMPORTANT
    3. Bake shadows: checked // IMPORTANT
    4. Keep original shading network: checked // IMPORTANT
    5. Use bake set override: checked // IMPORTANT
    6. Color mode: light and color // IMPORTANT
    7. Normal direction: surface front // IMPORTANT
    8. Prefix: myLightmap // IMPORTANT this will be the filename of the lightmap TIFF, pick a name you like
    9. X resolution: 2048 // depends on the size of the object usually 2048 is plenty, try various values
    10. Y resolution: same value as "X resolution"
    11. File format: TIFF // others work to as long as Unity can import them
    12. Bits per channel: 8 bits // IMPORTANT
    13. Number of samples: 1
    14. Bake to one map: checked // IMPORTANT
    15. UV range: Normal [0 to 1] // IMPORTANT, other settings lead to distorted maps
    16. Fill texture seams: 3 // IMPORTANT, this is the bleed area in pixels around each UV shape to avoid jaggy edges later in Unity
    17. Override mesh UV assignments: checked
    18. UV set name: Lightmap
    8) Maya will now render the lightmap into a texture (this may take a long time depending on the resolution settings and render options you used) and create a file using the prefix you specified. The lightmap will NOT display in Maya. The file will look something like this:

    9) Save your scene and ...


    ... import it to Unity
    10) Locate the lightmap ( default: /user/[your username]/documents/maya/projects/[maya project name]/renderData/mentalray/lightMap/[prefix].tiff and import it
    11) Place the Object in a Scene and select it
    12) Change all materials associated with the Object to "Lightmapped" and apply the .tiff file we just imported as lightmap
    13) Done, enjoy.

    Hope this helps. Some more details can be harvested in this thread:
  2. AaronC


    Mar 6, 2006
    Nice work! This will be helpful.

    The only trick I learned as well, was to rightclick over the geometry, select UV Linking, and in the box that appears, select the UV in the left, and the corresponding filetexture in the right, and just by doing so assignes the file texture to the correct UV set.>Save...Open Unity>Do Cool stuff

    Good Stuff Gerold!
  3. nm8shun


    Jul 14, 2007
    Yes. Thanks much!
  4. antenna-tree


    Oct 30, 2005
    Nice work GeroldS, goes through most of the process. The only problem is you combine meshes with separate materials. Combining meshes and calculating the Lightmap is great, but you then need to separate these meshes that don't use the same material... you can then assign the lightmap to each one of these objects in the secondary UV channel.

    Creating 2 UV channels is the key and UT will hopefully be coming out with a full tutorial of this process in the near future... I created one for the Unity Magazine, but now it will probably be integrated into a future Unity tutorial.

  5. marty


    Apr 27, 2005
    Did AT's tutorial ever appear anywhere?
  6. MikePaixao


    Dec 1, 2008
    awesome place to start! I will add a few suggestions to cover any questions someone might have though


    if you want to brighten up the shadowed sections.

    before baking out the map, create an ambient light in your scene, it will tone down the shadow a bit (you cant really tell in his example, but once you start to have textures it becomes more apparent and you lose all diffuse to a pitch black shadow)

    brighter you set the ambient, less pronounced your shadows become


    there is a way to bake all your texture to a single texture using this technique, with some modification

    create your other UV set, and instead of baking shadows you disable that setting, and make sure the only lights you have in your scene is an ambient light, so everything is flat shaded, now you can bake out the "light and color" option and set the name as "texture" or something obvious.

    now you can copy the UV map from your lightmap UV channel to your map01 channel ( i suggest duplicating your original just incase )

    hope this helps!
  7. tz


    Oct 13, 2007
    I may be mistaken about what you were trying to do, but I believe if you're going to mix diffuse maps and lightmaps, you'll want to set the bakeset setting for color mode to 'light' only, as opposed to 'color and light', otherwise your lightmaps will get the diffuse texture map baked into them. This is fine if you have non-tiling textures and want to do a single texture, but if you're going to use the lightmap-diffuse shader in Unity, I believe you'll end up doubling up your diffuse pass.

    One further note that could trip people up. If your UVs don't come into Unity looking the way they do in Maya, one of the first things to do is to try deleting your construction history. Maya may be fine displaying UVs that are an aggregate of operations, but the history portion will be lost when brought into Unity.
  8. caitlyn


    Jun 20, 2008
    Yes, you are absolutely correct, I just discovered that myself.

    As TZ just said, be sure to set the bakeset to LIGHT and not "color and light"

    That little oversight aside, GeraldS THANK YOU for this extremely useful and informative tutorial! It has made my life a little bit easier today.

    :) :) :)
  9. SudoSoul


    Mar 3, 2009

    Thanks for all the helpful information in this and other threads regarding the lightmap process. The demo above is excellent and I have the Unity portion down, but I'm failing to successfully set up 2 UV's out of Maya.

    Once I combine all of the objects to create a new Auto generated UV map, what do I do with it then? Does it then permanently replace my individual items or is it simply used to create the entire-scene lightmap. If it's the later and I am to discard the combined object, then how do I retain the UV map from that combined set.

    I'm missing something simple in all this, but for the life of me I can't seem to figure it out. Any help would be *greatly* appreciated,

  10. raulvisel


    Feb 29, 2008
    i´ve tried this tutorial and works great on my iphone project, finally after several years i know how to bake shadows in Maya :D

    i discovered a trick also for bake ambient light, first i tried with camera color enviroment and didnt work, then with mental ray enviroment sky and didnt work, finally the solution was to create a big sphere covering all the level with inverted normals (normals facing the center of the sphere) and add a material with incandescende, this means the sphere will emit light in the normals direction,
    that create a cool GI effect on my level

    i dont know if this is the best solution to create a GI effect thought it worked ok for me

    hope this helps
  11. limdor


    Sep 30, 2008
    Hello I've some problem with the generated texture. (see picture)

    Any body knows how to fix it?

    Thank you![/img]

    Attached Files:

  12. lolclol


    Jan 24, 2013
    a video tutorial would have been great. :D
  13. lolclol


    Jan 24, 2013
    a video tutorial would have been great. :D