[25.jun.2015 updated to version 0.9. Added an ambient occlusion mapper, map images can now be resized, reworked the “dynamic with colors” option for the lightmap]

I made a plugin to generate static lightmaps. After lots of experiments I found out that It kinda works and I plan to use it in my current game project. Someone else might find it useful so I’m posting it here. (5.4kb)

Describing what it does is actually more complicated than what it actually does. Basically, it does (a lot less of) what TextureAtlas does then some. It takes all the selected objects (or all the meshes in the current layer if no object is selected), creates an uvlayer dedicated to the lightmap (if it doesn’t exists), it bakes the scene, assigns the image to a texture (if it has not already been created) then adds that texture to the materials of the selected objects (if it has not already been added).
It also changes the “emit” value of the materials (if the emit field in the Lightmapper panel is not -1), because (but I might be wrong here), unless you use nodes, if you want the lightmap to work decently with dynamic lights there must be some sort of overall ambient lighting.

In all this, the workflow is as follows:

create the scene with all the objects you want, adds all the lights you like, add the diffuse textures or multimaterials… whatever, as usual. Then you press the button and voilà, you should have your static lightmap built and applied. The lightmap image must then be saved somewhere manually if you want to actually keep it.
Once the map has been generated, it will be overwritten by subsequent calls of the operator, so one can make adjustments.

I actually didn’t tested it but it should be possible to create more than one lightmap in a scene, you just use a different name in the lightmapper “name” field and possibly select a different subset of objects before to press the button.
I’ve used it on large maps with lots of stuff and lights and it seems to work well.

I think there are no more bugs but never say never. I’m 99.9% positive that it shouldn’t work with objects that uses nodes for their materials.

Latest test video:

1 Like

wow so it basicly bake the map and apply it to the UV setting right away! you did a great work there!

In theory the only thing that one has to do is to press the button. And save the image if the result is ok. The plugin does everything from the uv layer creation to the association of the lightmap texture and, of course, the actual baking of the lightmap. I say in theory because despite having tested it on a lot of scenes, my maps are usually quite simple in therms of texturing techniques (for example I never tested it with a scene that uses custom glsl shaders, it may somehow alter the preconditions of the shader).

The code itself is really nothing more than a trivial combination of functions already available through the blender-python api.

Very very nice work!

Now this + a dynamic lighting manager + dynamic libLoad/libFree +Lod+instanced geometry

and we are in business for amazingly detailed massive worlds, without insane level of entry for a developer.

Thks pgi,

I would use it thinking to you and all your work.
Very useful also in me.

As usual, great and usefull plugin! Thanks!

I have updated the script to fix a bug (when an existing texture slot had no texture attached a npe was thrown).

Another bugfix. I was skipping non traceable objects but that caused a circular reference during baking. I’ve also added a button that removes a lightmap from the texture slots of all objects.

This is nice! A lot of people will be appreciative of this.
(I gave you a little flak in another thread about this, but this is actually pretty cool)

If I have spare time, I may try making some scenery using this. If anything, it would be nice to have some good screen shots here to show off the results.

Nice work :cool:

I have updated the plugin to version 0.8. Now there’s an option box to choose the output.

Lightmap only: creates the lightmap image but doesn’t apply it
Dynamic No colors: creates the lightmap and applies it setting it so that it can be combined with dynamic lights. The colors of the baked lights are lost (I haven’t find a setup that preserves it decently)
Dynamic Colored*: an half failed setup that tries to also have baked light colors but one has to play with the energy factor (increasing it) of the colored lights to actually see some result.
Static: creates and applies the lightmap, the texture setup doesn’t play well with dynamic lights, one can set the environment to shadeless or use the emit factor to see the effect. It renders the light colors nicely.

I should probably use nodes to have a proper lightmap that render colors and plays well with additional lights but I haven’t figured out yet the correct setup and how to add the lightmap nodes to the existing material in a way that can also be removed, switching back to the original appearance of the scene.

Thanks pgi,
Always a lot of job for you.
Good Luck.

This looks interesting. Any chance that you’ll include an AO-option in further updates?

When BGE may include real time GI like Unity and UE4 does? I know it is complicated thing, but still should be possible.

x deempa89.

Adding an AO map option is a piece of cake. The only problem is figuring out how to present the option in a way that gracefully coexists with the shadow map but that is just a ui design problem.I’ll find out a way and add that to the next update.

x adriansnetlis

I’m not a blender developer so I can only speculate but common sense tells me that the problem here is not how complicate something is but how many hands and eyes are available. If 100 software engineers would suddenly volunteer to work on BGE we could have BlendSys or UnreaEnder in a few months. I don’t see that happening any time soon. But I’ll try to wish for it very hard :smiley:

I just began learning to develop BGE, but such begginer as me can’t make it have PBR, real time GI, easy to use assets manager and other things like that:D

Mhhh… question: is it normal for a baked ambient occlusion map to look like garbage?

And while we’re at it, what are the correct parameters to set for an ambient occlusion texture? Add & Diffuse color 1? Multiply, mix, softlight? The image is taken with a chaotic “diffuse color 1, mix, rgb to intensity (color black), negative”.

Hey PGI, thank you again for this plugin.

any chance at a dymamic lighting manager that deletes all the lamps, and adds back x lights that populate where the deleted lights were?

x blueprintrandom

I tried a light manager for a (never finished) game and things turned out to be not so easy. The problem is not positioning and moving a predefined set of lights, based on the distance from the active camera, but supporting the scripts that the user might want to add to the light object.
When I think about a scene with many dynamic lights I imagine a light that turns on only when a door opens or a light that switches on and off to signal an emergency, the light of a missile that gets deleted when the missile explodes.
So you have to think about redirecting all this stuff and possibly trapping the delete calls, otherwise you’ll have users saying “hey, I tried this plugin and guess what, everything broke up after five minutes of gameplay. I really hope the writer misses a step walking downstairs”. That’s not nice :D.

what about a flag? managed?
(so you only manage lights flagged for it?)

I use multiply for AO maps. I don’t know if it works, but switching to approximate lighting in internal for baking may fix noise. But it still won’t work in BGE.