Search Unity

Can someone explain light baking?

Discussion in 'Formats & External Tools' started by Randy-Edmonds, Sep 25, 2007.

  1. Randy-Edmonds

    Randy-Edmonds

    Joined:
    Oct 10, 2005
    Posts:
    1,122
    I'm having a hard time understanding light baking and how it works with Unity. The way I understand it is that you use a modeler (ie Cheetah 3D) to render the objects such that the shadows and highlights are created on the 3d objects. Then somehow, and this is what I don't understand, new textures (that include the shadows) are exported to be used in Unity?
     
  2. DaveyJJ

    DaveyJJ

    Joined:
    Mar 24, 2005
    Posts:
    1,558
    Texture baking does indeed take place in your 3D modeling program. ou bascally set up your scene including any ambient/direct etc lighting and render the resulting lighting effects (shadows, etc) into a texture that is then part of the 3D model that can be brought into Unity.

    The only downside to this method is of course that the shadows etc are not live, and that the rendering process can take some time in your 3D program depending on how complex your scene and lighting is, how well it's rendered, etc.

    In Banana Warehouse 2 Ron and I will be using a combination of baked textures because of how well Ron can model shadows etc, and dynamic lighting and shadowing that's part of the upcoming Unity 2.
     
  3. Randy-Edmonds

    Randy-Edmonds

    Joined:
    Oct 10, 2005
    Posts:
    1,122
    Thanks DaveyJJ,
    But can you tell me why, in Cheetah 3D, I export an object I get the .3ds object and a small texture that is just basic.... the texture is small and just repeats throughout the object, it isn't the entire rendered texture.
    It might help to know what I am doing....
    1. I create a tree in VUE Infinite.
    2. I export the tree as a 3ds (the texture is just a small 'sample' that gets tiled onto object, part for the truck and part for the leafs).
    3. I open the 3ds file into Cheetah and save as native Cheetah file (plays well with Unity). But this doesn't save the rendered model, its just the same texture data as was exported from VUE.
     
  4. drJones

    drJones

    Joined:
    Oct 19, 2005
    Posts:
    1,351
    you need to set up 2 UV sets - one for the texture on that object only, and one for the lightmap (usually many object uvs grouped together in one tx for performance).

    in the fps tut there's many texture examples to see like this, that'll probably give you a good example if you check out the textures materials there ; )
     
  5. Randy-Edmonds

    Randy-Edmonds

    Joined:
    Oct 10, 2005
    Posts:
    1,122
    @drJones... I think you are talking about the Lightmap feature built into Unity. I'm talking about using an external 3d modeler to bake textures.

    @DaveyJJ... I just discovered that Cheetah 3D version 4.2 doesn't do texture baking, but, the new beta version (4.3) does! I downloaded it and, after a few minutes of frustration, figured it out. It works great!!

    Thanks!!
     
  6. jaydubs

    jaydubs

    Joined:
    May 3, 2007
    Posts:
    136
    dr.jones ... why have one large texture for the lightmap ? Why not bake into each texture ? Why not only have one UV set per mesh with the light baked into it ? If there was a nice texture per mesh and then one large texture for light/shadows that covers the whole room wouldn't it be really grainy thus spoiling the look of the nice texture ? I'm trying to understand multiple UV sets and can't figure out the benefiets ...

    I don't get the actual reason for multiple UV sets per mesh for my personal use of Maya and Unity ... I create 3D architecture pre-vis ... apart from if the lighting changes, but if you get hi res renders checked off then provide the real-time player from Unity it's going to look as per the hi res lighting set-up ... :?

    JW
     
  7. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Usually when you are texturing, it is quite useful to mirror uvs, tile it etc.
    When you mirror or tile geometry then you don't have unique uv's for each pixel on screen anymore. For lightmaps you need a uv set that is unique for the entire model. Another reason is that very often you want to share lightmaps between many objects, but not the diffuse texture. With multiple uv sets you can set your uv's up completely seperate so you have more flexibility.

    If you can do it without using mirroring and tiling only using uv scale/offset then you might as well only use a single uv set.

    Baking lighting and diffuse texture into the same texture is a bad idea. The reason is that if you want high detail textures, then most likely you want to use tiling. Lightmaps are unique and non-tiling and usually quite a bit lower resolution than your diffuse texture.
     
    Henry_Sun likes this.
  8. NicholasFrancis

    NicholasFrancis

    Joined:
    Apr 8, 2005
    Posts:
    1,587
    The idea is that you have, say, a wood floor texture that tiles several times over the floor. Then you have the lightmap that covers the entire floor.

    You want to be able to see the grains in the wood, but your lighting doesn't need that millimeter precision.

    Hence you want to use different mapping for floor and lightmap.

    Some people do that by using one UV set and just tiling the floor texture, however, once you begin to do some precise mapping with your diffuse texture, that quickly become unwieldy....
     
  9. AaronC

    AaronC

    Joined:
    Mar 6, 2006
    Posts:
    3,552
    Thanks Nicholas and Joachim, its always good to hear from you guys because well, if anyone knows it should definately be you guys...

    Theres a bunch of conventions for lightmapping that we learn along the way. Picture this:

    My Barracks, around 1000 different pieces of wood, sandbags sheets of tin, posts. All nicely UV'ed on first set.

    I can either combine the objects into one, map a second uv set, and bake lighting, then seperate each object again (to get under the 65000 poly threshold for unity import), or bake each object seperately.

    Version one means theres a single lightmapp for the whole scene, but each objects lightmap is around 0.05 % of the lightmap. (good for convinience but not really good for performance, im guessing..)

    Version 2 (select 1000 objects and batch bake, create a new lightmap for each object) crashes maya. (on an intel 2.16ghtz cpu)

    I have yet to try batch baking in smaller batches, say 20 at a time-that will probably work though. Maybe.

    My question is, using the origional method, where each individual object uses 0.05 % of the lightmap, is that a ridiculous idea in terms of loading those textures into ram/vram? Ie for quality, I get 0.05% of the texture per object, but is the computer having to process the whole texture sheet for every object, or is it only having to process the tiny portion visible...?

    It seems like a convinience/low performance vs a inconvinient,/better performance tradeoff to me. These pics illustrate the issue.

    If anyone has suggestions on best methods/worst methods, I would welcome the input.
    AC
     

    Attached Files:

  10. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    If all those objects use the same big lightmap, just use small parts of it, then it's perfectly fine. In fact most likely faster than using lots of small lightmaps.

    And it's a standard practice when doing ligthmaps - the level is built from dozens of separate objects, but most often it uses just a couple of big lightmap textures, each object using a small part of the texture.
     
  11. AaronC

    AaronC

    Joined:
    Mar 6, 2006
    Posts:
    3,552
    Thanks Aras.

    Okay thats the part I find confusing-if I have 1000 instances of the above 2 textures( for 1000 individual objects), diffuse at 1024 and lightmap at 2048(to get rid of the jaggies), isnt that slower than diffuse at 1024 and lightmap at 1024(with an individual map for each object)?

    So even though the standard way of doing it is the easy way, theres lots of unrendered texture for each object, as opposed to the labour intensive method of individually mapping each object, at a higher quality...

    For both performance and texture quality i wouldve thought AAA studios would map individually, eventhough its more work...

    Thanks for your knowlege here :wink: Ive been racking my brains over this stuff for ages.
    AC
     
  12. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    Not quite sure what you mean... :)

    In the above lightmap - is that a lightmap for a single object? Or are there lots of objects in that lightmap, each occupying only a very small portion of the whole texture?

    The efficient way is to use the same lightmap on different objects, where each object gets it's own chunk of lightmap space.
     
  13. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    If you look at commercial games that use lightmapping, you see that the lightmap is, in fact, far lower resolution than the rest of the textures, and is, in fact, quite grainy. So in that sense, yes. But it's just shadows, so bilinear filtering usually makes it look acceptable. The point of using 2 UV sets is so that you have your low-res lightmap that uniquely covers the entire level, which is totally independent of your nice textures that are tiled and whatnot.

    --Eric
     
  14. AaronC

    AaronC

    Joined:
    Mar 6, 2006
    Posts:
    3,552
    Thats a lightmap for about 1000 objects. so thats 1000x a 1024 diffuse, and 1000x a 2048 lightmap, given each object has its own copy of the material ( So that meants the same material, 1000 times over, once for each object. The issue being that of those 1000 lightmaps, 99.05% of everysingleone is not used. Is it? If its paid for by the engine/cpu/gpu/ram and not being used, its not efficent, right?

    To try and simplify, these are cube uv maps. Does unity calculate them both thew same, or is the one with the smaller uv map cheaper? the smaller one uses less pixels, but both textures are 512x512. Im assuming unity would calculate both based on the 512x512 factor, therefore from start to finish, neither is cheaper, but both are the same. I mean cheaper in the laymans context of "We want highest framerates possible"

    Thanks again, Im about to learn something really valuable I think.
    AC
     

    Attached Files:

  15. NicholasFrancis

    NicholasFrancis

    Joined:
    Apr 8, 2005
    Posts:
    1,587
    Let's do some math here:

    1024x1024 RGB texture takes up 600Kb of memory compressed.

    That means one detail texture and one 2048x2048 will take up 3.3 MB of video memory.

    having a unique 1k per object diffuse+lightmap for 1000 objects will put you at around 1.3 gig of video memory. That will be SLOW, as the graphics card will not be able to fit that in at once and will begin swapping in and out.

    AAA games are the same as most other titles - they're doing performance tradeoffs like the rest of us (in this case: blurry lighting for being able to actually RUN the game).

    Read this tutorial:

    http://www.cybergooch.com/tutorials/pages/lighting_rfom1.htm

    Although it's mostly about style, some of the later pages have the lightmap alone so you can see how its done.
     
  16. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    No. The materials are different for each object, but all of them still use the same lightmap. So all objects use the same lightmap. Everything is ok and good, and in fact better than having 1000 of very small textures!
     
  17. AaronC

    AaronC

    Joined:
    Mar 6, 2006
    Posts:
    3,552
    Well thats good news. I guess theres some things I just dont need to know, if you guys tell me what to do!

    Ive been pondering this for a while now and its very timely to learn this. Very much appreciated. Thank you.

    And thanks Nich for the link, a lot of those pictures change on mouseover, which is really interesting. Looks a great game..

    I'd love to find a place to learn exactly how they do things in hot titles, like seeing how many materials were used in a call of duty level for example, what the wireframe looks like, and what the texture sheets look like, their size etc.

    Do any forum members have any favorite links for "How they did (xxxx title here)" I really dig learning from examples like that. Cheers guys

    AaronC
     
  18. Jonathan Czeck

    Jonathan Czeck

    Joined:
    Mar 17, 2005
    Posts:
    1,713
    http://forum.unity3d.com/viewtopic.php?p=49517

    Cheers,
    -Jon