Search Unity

Lightmap baking (Maya 2008)

Discussion in 'Formats & External Tools' started by noradninja, Nov 18, 2007.

  1. noradninja

    noradninja

    Joined:
    Nov 12, 2007
    Posts:
    420
    I am trying to bake lightmaps in Maya 2008. I did this in Game Scene and Character design in Uni (Fullsail), but that was a year and a half ago, and I cannot remember the correct way to do it.

    So what I have done is created a secondary UV set for all the objects in the scene that maps all the scene object UV's to a single texture, so I can use one lightmap for the whole scene.

    When I try to use bake set overrides to create a single map for the lightmap, this is what I get:




    Obviously, this is not correct, and I cannot for the life of me figure out what I am doing wrong here.

    If, however, I do not use a bake set override, from the front, things look fine:




    BUT, from the back, things are not as good as they would seem from the front:




    Of course, the other downfall to this is that it creates multiple maps for the lightmap, which is not ideal at all; I would like to create a single texture sheet for the scene lightmap.

    Any help anyone can give me on this would be greatly appreciated; I have scoured Google for tut, but am unable to find any that will help me with this :eek:
     
  2. noradninja

    noradninja

    Joined:
    Nov 12, 2007
    Posts:
    420
    On some more research, here is the weird bit:

    Maya bakes the lightmap properly, with each object's lightmap on the texture sheet:



    However, it is applying the texture to the objects using the default UV set (where each object takes up the entire UV map) as opposed to the lightmap UV set, even though I have switched the objects to the lightmap set:



    I cannot, for the life of me, figure out what it is I am doing wrong here. Halp! :p

    (Also, strangely, when I switch to the lightmap UV set, you'll note that Maya refuses to display the texture assigned to the objects in the UV Texture Editor....)
     
  3. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,324
    Here's a similar example to your sample scene using Maya 2008 with 2 UVs and a layered texture. Have you tried opening any of these models in Unity yet to see whether or not the 2 UV sets work? In Maya sometimes the UV linking can get screwed up and therefore show the wrong image on the wrong UV. Take a look at how my example scene is set up and if you have any further questions I'll be more than happy to try and answer them.
     

    Attached Files:

  4. AaronC

    AaronC

    Joined:
    Mar 6, 2006
    Posts:
    3,552
    I got errors with Ethans file unfortunately.

    He's the man, but my 2c says :

    Right click over your geometry, go UV sets> Uv linking.

    That should open the relationship editor. Leftclick items in left collum, and click their related nodes in righthand collumn. By default, All textures are usually alligned to the first uv set.

    I also found having the scene rendering set to high quality visually stuffs things up, so try alternating between high quality and default, doing quick test renders inbetween. And as Ethan says, save the files into a unity project, so you can see whats happening with each change.

    You'll have it sorted before the day is out Im sure.

    /2c

    AC
     
  5. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,324
    Yep, make sure those UV links are set correctly... thanks Targos, I forgot to mention exactly how to go about linking them up properly. And even if they don't look right in Maya, those 2 UV sets will import into Unity so have a go on importing them into Unity and applying the Lightmapped shader and see what happens :wink:

    Best of luck and we're here to help until you get it working,
    Ethan
     
  6. noradninja

    noradninja

    Joined:
    Nov 12, 2007
    Posts:
    420
    Thanks for the sample. As it turns out, it was the UV Linking (which, it having been about a year since I used multiple UV sets, I had completely forgotten about). Once I relinked the lightmap UV sets with the correct map, all is glorious and right in the world.




    Again, thanks a ton to all who helped me here, I beat my head on this for about 3 hours today:p
     
  7. deepcgi

    deepcgi

    Joined:
    Aug 24, 2006
    Posts:
    57
    I was going to make a request for exporting layered shaders directly into Unity, anyway, but this thread demonstrates the need nicely.

    In Maya 2008, Autodesk has finally updated the rendering engine to include multi-layered, multi-UV materials. It also does a nice job with CGFX pixel shaders. In other words, we can finally see our game levels in Maya as we are modeling, texturing and lighting them.

    The tight integration of Unity with Maya is already a wonder to behold! It would be wonderful if layered shaders (with up to 2 UV sets) could be carried, more-or-less directly, into Unity. Perhaps, by generating simple, placeholder pixel shaders on import?
     
  8. noradninja

    noradninja

    Joined:
    Nov 12, 2007
    Posts:
    420
    In this vein, what would really knock my socks off would be the ability to export shader networks from Maya to Unity (perhaps via CGFX translation). I can easily put a shader network together in Maya and preview it on my various machines (ie Mac Pro) with the high quality setting turned on in the veiwport, it would be a real time saver to just export that directly to Unity as opposed to recreating the shader and possibly running up against limitations like the (until recently, thanks again, Aras) lack of RGB spec maps.
     
  9. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    I'm completely new to lightmapping, but want to start using it to make my games more efficient. I was trying to do it in Blender, but the documentation for that is nil, so I'm using Maya now. From what I saw in the manual, lightmapping is probably covered, but I'm not familiar enough yet with Maya to follow the instructions well. How did you guys learn to get lightmapping happening?
     
  10. noradninja

    noradninja

    Joined:
    Nov 12, 2007
    Posts:
    420
    Well, I happened to go to Fullsail Real World Education in FL and got an Associates of Science in Computer Animation :D

    That being said, I will give you a quick rundown:

    Model all your scene objects and UV map them for texturing.
    Once you have done that, open the UV Set Editor (Create UV's>UV Set Editor), select all your objects, and add a new UV map (name it something like Lightmap). Then open the UV Texture Editor (Window>UV Texture Editor). With all your scene objects still selected, select the Lightmap set in the UV Set Editor window (see picture below.)



    Now click Create UV's>Automatic Mapping option box, and set it like shown below:



    These settings will automatically map all your objects with no overlapping UV's and fit them into the texture square.

    Once you have your whole scene automapped in the Lightmap UV set, arrange all your lights and do a few test renders (in Mental Ray) to get them looking how you want. When you are ready to generate your lightmap, click Color>Batch Bake (Mental Ray) option box. Bake all objects to a texture, and be sure to turn on the Bake Set Overrides box, then use the settings below:



    The Fill Texture Seams setting is important if your UV's are close to the edge of the map; that can sometimes cause errors in the map so adjusting this will compensate for that so you don't get seam lines.

    Feel free to change the map size and file format, but keep in mind that since they are just shadows, it's best not to go too high; the idea is to render one or two lightmaps for an entire scene (eg. rendering two 10k x 10k maps to get detailed shadows is a waste of texture VRAM, and lightmaps don't need to be super detailed to look good). If you scroll down in this dialog you can set up Final Gather settings, etc if you choose.

    Now, you can click the Bake and Close button. Be prepared to wait; even on a beast like the Mac Pro Mental Ray renders can take a while, especially if you have lots of lights :p

    Once all is done, just create a layered shader in Maya for each object; the bottom layer is going to be the object texture, and the top layer will be your lightmap. If your lightmaps look wonky like they are applying the whole map to each object, see the above instructions for fixing the UV linking. OR, you could just load Unity with your scene, and use one of the lightmapped textures with your lightmap image to see them in engine.

    I know it seems long, but its really quite easy once you do it a couple of times. It will seem like old hat in no time, and if you have any issues, let us know and we will help you out. :wink:
     
  11. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    Ok, that helped out a ton. Thanks!

    However, as soon as I bake the light map at this point, it then replaces the texture that had previously been used on the object. It also places the map in an inconvenient place, somewhere deep in my Documents folder. I am sure this stuff is easy to fix, but I'm incredibly new at this. I also don't know how to do the following:

    I don't expect anyone to teach me all about Maya, so if this is very basic, feel free to tell me where to look instead of making a tutorial. I appreciate whatever you can do for me.
     
  12. noradninja

    noradninja

    Joined:
    Nov 12, 2007
    Posts:
    420
    To prevent the texture replacement, be sure to check Keep original shading network. (See picture)



    As for the file location, what you want to do is create and set a project for each scene file you are working on. This will make it easier for you to find the images you are looking for. SO, when you create a new file (for your scene) in Maya, click File>Create new Project. Navigate to the disk you want to save the file to and choose it.





    In the New Project dialog, click browse to pick a location for your project, and give it a name in the Name field. This will create a folder with that name. Then click the Use Defaults button to fill out the rest of the form, and click Accept. This will store your project in volumename/projectname/. Now click File>Project>Set and pick the enclosing folder (the one you put in the project name for). Now, when you save the files, they will be saved in volumename/projectname/scenes/, and all your renders and such will be stored in the Images folder in the project folder. Your baked textures will be stored in volumename/projectname/renderData/mentalRay/prefixname/, where prefixname is the prefix you put into the Baking Options dialog (for this, I always use Lightmap, it just makes it easier for me). At this point, you can use File>Import to import other Maya files to arrange your scene. I make it a point to do this before I work on anything in Maya; I would suggest the same to you just for organizational purposes.



    As for the layered shader, you can go here http://www.digitaltutors.com/digital_tutors/video.php?v=153 and watch a nice video that will walk you through the process step by step. Note that you don't *have* to do this, you could just set it up in Unity, but I personally like to do it in Maya first to see exactly how things look before I start moving assets to Unity, that way I can debug the art side of things early on. Good luck, and again, let me know if you need any other help.
     
  13. babelchips

    babelchips

    Joined:
    Jan 27, 2008
    Posts:
    6
    This post is very useful, but the pics don't show anymore.

    It would be extremely useful if the images were relinked or uploaded...
     
  14. GeroldS

    GeroldS

    Joined:
    Dec 30, 2007
    Posts:
    34