WoLD Archives Search About Contact

World of Level Design

Tutorials to Becoming the Best Level Designer and Game Environment Artist (since 2008)

UDK: 18 Important Principles for Creating/Using Lightmaps (Lightmapping Basics)

Category: UDK
May 21, 2012

Lightmaps are very important part of game environment production in UDK. The quality of baked lighting and shadows in your map depend on it. Lightmaps determine how your models are lit, how they receive and cast shadows.

In the following 5-part series, I will go into depth about UDK Lightmaps. You will learn everything you ever wanted to know about lightmaps and how to make your Static Meshes light and shadow correctly.

Lightmaps is something I've had a lot of problems with. So, I set out to know as much as I could about them. The following series are my studies.

UDK Lightmapping Series:

UDK: Lightmap Basics and 18 Important Principles for Creating and Using Lightmaps
UDK: Lightmap UV Layout Techniques and How to Create a Second UV Channel in Maya
UDK: How to Fix Lightmap Light/Shadow Bleeding and Seams
UDK: Lightmap Resolution for Static Meshes and BSP
UDK: Lightmap Common Problems and Solutions

There are many important principles to keep in mind when you are creating lightmap UVs and lighting your custom game models. To give you a better example of what lightmaps actually do, here are a couple of screenshots.

Below is an example of a custom model imported into UDK that does not have lightmap UVs. It contains a single UV channel; this single UV channel is used for texturing the custom model. It does not contain a second UV channel, which would be used for a lightmap. When we build lighting in UDK, this model contains many visual errors. Light and shadow bleeding and it just plain looks bad. Not something you would ever put in a level and call it done.

No second UV channel for lightmap:

Here is the same model that contains 2 UV channels. First UV channel are UVs for texturing the model; second UV channel are UVs for lightmap information. When we build lights inside UDK, we receive correct light and shadows. No light or shadow bleeding.

Contains a second UV channel for lightmap:

In the following tutorial I will cover important and tested principles of creating and using lightmaps for UDK. These principles are the key for making your static custom models light/shadow correctly.

First lets cover what lightmaps are and what are they used for in UDK in more detail. Then we'll cover the principles to follow when creating lightmap UVs and having your custom models light/shadow properly.

What Are Lightmaps?

Lightmap is a way of generating textures that simulate lighting of your game environment. Lightmaps are baked during compiling (when you build lights) and are overlaid on top of geometry (bsp and custom static meshes) to simulate lighting and shadows. Theses lightmap textures are generated when you build lighting inside UDK.

Lightmaps are used for non-moving, static geometry and bsp.

Lightmaps are enabled by default in UDK. It's what you will use for lighting majority of your game environment.

When you do not have a second UV channel for lightmap on your Static Mesh (custom model) you will see "invalid LightMap Coordinate Index" error after Lighting Build:

All lightmaps are stored within the UDK map file. Here are lightmaps within the UDK map file generated after you build lights:

click on image to view full size

You do have two other options to light your Static Meshes. Vertex lighting and dynamic lighting. These two options should be used sparingly. Remember that majority of your level should be using lightmaps.

Vertex lighting uses vertices information to light your mesh. Vertex lighting is more memory intensive and requires geometry tessellation to receive and cast proper light/shadows.

Dynamic lighting is rendered in real-time and is very expensive.

Lightmapping generates better light and shadow information and does not rely on tessellation or expensive real time rendering.

"Lightmaps reduce CPU and GPU load. Since there are no lighting calculations done on geometry and all the lighting information is baked into textures."

Source: (Epic's UDN Games Level Optimization #Lightmaps).

Important part of making your model light and cast/receive shadows well is the way you UV the model by creating a second set of UVs to contain that lightmap information.

18 Lightmap Principles to Follow for UDK:

Everything in this study was built on Production Lighting to avoid any Preview Lighting artifacts and give you the most accurate lightmap lighting situation.

1. Lightmaps are Automatically Set

Static Meshes in UDK are set to use lightmaps automatically. If your meshes are not lit properly and have patchy light and shadow issues as well as a lot of light/shadow bleeding, this means you have not set up custom lightmaps UVs in the second UV channel. You can generate unique UVs for lightmap in UDK, but better option is to create a second UV channel in a 3d app.

If you open Content Browser window and double click on any static mesh, you will see Static Mesh Editor pop up. In here you can check how many UV Channels a static mesh has.

1 UV channel means the object has texturing UVs:

 

2 UV channels means the object has both texturing and lightmap UVs:

2. Second UV Channel

For your static model to light/shadow properly you need to create a second UV channel inside modeling app such as Maya or 3dsMax.

You could generate unique UVs in UDK within Static Mesh Editor, but the best way is to create a custom set of UVs is using a 3d application. This way you have complete control over how lightmaps appear in your map.

In the second UV channel, the UVs will be laid out specifically for lightmaps. The way you lay them out will be different then you would for texturing.

To create a second UV channel in Maya do the following:

Make sure you are under Polygons:

Go to Create UVs and choose either to Create New UV Set or Copy Current UV Set:

To check that you have 2 UV channels, open up UV Texture Editor window and under UV Sets you will see 2 UV channels. First one will be for your texturing UVs. Second one will be for lightmap UVs.

3. Lightmap UVs Must be Unique - No Overlapping

Once you have created a second UV channel it will be used for lightmapping. You must not have any overlapping UVs in the lightmap UV channel. Each face must be uniquely laid out. If there is any overlap, the faces tend to render black after lighting build. This means you will often have to manually unwrap for the second channel, just as you did for the first (texturing) UV channel.

Overlapping UVs in the 2nd UV channel:

Overlapping UVs error after Lighting Build:

Overlapping UVs in game:

click on image to view full size

Remember that second UV channel should be unwrapped differently then for texturing. In the first (texturing UVs) you can have overlapping UVs. But in your second UV channel (lightmap), you need to avoid any overlapping UVs. You will also weld the UV edges differently then you would for texturing.

Texturing UVs:

Lightmap UVs:

4. 0 to 1 UV Space

Lightmap UVs must be within 0 to 1 space. No UV should be outside of 0 to 1 UV space.

If you receive "Object has wrapping UV's" error that means you have UVs outside the 0 to 1 space.

5. Do Not Use Automatic Unwrap

Generally using automatic unwrap is not good practice for creating UV lightmaps. Automatic unwrap simply splits your faces into individual UV shells. There is too much wasted UV space and it doesn't take padding into account. Although sometimes automatic unwrap does work, it is better to start with automatic unwrap but weld and pad the rest of unwrap and layout yourself.

Automatic unwrap is just that. Automatic. It doesn't know what its unwrapping for.

For best results you will have to manually unwrap your lightmap UVs. Automatic unwrap causes to many UV islands and wastes a lot of unused space where it could be used to increase the quality of your lightmap.

6. Padding and Bleeds: UVs Shells/Charts Must Have Padding

You must have padding to prevent lighting/shadow bleeds across your model around every UVs shell. 2px is good, sometimes it will require 4px.

There should be enough padding between UV shells. You can use the edges of 0,1 space of the UV layout. Lightmass automatically pads the outside of the layout, but within the 0,1 space of the UV Layout, you need to make sure that each UV shell has padding to prevent light bleeds.

Here is what happens when there is no consideration taken with UV shell padding. UV layout:

Results in UDK: light/shadow bleeding.

UV lightmap with 2px shell padding:

Result in UDK: clean lightmap.

Often you can "fix" this padding and bleeding issue by increasing the lightmap resolution, but this adds to texture memory size and you are only creating another problem in another area of the production and not fixing the problem.

7. Splitting and Connecting UV Shells

Weld UV's where you want continuous lighting. Split the UVs where there will be a break in lighting. Such as a turning corner or top of the object.

Keep faces that change direction and will cause light/shadow change as separate UV shell.

Continuous faces, polygons facing same direction and connected in UV layout:

click on image to view full size

Break in lighting along faces that change direction. These will be cut in UV layout into separate shell to prevent light/shadow bleeding:

"Generally when creating primary UVs, it's a good idea to connect pieces as much as possible. It eliminates texture seams and reduces the number of parts, making the task of texturing easier. However, for lightmap UVs, it's usually a bad idea to connect pieces that go around corners, particularly when they are intended to be hard corners."

Source (Stephen Jameson.com)

8. UV Lightmap Coordinate Index

When you open up Static Mesh Editor by double licking on any Static Mesh within Content Browser you are able to see how many UV channels the mesh has. You can also view the UVs.

In UDK diffuse/texturing UVs will be on channel 0, while lightmap UV will be on channel 1. In your modeling application the count will start at channel 1 (diffuse/texturing UVs) and channel 2 (lightmap UVs).

UDK LightMapCoordinateIndex:

  • UV Channel 0 = diffuse UVs
  • UV Channel 1 = lightmap UVs

Make sure to click on 'Show UV Overlay' to view the UVs.

Light Map Coordinate Index defines which UV Channel will be set for a lightmap. Default is 1.

9. Generating Unique UVs for Lightmap in UDK

You can generate unique UVs for your lightmap in UDK. With simple objects this may work. But for best results and full control you should create your own UVs inside a 3d app (Maya, 3dsMax etc).

Lets use the simple wall that I've used as an example in this tutorial.

In the Static Mesh Editor, go to Mesh -> Generate Unique UVs:

Here is the result of the lightmap UVs generated in UDK:

Results in game: bleeding light/shadow errrors.

10. Lightmap Resolution

Lightmap resolution defines how good and how accurate the light and shadow will look. Just as texture resolution, lightmap resolution is defined by pixels.

Default lightmap resolution in UDK is currently set at 32. 32x32 pixels. You can increase or decrease these values. The powers of 2s should be used for lightmap resolution, just as for texture resolution. Meaning: 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024 etc.

Also lightmap resolutions are a lot smaller in pixel size then texture resolutions.

For lightmap resolution keep these values down in the range of 8-128. Higher resolution will look better but will use more texture memory. Setting a point of reference for your map such as the default 32 is a good start. You can always reduce these values when you are optimizing your meshes.

Open up the Static Mesh Editor and double click on the mesh. In the properties you can set the lightmap resolution. This will control the lightmap resolution for every model in your map.

If you need to increase lightmap resolution to a higher value such as 256, 512, 1024 it should depend on how important and how close the object is to the player and how much of light and shadow transition it receives.

"Ideally, most of the lightmap resolution should be allocated around the high visual impact areas and in places where there are high frequency shadows."

Source (Epic's UDN Lightmass #Lightmap resolution)

You can also set lightmap resolution per model. Double click on the Static Mesh inside your map and in the properties, override the resolution and input the resolution size.

Here are varius screenshot lightmap resolution comparison:

With material applied:

11. Seams

One of the most common problems in lightmaps are seams. It is impossible to remove all seams. The best way is to minimize them by placing UV seams in places where they won't be seen or by using other geometry such as pillars, borders or other static mesh details.

12. Ambient Occlusion

Ambient Occlusion is indirect shadows that you see on objects around edges when they come in contact with other geometry. AO adds realism to the models. Think of AO as contact shadows.

By default AO is turned on. You can enable/disable AO in World Properties. When you build lighting you can turn on/off to see the AO results.

Although AO does not directly help your lightmaps, they do help to add more believability and realism to the scene of your objects. It is an indirect way to help your lightmaps.

Here are two screenshots. One is with AO off. Another with AO on. You can notice the difference it adds the lightmaps. Although you may not have to tweak any of AO properties. Knowing that AO does shade your model slightly can help you enable and disable AO shading to see your lightmaps more clearly.

AO on:

AO off:

13. On Grid

One of the most ideal ways to create lightmaps is to make sure the UV edges fall on the grid. One of the causes in light/shadow bleeds when an edge of the UV falls in-between pixel space of UV layout. Lightmass then bleeds the shadow or light onto the surface. Because of UV edge falling in-between a pixel. Many times it isn't a problem. The texture of your model, the placement of the object in the world makes this issue unnoticeable. But when you do encounter a seam and light/shadow bleeding, make sure to first take a look at the amount of padding the shell has to the surrounding shells and sometimes you may need to align certain edges onto a grid to avoid having UV edge fall in-between pixels. Modular assets often encounter this problem.

To make this clear, take a look at the following screenshots.

UV edges fall onto the layout gridlines:

Result in UDK. No seams between planes:

UV edges do not fall onto the layout gridlines:

Result in UDK. Seams between planes:

I'm not sayng you should try to make everything fall on the UV gridlines, but if you are having issues with bleeding and seams, take a loot at the troubling area and try to align the UV edges onto the grid and give enough padding between neighboring UV charts and see if that fixes the problem. Modular geometry often suffers from this issue and in many instances it does fix it.

Note that my grid in Maya matches the lightmap resolution in UDK for this plane. Which is set at 16 pixels.

For a more detailed tutorial on how to make sure your UV layout matches the grid lines of the lightmap resolution, go here.

Again, this issue can often be fixed by increasing your lightmap resolution. In my experience this sometimes solved the problem, although I would rather fix the UV's in 3d app and re-import and not increase my resolution of the UV lightmap where it isn't needed. I'd rather give more resolution to areas where focal point is important, rather then trying to fix a problem by increasing lightmap size where it isn't necessary.

14. Know Your Lighting

Another element to consider when UVing your object for lightmaps is knowing how you will light your mesh and what the lighting will be in your environment. This can help to determine how to UV your lightmap for best results. Such as when to connect certain UV edges and which UV shells should take up more or less space in 0,1 UV space.

If you are creating an object that can be used in a variety of lighting situations, then you would lightmap it differently then if you knew exactly how the light and shadows will fall onto an object. This does make your object less likely be lit well in all lighting scenario so you have to take that into consideration.

15. Lightmap Density or Lighting Only with Texel Density

Use viewport option to check lightmap texel density. Click on Lighting Only with Texel Density or LightMap Density viewport view to check consistency of your environment lighting and shadow.

If you have an object casting shadow on multiple other objects, difference in lightmap density will cause shadow distortion between these objects. Viewing Lightmap Texel Density will help you to solve this issue. To do this by changing the resolution of the lightmaps to match across two objects.

Variety of lightmap texel density across multiple planes:

16. Study UV Lightmaps in UDK

Best way to study the lightmaps is to see how the professionals did it. Open up Content Browser and look through Epic's gallery of Static Meshes. Take a look at the 2nd UV channel. In UDK this will be marked as UV Channel 1. Turn on Show UV Overlay study how they laid out the UVs, connected various UV shells, the resolution of each object's lightmap and how much padding the object has.

Lightmap UVs in UDK:

17. Always Test In-Game

Lightmaps are never finished until you have tested them in-game while optimizing lightmap resolution. You have to constantly test in UDK, building lights, fixing bleeds and seams. Always test in game to see any problems with bleeds and seams lightmaps are done when they give you the result you want with minimum visual glitches. Use Production Lighting for most accurate results of your lightmaps.

18. BSP Lightmaps

Last but not least you can set a lightmap resolution for BSP geometry that you have in your map.

To do so, left-click on the BSP surface to select it. Press F4 to go to Surface Properties.

In the window you will be able to set lightmap resolution. The only thing you need to know is the lower the value of BSP Lightmap resolution, the better it will look. Which is opposite of Static Mesh lightmaps.

BSP lightmap resolution comparison:

UDK Lightmapping Series:

UDK: Lightmap Basics and 18 Important Principles for Creating and Using Lightmaps
UDK: Lightmap UV Layout Techniques and How to Create a Second UV Channel in Maya
UDK: How to Fix Lightmap Light/Shadow Bleeding and Seams
UDK: Lightmap Resolution for Static Meshes and BSP
UDK: Lightmap Common Problems and Solutions

Other Recommended Links and Resources:

Epic's UDN LightMap Unwrapping
Epic's UDN Level Optimization #Lightmaps
Epic's UDN Lightmass - Lightmap resolution
Stephen Jameson.com - Lightmap UVs Tutorial

SUBSCRIBE & GET FREE UE5 PDF GUIDE

Subscribe to receive NEW/UPDATED and FREE "UE5 Beginner's Quick Start Guide" PDF (90 pages).

Subscribe and Get Free UE5 PDF Guide

Visit this page for more info about the guide...


Follow WoLD




UE5 FUNDAMENTALS VOL.1 COURSE


UE5: RETRO OFFICE PROJECT


LEARN THE PREPRODUCTION PROCESS


ABOUT WoLD & ALEXG

About World of Level Design

My name is AlexG. I am self-taught level designer, game environment artist and the creator of World of Level Design.com. I've learned everything I know from personal experimentation and decades of being around various online communities of fellow environment artist and level designers. On World of Level Design you will find tutorials to make you become the best level designer and game environment artist.

Read More »


Home Terms of Use/Trademarks/Disclaimers Privacy Policy Donate About Contact

All content on this website is copyrighted ©2008-2024 World of Level Design LLC. All rights reserved.
Duplication and distribution is illegal and strictly prohibited.

World of Level Design LLC is an independent company. World of Level Design website, its tutorials and products are not endorsed, sponsored or approved by any mentioned companies on this website in any way. All content is based on my own personal experimentation, experience and opinion. World of Level Design™ and 11 Day Level Design™ are trademarks of AlexG.

Template powered by w3.css