TUTORIALS - UE3 LIGHTMAPPING

Info

About : This tutorial will explain the reader how to get meshes lightmapped in an Unreal Engine 3 environment.

Target Audience : Unreal Engine users - intermediate skill required

Platform : Unreal Engine 3 including RoboBlitz

Last Update : November 2006

Related links :

Vertex Light Tutorial










The basics

In UE3 meshes too can be lightmapped. While in the previous engines only brushes were lightmapped (=LM) now meshes too can be LM'ed. Lightmapping is a static lighting technique using colored bitmaps that are blended on top of the textures in order to make them appear lit. It can give great results but it is also quite heavy on the memory and it is of course very static. It is far better than vertex lighting though!

UE3 supports dynamic light (stencil shadows) and two types of static lighting: lightmaps and vertex lighting. Its vertex lighting is identical to UE2 titles such as UT2004. Information about vertex lighting can be found in my Vertex Lighting Tutorial.

Lets start this tutorial with a basic test setup.



The test setup features a BSP platform with a white steel mesh cube and a torus knot mesh above it. The torus knot will function as a cool shadow caster. The white steel mesh is the test subject.
As one can see the scene currently has some very cool shadows. These are the dynamic stencil shadows.

Upon rebuilding however it looks a lot less cool.



This is because whenever a light (whatever type it was) is changed
it will become a dynamic light until the next lighting rebuild. Any shadow that looks cool might therefore not look so cool anymore after a rebuild unless it is a dynamic light.

The reason why the test mesh doesn't seem to have any type of shadow anymore is because the static lighting was baked as vertex lighting. In a lighting only viewport mode one can clearly notice so.



The mesh still has some shadows because it was heavily tessellated in 3DSMax.

All meshes a user imports will always fall back to basic vertex lighting if the mesh was not properly configured for lightmapping. This test mesh was not properly configured for lightmapping and thus fell back on vertex lighting when it was rebuilding.




Lightmapping a mesh

A mesh will not be lightmapped in UE3 if it does not has a correct UV set available for the lightmapper. In other words. A mesh must have a second (or 3rd/4th etc. dependent on the mesh) UV set/Unwrap layer available.

That second UV set must be correctly unwrapped.


No faces may take up the same position. Every face needs a unique location.





All faces must be in a single UV space.



The diffuse unwrapping of most objects does not fit those requirements. Often faces share identical positions of a skin or texture and they often are also a lot larger than a single UV space. Therefore, to not having to adjust the basic diffuse UV set one must make a second UV set that will be used solely for the lightmap info and will have zero influence on the basic diffuse unwrap.

In 3DsMax (multiple UV sets are supported by all major 3d packages including Maya) add a new Unwrap UVW modifier (a1) and be sure to set the Channel to 2 (a2). Next unwrap your mesh nicely according to the rules or, if you are too lazy, you can also let Max auto unwrap the mesh for you. To do so click on Mapping -> Flatten Mapping (a3).



If you wish to preview how the unwrap looks in Max be sure to add a material to the mesh that has been set to channel 2.



Once done with all of that export the mesh the regular way and import it in UED, also the regular way.

Please note that the newer versions of Unreal Engine 3 now also support in-editor generation of lightmap UV's, it is therefore not required to manually create the UV's anymore, but it usually does gets you a cleaner result.


In UED you also need to set a couple of important options.

Once the mesh has been imported double click it in the generic browser and in its properties be sure to set its LightmapCoordinateIndex to 1 and the LightmapResolution to 512.



The CoordindateIndex is what UV set/channel it should use. The Unreal Engine, unlike 3DSMax or Maya, starts counting from 0. Therefore the second UV channel you made in your 3D program of choice is not number 2 but number 1 in UED.
The LightmapResolution determines how detailed the lighting information will be on that particular mesh. Obviously you only want to enter numbers like 8,16, 32, 64, 128, 256, 512, 1024, 2048. Do not go over the top with the number. Every single instance of the mesh will get a unique lightmap of the size you entered. Too many too large lightmaps will kill the engine and drive up the filesize. Don't be afraid of using small lightmaps. Even a small lightmap can make things look great!

Once that's done place the mesh in your level and be sure to go to its properties. In there go to StaticMeshActor -> Lighting and StaticMeshComponent. In those two sub sections be sure to check bForceDirectLightmap and especially bOverrideLightMapResolution. The latter is enabled by default and unless you turn it off or enter a valid lightmapresolution in the property below, your mesh will not be LM'ed correctly!!




Once you did all of that correctly the result will look really cool. Also be sure to rebuild lighting!