Search Unity

level building workflow (and lightmaps)

Discussion in 'Formats & External Tools' started by markb, Jun 26, 2007.

  1. markb

    markb

    Joined:
    Jun 15, 2007
    Posts:
    9
    So in my reading, it seems that level building is most efficiently done within Unity. This makes sense, as we don't want duplicated geo when we should be using prefabs. Curious if people have...

    1. Build parts (rocks, trees, pylons, etc) in Maya. (or whatever)
    2. Setup my level in Maya.
    3. Do my lighting in Maya, including my lightmapping.
    4. Write out some simple data file via MEL of objects and their transforms.
    5. Have Unity read this data file and "rebuild" my level.

    Sounds like it would work, but then I think, hey, what about my lightmaps? If I have 3 trees in 3 places, I'd like them all to have different lightmaps. Do I have to export that info as well? And then reassign each map in my shaders? Giving each instance of the prefab a different map? People must have to deal with this all the time.

    If this IS similar to how your pipes work, do you read/stock your levels once, like a utility? And then remove that function when it comes time to distribute?

    Is there some easier/smarter way?!

    Thanks.
     
  2. pete

    pete

    Joined:
    Jul 21, 2005
    Posts:
    1,647
    prefabs are still duplicate geo and you want to build your level in maya. you can build in unity but there's no snap or place on surface in unity (unless you script it). props that you use in game you want to place as individual objects but your level geo you want to combine for optimization. unity is an ide for building your game rather than building your geo.

    basically, each object is rendered as many times per frame as it has textures. so if you have 3 trees that share the same 3 textures (ie diffuse, bump, lightmap): as separate objects they will render 9 times; as 1 object it will render 3 times. the amount of polys dumped to the gfx card can add up for complex stuff. so optimize as much as you can. for your example, i would try to use the same texture for my lightmap and make them one object. the lightmaps can be different parts of the texture so that they're unique but combining them into one object will reduce rendered polys per frame. though sometimes that might not help if say the trees are on opposite sides of the level. unity uses frustum culling. if part of it is in view, the whole thing gets rendered. so you need to think it through/test a bit.

    i don't work in maya. i'm lightwave -> fbx. for me, textures automagically are assigned as long as i have the texture in my assets folder. the default is the simple diffuse shader though. so lightmaps and bumps etc need to be manually assigned. i'm sure you can make an editor script to do it for you.

    as you noticed, using prefabs helps. set it up once and instantiate via script or duplicate in editor. but that isn't like instancing for static rendering. a prefab is still a bunch of polys that get rendered every frame. each instance will have the scripts and shaders you assigned to the original. if you want them different, yes, you have to change them individually which will break the prefab connection.

    more-or-less, transforms come in auto. where you place it in maya is where it should be in unity - relative to 0,0,0. pretty much just save and import. one great thing is double click it in unity, make changes, save and poof! updated in unity. no need for any outside functions/mel scripts.

    not sure if lights will come in. iirc they won't. the workaround is place a poly where your lights are and then you can find them in unity (again iirc, not real sure).

    so after all that, the short answer: 1 2 yes. 3, place polys for your lights and manually/script to place lights in unity. and yes, bake your lightmaps in maya then assign in unity. 4 5 don't worry about - just save your model.
     
  3. NicholasFrancis

    NicholasFrancis

    Joined:
    Apr 8, 2005
    Posts:
    1,587
    Actually not - they get shared between objects, so having multiple prefabs of the same object keeps memory usage file size down. There is one exception: If you scale the objects differently they will get duplicated, so there is a memory cost. They are still loaded as one object, so the file size is not modified. duplicating the objects inside Maya will mean a larger scene as we do NOT share meshes.
    [/quote]

    This is not correct. Each MATERIAL gets rendered one time for each pixel light hitting the object. So using complex shaders does not result in more draw calls.

    See here for more info:
    http://unity3d.com/Documentation/Manual/Optimizing Graphics Performance.html

    In general: people who use lightmapping, create their entire level in Maya or others. People who are not going to use lightmaps mostly assemble levels in Unity from smaller prefabs. Another solution would be to use ambient occlusion though - it depends on the style but if ambient occlusion works for you you can still make parts and assemble them in Unity.
     
  4. pete

    pete

    Joined:
    Jul 21, 2005
    Posts:
    1,647
    i stand corrected. hope it helped! :)
     
  5. markb

    markb

    Joined:
    Jun 15, 2007
    Posts:
    9
    Thanks a lot to the both of you. It helps a great deal! I will assemble in maya for anything that's not overly repetitive.

    Nicholas: When you say I could use ambient occlusion you mean as a light map, yes? I intended to bake both direct and indirect lighting into my lightmaps. Do you mean bake only AO into my set pieces and then add my direct lighting in Unity? I intend to do that for characters and props. I just don't want to loose my cast shadows for this project.

    Thanks again!