Search Unity

Lightmaps and Blender - are they mindboggling?

Discussion in 'Asset Importing & Exporting' started by reset, Jun 15, 2010.

  1. reset

    reset

    Joined:
    May 22, 2009
    Posts:
    393
    hi

    if I import my level geometry from sketchup into blender and add some lights, is it really easy to create lightmaps for unity?

    i want it to be as easy as the lightup/sketchup to unity workflow - but i dont think it will be?

    i wish the external ligtmapping tool worked with blender :(
     
  2. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    I create lightmaps in Blender all the time, easy peasy. ;) Here's some tips:

    1. Make sure all your meshes are properly UV mapped and have textures assigned to them.

    2. If all you want is an Ambient Occlusion map, then just use Render > Bake Render Meshes > Ambient Occlusion. Be sure you've adjusted the AO settings first! I usually bump the samples up to 12 or higher for nice smooth AO.

    If you want a "full" light map, then you'll need to take some extra steps:

    3. Assign a pure white material to all the meshes in your scene.

    4. Make sure you set up your lights and shadow properties as desired.

    5. Then use Render > Bake Render Meshes > Full Render

    To use these textures in Unity I usually pull them into Gimp and make the white color transparent and save as a PSD or PNG.

    Works like a charm. :)

    I usually create 3 copies of my blender file, one just for light mapping, a second that I use for materials/texture baking and a third that I import into Unity that I use to adjust how many materials are imported / assigned.

    There are other ways of setting up for lightmaps by using multiple UV's. Although I've done it that way too, I find this method easier / faster.
     
  3. reset

    reset

    Joined:
    May 22, 2009
    Posts:
    393
    hi there

    thanks for your help - sounds easy!!! :)

    So I would bring my game level into Blender from Sketchup - this will have all the textures assigned etc.

    So how do I assign "a pure white material" to my level?

    Is this an extra material - in a layer - or something?
     
  4. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    I don't use Sketchup that much so I'm not too familiar with how it handles materials and UV maps. But I'm guessing you'd export from SU as a .OBJ and then import into Blender. If the materials import OK and you're happy with the UV maps then make a copy of the .blend (saving the original just in case) and change all the materials in the scene to white. Then create your lights, create a blank texture, assign it to your mesh and bake.

    The few times I have imported models from SU the UV maps weren't ready for baking so I created new ones. Fortunately, Blender has some very nice automatic UV mapping tools.
     
  5. reset

    reset

    Joined:
    May 22, 2009
    Posts:
    393
    ah ...

    this is most likely the messy bit I was worried about - the UV mapping. This where I need to unwrap all my meshes? Is this right??

    So if I have a highly detailed level designed in SU and bring it into Blender for lighting, I am going to have to create seams and unwrap everything??

    I think LightUp might be a much easier workflow for SU/Unity lightmaps.

    Or am I wrong :)
     
  6. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    I haven't tried LightUp so can't comment on that, but the -easiest- way to unwrap in Blender is to use its automatic UV mapping tool:

    1. Select an object
    2. Press TAB to enter edit mode
    3. Press U to get the Unwrap menu
    4. Select "Unwrap (Smart Projections)"
    5. Select "OK"
    6. Done :)

    You'll want to experiment with the "Island Margins" setting as well as the others to get the UV's set up so your textures won't have any stretching or borders. With some experimenting and practice the auto UV mapping tool gets fairly decent results. I use it for all the mundane objects in a scene and save the manual unwrapping for more important things that will be closer to the viewer.

    Sounds like you'd benefit from a Blender tutorial or two. Google "Blender 3D UV mapping" and I'm sure you'll find lots of tuts out there.

    Good luck and have fun!
     
  7. reset

    reset

    Joined:
    May 22, 2009
    Posts:
    393
    Hi thanks for your help

    so I bought my model into Blender from SketchUp - linked all the objects to their original textures/materials - then did the UnWrap (Smart Projections) on all the objects - I then actually saw my textures!! How come I cant see my textures until I do this process - my view is set to "Textured", under "Game" I have set it to "Blender GLSL Materials"

    Now do I create an "extra" material - is this right???

    Can I bring my model in and have all the textures applied - as they were in SketchUp - or do I need to reapply them - I brought my model in as a .dae.

    I promise people that once I figure all this out I am going to write the definite lightmapping tutorial for Blender to Unity!!!

    Blender is awesome and a tutorial need to be written.

    I cant find a great one anywhere that simplifies lightmapping. :(
     
  8. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    You lost me. All you should have to do to see your texture in Blender:

    1. Go to edit mode (TAB) and UV unwrap your model.
    2. While still in edit mode, make sure you have a texture window open and in that window open your texture.
    3. Then exit edit mode (TAB). You should see your texture applied to the model (as long as you have "Textured" selected for "Draw Type").

    .

    You imported the model into Blender using .dae? I haven't tried this, I usually use .obj. The Collada importer (and exporter) are pretty buggy, but the Wavefront (.obj) importer/exporter are pretty good.
     
  9. reset

    reset

    Joined:
    May 22, 2009
    Posts:
    393
    thanks for your reply.

    I have UV unwrapped my meshes - can see all my textures etc - this is all great - have a spot light - casting shadows.

    I am not sure how to bake this light and its shadows though. :(

    You mentioned creating a "white" material and a blank texture?

    Sorry but I am confused. :)
     
  10. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    Ok, here's a quick tutorial.

    Step 1 - In Edit Mode, select all your faces and select create a new material link
     

    Attached Files:

  11. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    Step 2 - Still in Edit Mode, change the material color to pure white.
     

    Attached Files:

  12. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    Step 3 - Still in Edit Mode, UV unwrap your mesh, select all the faces and in an image edit window, create a new texture.
     

    Attached Files:

  13. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    Step 3 continued - Set the texture dimensions and texture name.
     

    Attached Files:

  14. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    Step 4 - Return to Object Mode and bake render full your scene.
     

    Attached Files:

  15. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    Step 5 - Back to the image window and save your image to file. Done.

    As I said earlier, there are other ways to do this, but this is the way I do it.
     
  16. tbarbe

    tbarbe

    Joined:
    Dec 22, 2008
    Posts:
    154
    Hi

    Great quick tutorial for baking in Blender for Unity...

    Is there one up somewhere that shows this now in 2.5.3?
     
  17. Recluse

    Recluse

    Joined:
    May 16, 2010
    Posts:
    485
    I can't get this to work - no matter what. I can UV map my object with a texture in Blender and I can bake a lightmap in Blender. But after months of trial and error I cannot bake a lightmap onto a UV mapped object to produce a single texture that contains both the texture and the lightmap. Why is this so difficult? Why does the UV texture layer not show up when I bake a lightmap? This should be one-click simple really.
    I can do the texture mapping, I can do the lightmapping... Why can't I get both baked down to one texture? Any help clearing this up for me would be fantastic!
     
  18. Recluse

    Recluse

    Joined:
    May 16, 2010
    Posts:
    485
    I can get the lightmap to show on top of a UV textured object if I unwrap the object and use smart projections. However, unwrapping the object screws up my previous UV mapping, and also it makes UV editing problematic - if I unwrap (smart projections) and then rotate the UV layout or move some of the UV face co-ordinates this is not reflected in the render preview, which still shows the smart projection UV mapping... Why doesn't it update when I change some of the faces UV mapping? Damn, I suck at Blender.
     
  19. KnifeFightBob

    KnifeFightBob

    Joined:
    Jan 22, 2009
    Posts:
    196
    I'm sorry if I am offending anyone's preferences, but I personally find the new lightmapping with Beast so incredibly much easier and better that I simply can't see any reason to bake lightmaps manually anymore, if you're not on a pre-3.0 Unity that is. That may not be helpful, of course, but do try it if you can.
     
  20. Recluse

    Recluse

    Joined:
    May 16, 2010
    Posts:
    485
    I agree KnifeFightBob, but I'm finding using a lightmap + texture map for my level geometry slows things down on iPhone. I need a single texture which combines textures and shadows, hence my trials with Blender's rather obscure interface. Or is it possible to render a lightmap with Beast that includes the underlying object texture, allowing you to delete the original material?

    Anyway, I have finally cracked it in Blender today :))))

    I now have a level with a single texture, containing details like wall tiles etc and also lightmapped. One texture = one draw call. Makes a big difference on iPhone. If it's possible to do this using Beast, please put me straight. From my quick experiment with it, it seems to need a material with two textures to use Beast lightmaps in Unity?
     
  21. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    For reference, other people may find it just easier to set up a unity scene with lights, import the mesh, and bake the lightmaps. Then what you do is load the lightmap into gimp or photoshop, and overlay it over the original texture, voila baked texture+lm.

    Its probably quicker for a lot of people too.