Search Unity

  1. Unity 2019.1 beta is now available.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We're looking for insight from anyone who has experience with game testing to help us better Unity. Take our survey here. If chosen to participate you'll be entered into a sweepstake to win an Amazon gift card.
    Dismiss Notice
  4. On February 28th the Feedback website will shut down and be redirected to the Unity forums. See the full post for more information.
    Dismiss Notice
  5. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  6. Unity 2018.3 is now released.
    Dismiss Notice
  7. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Lightmaps similar to Penelope and the iPhone FPS Tutorial

Discussion in 'External Tools' started by prime31, Dec 21, 2009.

  1. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,427
    This was posted previously but for some reason it was locked so I am reposting.

    I was curious if anyone knows how the lightmaps for Penelope and the FPS tutorial were created? Is it possible to emulate the method in Blender?

    I am looking for a way to have multiple objects in a scene each with it's own diffuse texture and then have just one lightmap texture shared for all the objects just like in those tutorials. Does anyone have any pointers? Days of Google and forum searching have not come up with a solution yet...
     
  2. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,427
    After a lot of playing around in Blender this weekend I came up with a partial solution that works pretty well. The problem with it is that for some reason I only get one shot at baking. If I go back in and tweak the lights, etc and rebake I get a black texture every time. Below are the steps I am using. Does anyone have a better way to do this or am I on the right track?


    Code (csharp):
    1. General Setup
    2. - In the 'World' panel, find the 'Amb Occ' panel and click the Ambient Occlusion button
    3. - Set the type to 'Approximate'
    4.  
    5.  
    6. Blender Modelling
    7. - Setup your scene and texture all objects
    8. - Reset all the Scale and Rotation your objects (Select object in 'Object Mode' and press Ctrl-A)
    9. - Set the material color to white in preparation to receive the lightmap ('Shading', 'Material Buttons' then in 'Material' panel set the 'Col' to white
    10. - Turn off all textures ('Shading', 'Material Buttons' then in 'Texture' panel uncheck the texture).  This is necessary so we can do a Full Render on a blank canvas
    11. - Backup your blend file at this point just in case
    12. - Select all the objects that you want to be in the lightmap
    13. - Press 'Tab' to enter Edit mode
    14. - Press 'U' then choose 'Lightmap UV Pack' with the following settings:
    15.     * Deselect 'Active Object' and 'Selected Faces'
    16.     * Select 'Share Tex Space', 'New UV Layer' and 'New Image'
    17.     * Set an appropriate image size (256 should be fine for iPhone)
    18.     * Set the margin value to 0.2
    19.  
    20.  
    21.  
    22. - Open the 'Scene' panel then the 'Render' panel
    23. - Locate the 'Bake' panel and choose 'Full Render' as the bake type (Note: if you are not using any tiled textures or the textures you are using will only be in this scene you can turn your textures back on and bake the shadows right on the texture so that all the objects in your scene will use the same, single material)
    24. - Click the 'Bake' button to create the shadow map
    25. - For each of your objects do the following:
    26.     * Add a new image texture ('Shading' button then 'Texture' button then find the 'Texture' panel)
    27.     * Set the image as the lightmap that you just created
    28.     * Under the 'Shading' button then the 'Material' button find the 'Map Input' panel and for both textures choose 'UV'
    29.     * In the same section, find the 'Map To' panel and set the second (lightmap) texture to 'Multiply' in the drop down
    30. - Be sure to save your lightmap image to your Materials folder in the UV/Image Editor window under the 'Image' section
    31. - To get a preview of how the scene will look in the 'Game' menu choose 'Blender GLSL Materials'.  If you deleted your light you will need to also change all your materials to 'Shadeless' in the 'Shading' then 'Material Buttons' 'Material panel.
    32.  
    33.  
    34. Unity Import
    35. - Drag and drop your blend file and Materials folder into Unity
    36. - For each material you will need to give it a shader that supports a lightmap then choose the lightmap image
    37. - Add your newly created object to your scene and you should have your lightmap in place
    38.  
     
  3. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,427
    While I'm answering my own questions I might as well post a bit more info in case anyone else finds this thread. Below is a little Python script that will help with the process of enabling/disabling texture channels. If you run this script, you can choose which channel to enable/disable then just press the 'Set Channel' button and voila. This makes setting up the lightmap much quicker.

    EDIT: script has been updated

    Code (csharp):
    1. #!BPY
    2.  
    3. # Install the script in the 'Object' menu
    4. """
    5. Name: 'Turn off/on all diffuse textures'
    6. Blender: 249
    7. Group: 'Object'
    8. Tooltip: 'Sets all diffuse textures for the selected objects off/on for lightmap baking'
    9. """
    10.  
    11. """
    12. Helper for creating lightmaps.
    13.  
    14. Diffuse: toggles the diffuse (first) texture channel
    15. Lightmap: toggles the lightmap (second) texture channel
    16. Set Material to White: sets all materials to white in preparation for receiving the baked lightmap
    17. """
    18.  
    19. import os
    20. import sys
    21. import struct
    22. import math
    23. import string
    24. import Blender
    25. import platform
    26. import shutil
    27. import syslog
    28.  
    29. from Blender                    import Material
    30. from Blender                    import Texture
    31. from Blender                    import Window
    32. from Blender                    import Object
    33. from Blender                    import NMesh
    34. from Blender                    import Mathutils
    35. from Blender.Scene              import Render
    36. from Blender.Draw               import *
    37. from Blender.BGL                import *
    38. from Blender.Window             import *
    39. from Blender.Mathutils          import *
    40.  
    41. # GUI variables
    42. EVENT_EXIT                      = 0
    43. EVENT_TOGGLE_DIFFUSE            = 1
    44. EVENT_TOGGLE_LIGHTMAP           = 2
    45. EVENT_TOGGLE_MATERIAL_TO_WHITE  = 3
    46. EVENT_SET_CHANNELS              = 4
    47.  
    48. DIFFUSE_ON              = 0
    49. LIGHTMAP_ON             = 0
    50. MATERIAL_TO_WHITE       = 1
    51.  
    52.  
    53. def log( t ):
    54.     syslog.syslog( syslog.LOG_ALERT, t )
    55.  
    56.  
    57. #========================================
    58. # DRAW RECTANGLE
    59. #========================================
    60. def draw_rectangle( x, y, w, h, r, g, b, a ):
    61.  
    62.     glEnable( GL_BLEND )
    63.     glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA )
    64.  
    65.     glColor4f( r,g,b,a )
    66.  
    67.     glBegin( GL_POLYGON )
    68.  
    69.     glVertex2i( x    , y     )
    70.     glVertex2i( x    , y + h )
    71.     glVertex2i( x + w, y + h )
    72.     glVertex2i( x + w, y     )
    73.  
    74.     glEnd()
    75.  
    76.     glDisable( GL_BLEND )
    77.  
    78.  
    79. #=========================================
    80. # RENDER THE EXPORTER GUI
    81. #=========================================
    82. def drawGui():
    83.  
    84.     glClearColor( 0.74, 0.74, 0.74, 0.0 )
    85.     glClear( GL_COLOR_BUFFER_BIT )
    86.  
    87.     draw_rectangle( 5, 125, 400, 20, 0.6, 0.6, 0.6, 1.0 )
    88.  
    89.     glColor3f( 1.0, 1.0, 1.0 )
    90.     glRasterPos2i( 15, 132 )
    91.  
    92.     Text( "Selected Object Texture Channel Toggler" )
    93.  
    94.     glPolygonMode( GL_FRONT_AND_BACK, GL_LINE )
    95.     draw_rectangle( 5, 7, 399, 138, 0.5, 0.5, 0.5, 1.0 )
    96.     draw_rectangle( 5, 7, 399, 138, 0.5, 0.5, 0.5, 1.0 )   
    97.     glPolygonMode( GL_FRONT_AND_BACK, GL_FILL )
    98.  
    99.     glColor3f( 0.0, 0.0, 0.0)
    100.     glRasterPos2i( 15, 100 )
    101.     Text( "Select the texture channels you want to enable." )
    102.     glRasterPos2i( 15, 85 )
    103.     Text( "This operation will only effect selected objects." )
    104.  
    105.     Toggle( "Diffuse", EVENT_TOGGLE_DIFFUSE, 15, 50, 45, 20, DIFFUSE_ON, "Toggle diffuse channel texture (channel 1)" )
    106.     Toggle( "Lightmap", EVENT_TOGGLE_LIGHTMAP, 65, 50, 55, 20, LIGHTMAP_ON, "Toggle lightmap channel texture (channel 2)" )
    107.     Toggle( "Set Material to White", EVENT_TOGGLE_MATERIAL_TO_WHITE, 125, 50, 135, 20, MATERIAL_TO_WHITE, "Set the material color to white" )
    108.    
    109.     Button( "Set Channels", EVENT_SET_CHANNELS, 185, 16, 100, 20 )
    110.     Button( "Exit", EVENT_EXIT, 295, 16, 100, 20 )
    111.  
    112.  
    113. #====================================
    114. # GUI EVENTS CALLBACKS
    115. #====================================
    116. def eventGui( event ):
    117.     global DIFFUSE_ON
    118.     global LIGHTMAP_ON
    119.     global MATERIAL_TO_WHITE
    120.  
    121.     if( event == EVENT_EXIT ):
    122.         Exit()
    123.        
    124.     if( event == EVENT_SET_CHANNELS ):
    125.         flipTextures()
    126.        
    127.     if( event == EVENT_TOGGLE_DIFFUSE ):
    128.         DIFFUSE_ON = not DIFFUSE_ON
    129.        
    130.     if( event == EVENT_TOGGLE_LIGHTMAP ):
    131.         LIGHTMAP_ON = not LIGHTMAP_ON
    132.    
    133.     if( event == EVENT_TOGGLE_MATERIAL_TO_WHITE ):
    134.         MATERIAL_TO_WHITE = not MATERIAL_TO_WHITE
    135.  
    136.  
    137. #====================================
    138. # SETS THE PROPER TEXTURES AS ACTIVE SELECTED FROM THE GUI
    139. #====================================
    140. def flipTextures():
    141.     global DIFFUSE_ON
    142.     global LIGHTMAP_ON
    143.     global MATERIAL_TO_WHITE
    144.    
    145.     # Grab the selected objects
    146.     scn = Blender.Scene.GetCurrent()
    147.    
    148.     log( "---------- Starting texture channel flipper -------------" )
    149.    
    150.     # Loop through our selected objects
    151.     for obj in scn.objects:
    152.        
    153.         # Make sure the object is on the first layer, it is a Mesh and it is selected
    154.         if( obj.getType() == "Mesh" and obj.layers[0] == 1 and obj.isSelected() ):
    155.            
    156.             # Grab the mesh data
    157.             mesh = obj.getData( False, True )
    158.            
    159.             # Make sure we have a material before proceeding
    160.             if( len( mesh.materials ) ):
    161.                
    162.                 # Loop through all materials
    163.                 for mat in mesh.materials:
    164.                     if( mat == None ):
    165.                         continue
    166.                    
    167.                     # Flip the color to white if necessary
    168.                     if( MATERIAL_TO_WHITE ):   
    169.                         mat.setRGBCol( 1, 1, 1 )
    170.    
    171.                     # Grab the textures
    172.                     texChannels = mat.getTextures()
    173.                    
    174.                     availableTextures = []
    175.                     newEnabledTextures = []
    176.                    
    177.                     for i in range( 0, 2 ):
    178.                         if( texChannels[i] != None and texChannels[i].tex.type == Texture.Types.IMAGE ):
    179.                             availableTextures.append( i )
    180.                    
    181.                     # Enable/disable based on the chosen settings and if we have the texture channel available
    182.                     if( DIFFUSE_ON and 0 in availableTextures ):
    183.                         newEnabledTextures.append( 0 )
    184.                    
    185.                     if( LIGHTMAP_ON and 1 in availableTextures ):
    186.                         newEnabledTextures.append( 1 )
    187.                    
    188.                     mat.enabledTextures = newEnabledTextures
    189.                     Exit()
    190.  
    191.  
    192. #====================================
    193. # MAIN
    194. #====================================
    195. # Prep logging
    196. syslog.openlog("Blender")
    197.  
    198. # run script
    199. Register( drawGui, None, eventGui )
    200.  
    201.  
     
  4. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,325
    Moving to External Tools so people can find this better. Thanks for sharing your process ;)
     
  5. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,427
    Continuing on learning Blender and Unity here is another useful Blender script (I also updated the first one to have a new option for setting the color to white of the material). This script will do the following to the selected objects:
    - Create a second texture (if there isn't already one) and name it 'Lightmap'
    - Sets the second textures image to one named 'lightmap' if it exists
    - Set both the first and second texture's Map Input to UV
    - Set the second textures blend mode to Multiply

    This should greatly speed up the previous lightmap creation steps when there are a lot of objects to deal with.

    Code (csharp):
    1. #!BPY
    2.  
    3. # Install the script in the 'Object' menu
    4. """
    5. Name: 'Lightmap Texture Helper'
    6. Blender: 249
    7. Group: 'Object'
    8. Tooltip: 'Creates textures, sets blend mode and maps textures to UVs'
    9. """
    10.  
    11. """
    12. Helper for creating lightmaps.
    13.  
    14. Create Texture:
    15.     - creates a new texture in the second channel of each selected object with a name of 'Lightmap'
    16.     - if "Set Image" is on, when creating the texture if there is one named 'lightmap' it will be used
    17. Map Input to UV:
    18.     - sets the mapping ('Shading' -> 'Material Buttons' -> 'Map Input' panel) to UV
    19.     - sets the 'Map To' to 'Multiply' for the Lightmap (second texture) channel
    20. """
    21.  
    22. import os
    23. import sys
    24. import struct
    25. import math
    26. import string
    27. import Blender
    28. import platform
    29. import shutil
    30. import syslog
    31.  
    32. from Blender                    import Material
    33. from Blender                    import Texture
    34. from Blender                    import Image
    35. from Blender                    import Window
    36. from Blender                    import Object
    37. from Blender                    import NMesh
    38. from Blender                    import Mathutils
    39. from Blender.Scene              import Render
    40. from Blender.Draw               import *
    41. from Blender.BGL                import *
    42. from Blender.Window             import *
    43. from Blender.Mathutils          import *
    44.  
    45. # GUI variables
    46. EVENT_EXIT                  = 0
    47. EVENT_CREATE_TEXTURE        = 1
    48. EVENT_MAPTO_UV              = 2
    49. EVENT_TOGGLE_SET_IMAGE      = 3
    50.  
    51. SET_IMAGE_ON = 1
    52.  
    53. def log( t ):
    54.     syslog.syslog( syslog.LOG_ALERT, t )
    55.  
    56.  
    57. #========================================
    58. # DRAW RECTANGLE
    59. #========================================
    60. def draw_rectangle( x, y, w, h, r, g, b, a ):
    61.  
    62.     glEnable( GL_BLEND )
    63.     glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA )
    64.  
    65.     glColor4f( r,g,b,a )
    66.  
    67.     glBegin( GL_POLYGON )
    68.  
    69.     glVertex2i( x    , y     )
    70.     glVertex2i( x    , y + h )
    71.     glVertex2i( x + w, y + h )
    72.     glVertex2i( x + w, y     )
    73.  
    74.     glEnd()
    75.  
    76.     glDisable( GL_BLEND )
    77.  
    78.  
    79. #=========================================
    80. # RENDER THE EXPORTER GUI
    81. #=========================================
    82. def drawGui():
    83.  
    84.     glClearColor( 0.74, 0.74, 0.74, 0.0 )
    85.     glClear( GL_COLOR_BUFFER_BIT )
    86.  
    87.     draw_rectangle( 5, 92, 450,  20, 0.6, 0.6, 0.6, 1.0 )
    88.     draw_rectangle( 5,  6, 450,  86, 0.8, 0.8, 0.8, 1.0 )
    89.  
    90.     glColor3f( 1.0, 1.0, 1.0 )
    91.     glRasterPos2i( 15, 98 )
    92.  
    93.     Text( "Lightmap Texture Helpers" )
    94.  
    95.     glPolygonMode( GL_FRONT_AND_BACK, GL_LINE )
    96.     draw_rectangle( 5,  7, 450, 106, 0.5, 0.5, 0.5, 1.0 )
    97.     draw_rectangle( 5,  7, 450,  86, 0.5, 0.5, 0.5, 1.0 )  
    98.     glPolygonMode( GL_FRONT_AND_BACK, GL_FILL )
    99.  
    100.     glColor3f( 0.0, 0.0, 0.0)
    101.     glRasterPos2i( 15, 72 )
    102.     Text( "Create Texture: creates a new texture in channel 2 with the name 'Lightmap'" )
    103.     glRasterPos2i( 15, 52 )
    104.     Text( "Map Input UV: sets all textures to Map Input UV and sets 'Lightmap' to Multiply" )
    105.  
    106.     Button( "Create Texture", EVENT_CREATE_TEXTURE, 15, 16, 95, 20 )
    107.     Button( "Map Input to UV", EVENT_MAPTO_UV, 115, 16, 100, 20 )
    108.     Toggle( "Set Image", EVENT_TOGGLE_SET_IMAGE, 235, 16, 75, 20, SET_IMAGE_ON, "Toggle lightmap channel texture (channel 2)" )
    109.     Button( "Exit", EVENT_EXIT, 370, 16, 75, 20 )
    110.  
    111. #====================================
    112. # GUI EVENTS CALLBACKS
    113. #====================================
    114. def eventGui( event ):
    115.     global SET_IMAGE_ON
    116.  
    117.     if( event == EVENT_EXIT ):
    118.         Exit()
    119.        
    120.     if( event == EVENT_CREATE_TEXTURE ):
    121.         createLightmapTexture()
    122.        
    123.     if( event == EVENT_MAPTO_UV ):
    124.         setMapToUVs()
    125.    
    126.     if( event == EVENT_TOGGLE_SET_IMAGE ):
    127.         SET_IMAGE_ON = not SET_IMAGE_ON
    128.  
    129.  
    130. #====================================
    131. # CREATES THE LIGHTMAP TEXTURE
    132. #====================================
    133. def createLightmapTexture():
    134.     global SET_IMAGE_ON
    135.    
    136.     # Grab our selected meshes
    137.     meshes = getSelectedMeshesOnFirstLayer()
    138.    
    139.     # Loop through all meshes
    140.     for mesh in meshes:
    141.         for mat in mesh.materials:
    142.             if( mat == None ):
    143.                 continue
    144.  
    145.             # Grab the textures
    146.             texChannels = mat.getTextures()
    147.            
    148.             # Only add the image if the channel is empty
    149.             if( texChannels[1] == None ):
    150.                 newTexture = Texture.New( 'Lightmap' )
    151.                 newTexture.setType( 'Image' )
    152.                
    153.                 # Attempt to set the image to one named 'lightmap' exists
    154.                 if( SET_IMAGE_ON ):
    155.                     try:
    156.                         images = Blender.Image.Get()
    157.                         for img in images:
    158.                             if( img.name.lower().startswith( "lightmap." ) ):
    159.                                 newTexture.image = img
    160.                                 break
    161.                     except:
    162.                         log( "Failed to find an image named 'lightmap'" )
    163.                
    164.                 # Set the materials second texture to be newTexture
    165.                 mat.setTexture( 1, newTexture )
    166.             else:
    167.                 # Note in the console that we will not be creating a new texture for this one
    168.                 log( "[%s]: Texture channel is not empty so not creating texture" % mesh.name )
    169.  
    170.  
    171. #====================================
    172. # SETS THE MAP_INPUT TO UV AND MAP_TO TO MULTIPLY FOR THE LIGHTMAP
    173. #====================================
    174. def setMapToUVs():
    175.     # Grab our selected meshes
    176.     meshes = getSelectedMeshesOnFirstLayer()
    177.    
    178.     # Loop through all meshes
    179.     for mesh in meshes:
    180.         for mat in mesh.materials:
    181.             if( mat == None ):
    182.                 continue
    183.  
    184.             # Grab the textures
    185.             texChannels = mat.getTextures()
    186.            
    187.             # Always check for empty before proceeding
    188.             if( texChannels[0] != None ):
    189.                 # Set MapInput to UV
    190.                 texChannels[0].texco = Texture.TexCo.UV
    191.            
    192.             if( texChannels[1] != None ):
    193.                 # Set MapInput to UV
    194.                 texChannels[1].texco = Texture.TexCo.UV
    195.                
    196.                 # Set MapTo to Multiply
    197.                 texChannels[1].blendmode = Texture.BlendModes.MULTIPLY
    198.  
    199.  
    200. #====================================
    201. # GRABS ALL THE SELECTED TEXTURES THAT HAVE AT LEAST ONE MATERIAL
    202. #====================================
    203. def getSelectedMeshesOnFirstLayer():
    204.     outMeshes = []
    205.    
    206.     # Grab all objects in the scene then filter them
    207.     scn = Blender.Scene.GetCurrent()
    208.    
    209.     # Loop through our selected objects
    210.     for obj in scn.objects:
    211.        
    212.         # Make sure the object is on the first layer, it is a Mesh and it is selected
    213.         if( obj.getType() == "Mesh" and obj.layers[0] == 1 and obj.isSelected() ):
    214.            
    215.             # Grab the mesh data
    216.             mesh = obj.getData( False, True )
    217.            
    218.             # Make sure we have a material before adding this object
    219.             if( len( mesh.materials ) ):
    220.                 outMeshes.append( mesh )
    221.        
    222.     return outMeshes
    223.  
    224.  
    225. #====================================
    226. # MAIN
    227. #====================================
    228. # Prep logging
    229. syslog.openlog("Blender")
    230.  
    231. # run script
    232. Register( drawGui, None, eventGui )
    233.  
     
  6. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,671
    uprise78:

    I just wanted to say thanks for this research...

    I've just started my journey into Lightmapping in Blender for the iPhone - and this thread is the top hit.

    I'll be making my way slowly down this path. I'll let you know anything I find out, but please do let us know if you learn anything more!

    ^_^
     
  7. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,427
    Little Angel, I have this down to a science now. I have refined the process to the bare minimum and a lot of the steps from this thread aren't needed. If you want the new list of steps to get a lightmap going just PM me or respond on this thread and I'll post them when I get home.
     
  8. GusM

    GusM

    Joined:
    Aug 27, 2005
    Posts:
    585
    Yes, please, I would also be interested.
     
  9. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,671
    uprise78:

    Please,

    If you could, let me know your revised pipeline. I'll hold off experimenting with what you've posted here so far, if you have a revised plan.

    LA
     
  10. bpatters

    bpatters

    Joined:
    Oct 5, 2009
    Posts:
    164
    I'm interested also. I'm using vertex lighting right now but will eventually want to expand to lightmaps for some of my lighting needs.
     
  11. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,671
    Thinking about this...

    I assume that you need to completely assemble and place your scene in Blender to get the accurate light map you need, no? Therefore, no creating discreet assets and importing them into Unity for placement...
     
  12. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,427
    The lightmap will require all objects to be in their final locations in Blender. You can swap textures and materials in Unity but your objects size and position will need to be final.
     
  13. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,427
    The updated instructions go something like this:

    Code (csharp):
    1. General Setup
    2. - In the 'World' panel, find the 'Amb Occ' panel and click the Ambient Occlusion button
    3. - Set the type to 'Approximate'
    4. - Setup appropriate ambient light in the 'Shading' -> 'World' panel (You can adjust and rebake later to get the desired ambient lighting)
    5.  
    6. Blender Modelling
    7. - Setup your scene and texture all objects
    8. - Reset all the Scale and Rotation your objects (Select object in 'Object Mode' and press Ctrl-A)
    9.  
    10. - Select all the objects that will be getting a lightmap
    11. - Press 'Tab' to enter Edit mode
    12. - Press 'U' then choose 'Lightmap UV Pack' with the following settings:
    13.    * Deselect 'Active Object' and 'Selected Faces'
    14.    * Select 'Share Tex Space', 'New UV Layer' and 'New Image'
    15.    * Set an appropriate image size (256 should be fine for iPhone)
    16.    * Set the margin value to 0.2
    17.  
    18. - Open the 'Scene' panel then the 'Render Buttons' panel
    19. - Locate the 'Bake' panel ('Scene' then 'Render buttons') and choose 'Full Render' as the bake type
    20. - Click the 'Bake' button to create the shadow map
    21.  
    22. - Be sure to save your lightmap image to your Textures folder in the UV/Image Editor window under the 'Image' section
    23. - Before saving be sure to set the 'active' and 'rendering' UV Texture ('Editing' buttons 'Mesh' panel) to the UVTex (or first non-lightmap UV Texture)
    24.  
    25. Unity Import
    26. - Drag and drop your blend file and Materials folder into Unity
    27. - For each material you will need to give it a shader that supports a lightmap then choose the lightmap image
    28. - Add your newly created object to your scene and you should have your lightmap in place
     
  14. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,671
    That's what I assumed. I think I was hoping that you might have discovered some pipeline for setting up scene in Unity, passing it to Blender for the light mapping and then returning it back to Unity once it was mapped. But, as I thought, it was wishful thinking.

    I'll try to give this a try on Monday, and thank you very much for posting this!
     
  15. afecelis

    afecelis

    Joined:
    Jul 3, 2009
    Posts:
    3
    Thanks a lot Uprise. This is extremely useful :D