Lightmap Your World

Information and tutorial


The purpose of the Lightmap application is to easily generate lightmaps for any 3D world.

This tutorial will walk you through the steps needed in order to generate nice lightmaps for your 3D world.


What are Lightmaps ?

Lightmapping is a technique that improves the visual quality of 3D worlds dramatically.

Here are some simple examples of before and after:

Screen shots

Here is a simple room built from 6 polygons each in a different color.

Screenshot 1



Now here is the same room after we added lightmaps.


Screenshot 2



Here is another example:  We dragged and dropped a few 3D models (first picture). Then we used the lightmap application to add lightmaps.

Screenshot 3


Screenshot 4



Another example (after adding Lightmaps)

Screenshot 5



How are lightmaps implemented ?

Every polygon in our 3D world could have an additional bitmap that includes its lighting information. The lighting information is calculated according to the light sources defined for the specific world. Each light source could have a different color and strength as well as other properties.

When the 3D engine renders the 3D world it merges the polygon color/bitmap with the polygon lightmap bitmap.

So actually this application automatically generates an additional bitmap for each polygon containing its lighting information. If we have 100 thousand polygons in our world and we generate lightmaps for all of them then we will generate 100 thousand additional bitmaps ! That’s a lot of bitmaps. The good news is that usually these bitmaps are very small so that 100 thousand lightmaps could be grouped into around 5 large 1024x1024 bitmaps. These bitmaps will contain the lighting information of the entire world !




Generating lightmaps

To generate lightmaps, all we need is to make 3 simple steps:

1) Load a  3D world

There are many free 3D worlds on the internet. Since the Lightmaps application currently accepts only 3DSTATE file formats, you can use the 3DS to 3DSTATE converter.

You can also use 3DSTATE Worldbuilder or 3D Editor to create your own worlds.

2) Define light sources.

Once we load our world into the Lightmaps application, we can then define the location of the light sources.

3) Generate the lightmaps


In this tutorial we will do a step by step walk through.


Step 1- Open a 3D World

1.1) Run the Lightmap Your World application

1.2) Click on the Open icon (at the top right corner)

1.3) go to the Sample Worlds and open the world1.3dstate file. It should look like the image in step 2

Moving inside the3D  world

Before we continue it is important that you know how to move inside the 3D world

·         Use the arrow keys to move forward and backwards and to turn left/right

·         Use the keys H and N to go up and down

·         Use A,Z to tilt the view up or down. Use the Q key to look straight.

Important ! you can always get back to the starting position by pressing on the “Jump to start” bottom at the bottom of the application window

If you are lost in space and you don’t find your world, press “Jump to start” then press the Q key to straighten the viewing direction then if you still can’t see anything, it means your world is behind you so turn left or right till you see it.

Notice also the following options at the bottom of the application window:

·         The Ghost checkbox (at the bottom) is checked, you can fly through walls and objects.

·         You can change the speed of movement

·         You can freeze the 3D screen so it doesn’t move when you use the arrow keys or the A,Z,H,N keys (for example if the application is opened and you write an email …)


Try moving inside your 3D world before continuing.



Step 2 – Select the parts of the world to get Lightmaps

Rounded Rectangular Callout: Here we have a tree defining the groups of polygons we have in our world. Houses, cars, trees etc.
Click on the checkbox to select all.

In our example we will create Lightmaps for all the polygons in our 3D world.  So simply click on the checkbox to select all as shown in the drawing above.

Note that to select parts of the world which need to be lightmaped you can select from the group tree or simply click on the 3D image. To select a single polygon, hold the shift key down while clicking the 3D image.

You can now skip to step 3 or continue to read some more

It is important to remember that you can create lightmaps for selected parts of the world. The size of the lightmap built for each polygon is according to the polygon size. So if we have a 3D world containing for example a huge terrain and a few buildings on the terrain, we would probably want the shadows details for the buildings to be very accurate.
But if we simply create lightmaps for the entire world, the terrain would receive the big portion of our lightmap budget and little would be lift for the buildings. In this case we should do the lightmap for the terrain separately (or use regular lighting for the terrain). This way we can make sure that the parts in our world that need to look good, will have big enough lightmaps associated with.


This is how it should look now:




Step 3 – defining light source for the world

3.1) click on the “light source” tab, the “light sources”  tabs will appear
In the first tab you can create/delete/disable light sources. You can create as many as you need.

The only disadvantage of creating many light sources is that the lightmap generation process will be slower.

In this tutorial we will simply use just one light source as the sun.

Each light source appears as a sun image (even when they are used as in door lamps …)


3.2) Go to the Color tab.

Select values as appear in the screenshots below:



Each light source has two important components: Ambient and Diffuse.

The ambient light is the background light while the Diffuse light emits from the light source itself.

Ambient light is the “available light” that has nothing to do with the light source itself. All parts of the world will be lit by the ambient light (whether there is a direct line to the light source or not).

Specular lighting is usually not used for lightmap generation.

How do you know whether you have the right Ambient/Diffuse values ?

If after you generate lightmaps, your world becomes too dark, it means you need to increase the values for the Ambient and Diffuse components.

If the light source effect is not noticeable enough, you need to reduce the ambient light and increase the diffuse light.

 If the result looks good you have the right values.

Note that if you define several light sources, you need to decrease the ambient/diffuse for each of them as not to have too much light.

This is all you need to know about Ambient and Diffuse lighting (though you can Google it up, and read a lot more)


3.3) The “Quick Test“ button.

This button help you see whether your Ambient/Diffuse settings are too dark or too bright.

Generating lightmaps could take a lot of time. Before you start this process you want to know that you have the right values.


3.4) Setting the light source location

Fly inside the 3D till you get to the location where you want position the light source.

Then go to the “Source Location” tab and press the

“Set light source location equal to the current viewing” button.

See image below:


Rounded Rectangular Callout: Click on this button, once you reached the position where you want the light source to be.
Rounded Rectangular Callout: When checked, the keyboard keys will move the light source and not the viewing point.




To fine tune the location of the light source, check the “Move selected light source” checkbox (at the bottom right of the application window, see above screenshot).


In our example, it doesn’t really matter where you put the light source. Put it somewhere high so it can simulate the sun lighting.


3.5) setting the light source reach (optional)

This step is optional.

Select the “distance reach” tab

Sometimes we might want to limit the effect of a specific light source to a certain radius. For example, a street light should effect its near surrounding and should not affect the entire street.


In our example, we will not limit the reach of the light source. We will select the default settings (infinite reach)


Step 4 – Generating the lightmaps

In this stage we will create the lightmaps. Select the “Create Lightmaps” tab.

Usually, the default settings are what we want. The one parameter however that we want to play with is the “Number of light samples”


This is the number of lightmap pixels we will generate during the process. The default is 10,000 which is very low.  The bigger this number is the better are the generated shadows/lightmaps.

The price we pay when we increase the number of samples is the time that it will take to generate the lightmaps.

1 million lightmap samples is a reasonable number. Also, 1 million lightmap samples could be stored in a 1024x1024 bitmap.

What to do ?

4.1) Increase the number of light samples to  1 million

4.2) uncheck the “render on-going progress” check box so it will be faster

4.3) click on the green “Create lightmaps” button

Now it is a good time to have a cup of coffee while the application is working …


Step 5 – Grouping lightmaps together

Your lightmap world should now look like this:


The direction of the shadows in your world could be different depending on where you positioned the light source.

If you try to move inside the world, you will notice it is now moving slower, this is because we have created more than 4000 additional bitmaps (about 4000 lightmaps, one for every polygon)

The good news is that we can group all these small bitmaps in one or two big bitmaps. This will make our world look better and fast.

To do so, click on the save icon at the top left of the application window.


Click on Save.

This will take quite some time.


Some more details about grouping lightmaps

The Problem

When creating lightmaps, a lightmap (a bitmap) is created for each polygon. These bitmaps can be very small (1x1 or 4x2 etc ...) So if we have 100000 polygons in the world, we will now have additional 100000 lightmaps. This could slow down rendering dramatically.


The solution

We can group these small bitmaps together. A regular 1024x1024 bitmap can store 1 million 1x1 lightmaps !!!  So instead of dealing with 1 million files, the 3D Engine and graphics card take care of just one 1024x1024 bitmap ! Usually of course we the lightmap bitmaps will have different sizes. This utility will squeeze them all into bigger bitmaps.




We can group all the bitmap together or just the lightmap bitmaps. Note that even if we want to group all the bitmaps, it is not always possible to group them all. For example, bitmaps that are used for tiling cannot be grouped and be part of bigger bitmap containing also many other bitmaps

"Group Bitmap Size"

This is the size of the bitmap that is used to group the tiny bitmaps together. A size of 1024 means a 1024x1024 bitmap. Most graphics card can handle this size easily


"Max Bitmap Size To Group"

We might want to leave some relatively big bitmap separated and not part of a bigger image.


Convert to 8 Bit

To make the grouped lightmap bitmaps take smaller size we can convert them into 8 bit color space. This is ok if we just group together lightmaps since they will usually be in grey scale. If however we use several sources of light in different color then 8 bit color space would compromise color accuracy.


Examining the result

Let’s go to where we saved our 3D world with the grouped lightmaps.

In the bitmap folder we will have two new bitmaps:

1) The lightmap of the ground polygon

Since this lightmap is big, it wasn’t grouped together with all the rest of the lightmaps

2) All the other lightmaps (for every  polygon other then the ground polygon) were grouped together to one bitmap:

This lightmap, contains around 4000 tiny lightmaps together.

It looks like garbage memory but it is not. The 3D engine can map the relevant fraction of the lightmap to its owner polygon.



--- T h e    E n d ---