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:
- Planes: 6
- Optimize for: Fewer Pieces
- Shell Layout: Into Square
- Scale Mode: Uniform // IMPORTANT to get clean maps
- Shell Stacking: Shape // IMPORTANT to make best use of the available resolution
- Percentage Space: 0.2000 // IMPORTANT to have enough room for the bleed areas
- Create new UV set: checked // IMPORTANT
- 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":
- Objects to bake: Selected
- Keep original shading network: checked // IMPORTANT
- Use bake set override: checked // IMPORTANT
- Normal direction: surface front // IMPORTANT
- Prefix: myLightmap // IMPORTANT this will be the filename of the lightmap TIFF, pick a name you like
- X resolution: 2048 // depends on the size of the object usually 2048 is plenty, try various values
- Y resolution: same value as "X resolution"
- File format: TIFF // others work to as long as Unity can import them
- Bits per channel: 8 bits // IMPORTANT
- Number of samples: 1
- UV range: Normal [0 to 1] // IMPORTANT, other settings lead to distorted maps
- Fill texture seams: 3 // IMPORTANT, this is the bleed area in pixels around each UV shape to avoid jaggy edges later in Unity
- Override mesh UV assignments: checked
- 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 ...
-- SWITCH TO UNITY --
... 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: http://forum.unity3d.com/viewtopic.php?p=66440
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!
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.
Did AT's tutorial ever appear anywhere?
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!
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.
Yes, you are absolutely correct, I just discovered that myself.Originally Posted by TzI 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.
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.
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,
i´ve tried this tutorial and works great on my iphone project, finally after several years i know how to bake shadows in Maya
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
Hello I've some problem with the generated texture. (see picture)
Any body knows how to fix it?