I use Blender too now, but it’s still 2 weeks though.
At the first start, I was wondering how hard it could be to get a bunch of objects lightmapped by batch process as I used to do in Maya with MEL.
So I tried it and found it’s pretty simple and straightforward.
There are 3 scripts in the zip :
- Lightmap Setup
- Lightmap Image Saver
- UV Layer Switcher
NOTE : I put those scripts to Help menu, just to minimize the find & execute time.
Brief overview :
My Lightmap Setup script also works on object with multiple materials. It’s demonstrated by the cube and the cylinders.
Instanced (linked duplicates) objects are not processed at all, only unique meshes are processed.
Only 1 lightmap texture is assigned to each object. The texture can be independent per object or shared by some objects.
For more info, read each script’s docstring.
Detailed features of the Lightmap Setup script :
- creates new UV layer for lightmap, if it’s not already exist
- sets the lightmap UV to be active, ready for baking
- creates a material if the object doesn’t have one already
- duplicates material which is used by multiple objects, so each object can use its own
lightmap texture, if it’s using an originally shared material
- removes existing lightmap textures from texture slots
- creates a new texture (+ an image) to bake to, and insert it to the material
after the last found texture in the slots
- sets the lightmap texture’s mapping to use the lightmap UV instead of the original (ORCO)
- links the lightmap texture to the lightmap UV layer, so Chicken will write out
that UV layer’s name instead of the first layer
- turns on “tangent vector usage in shading calculation” (at Shaders panel) to get full shading
for shadow baking, otherwise some areas of faces which is facing away from the light
wouldn’t be filled with shadow color.
- turns on “auto smooth during rendering” (at Mesh panel) and sets the max angle to minimum
to fully prevent artifacts, if user wants to bake shadow
- turns off “auto smooth during rendering” (at Mesh panel) and restores the max angle,
if user wants to bake AO
- runs Blender’s smart-projections UV unwrap script
Lightmapping steps using my scripts :
 select objects (it will be filtered to process Mesh only objects)
 run Lightmap Setup script
 fine tune the generated UV, in case any overlapping UV faces
Once the desired objects are processed, save the result :
 run Lightmap Image Saver script
 save your .blend file
You should run step 1-3 for small, medium, large, and extra large objects separately,
just to use optimum texture size for different sized objects.
I don’t use “Lightmap UVPack” UV unwrap module because :
- it can’t process selected objects, it only processes the active object only,
or all objects, including camera, lights, and everything else in the scene
- it’s harder to get good proportion quality
- it’s impossible to post-process the image (eg. blur) since the faces are
scattered all over
I use the “Smart Projections” instead.
The Lightmap Setup script turns on 2 flags :
- tangent vector usage for shading (at Shaders panel)
This flag is NOT good for normal rendering in Blender, but it’s the only way to get
correct shadow baking calculation. It doesn’t affect AO baking.
- auto smooth during rendering (at Mesh panel)
This is only good to fully remove artifacts in shadow baking,
but BAD for AO baking and normal rendering.
Note that those are my first Blender scripts, so I might miss something obvious, like this one :
I couldn’t get smooth shading when baking shadow, no matter what I did.
Any input, criticism, offensive feature objection, and better implementation are welcome.