UDK Lighting

Documentation for lighting in UDK:

Remember to read the official documentation in addition to this document. The official documentation goes into a lot of detail on the specifics.

  (The last one is the basics of lighting in engine,
   although much of it is out of date.)
Other less important topics:



Understanding UDK's Lightmass System

An Overview Of Lightmass

 The system that builds lighting in UDK is called "lightmass".  UDK, using lightmass, actually needs to handle at least two distint types of lighting:

During gameplay, both static and dynamic lighting are combined.  Note that a single object may use some combination of static lighting and dynamic lighting at the same time.  (Indirect lighting may be baked in a lightmap, but direct lighting may be dynamic to account for players and objects moving in front of the light source.)

For best performance, artists should try to use static lighting on as many objects as possible.

It's worth nothing that the UDK lightmass system is a full global illumination type system, visually similar to baking final gather lighting in Maya. The lightmass system also support creating ambient occlusion in the lightbaking process.  Also, the post process system does some minor screen space ambient occlusion, glows, and color correction.

For the reason's above, lightmap baking in Maya is not always required, though sometimes in can help get a better look. What is required is for most objects to have *really good* lightmap channel uvs. Alternatives to lightmaps include vertex colors and dynamic lighting. (See the section about Dynamic objects below.)

Most parts of most scenes will just be static models with static lightmaps.

Any lightmapping on objects done outside of UDK is essentially just "extra" lightmapping.  Normally, the build process in lighting computes all the lightmaps for the player.  UDK just needs good UVs on the models to support the lightmaps that are created by UDK.  Often it is useful to bake some additional lightmapping into the object (AO etc)  however, UDK is actually able to do most of it itself.

In particular, any lights baked prior to coming into UDK should be as generic as possible, since the objects will likely be moved around and duplicated in UDK.  For example, do not bake a spotlight shining a bright spot onto a part of an object using your 3d authoring package.  In general you should not bake directional shadows in your 3d authoring package either.

If color variation isn't required in the baked lighting, then it's good to put the baked lighting info into a single channel of an image. (As opposed to wasting 24bits per pixel.)  Either the alpha channel of one of the regular textures can be used, or one of the RGB channels on a texture can get used, with the other channels being used for other mapped properties.

Lightmass on Static Objects

Static objects will generally use static lighting, stored as either lightmaps or vertex colors.  However, moving lights will light static objects dynamically.  Light types with the name "Movable" in them, such as "PointLightMovable", will add dynamic light to objects that otherwise use static lighting.

Lightmass on Dynamic Objects

Dynamic lighting is generally lower quality than static lighting, because high quality dynamic lighting is extroardinarily hard to compute.  (Think of how long mental ray takes to render a frame, compared to UDK rendering 60 frames every second.)

Generally, for dynamic objects, UDK light environments are used.  During light building UDK bakes the global illumination lighting at various points in space, and the light environment component is able to sample that information. The light environment takes all the direct and indirect lighting into effect and turn it into "spherical harmonics" (complex math based storage of lighting) that can be applied to moving objects. In additionl to the spherical harmonics, a single direction light is created to represent the average direction of the brightest light.  (Thus only one shadow will be seen, even when several lights are shining on a light environment using actor.) The end result is that the light environment creates 



Lightmap Based Lighting

Lightmass generates lightmaps for most static lighting in your scene. Lightmaps are texture maps that the computer generates based on the lights that you place in your scene.  When you push "build lighting" lightmass regenerates the lightmaps, as well as any vertex color based lighting. (Explained in the next section.)

Lightmaps are explained more in the section below titled "Understanding Lightmaps".


Vertex Color Based Lighting

 Objects that have a lightmap resolution of zero will use vertex lighting instead of lightmaps, however, vertex lighting only works well when the objects has a lot of verts, and they are spread evenly.

To use vertex color based lighting, simply set the lightmap resolution to zero on any object, either in the static mesh editor, or on on the properties of the individual instance in your scene.



To Use Lightmass In Your Scene

A lightmass importance volume is crucial to have when using the lightmass system.  The lightmass importance volume tells UDK where it needs to focus on getting good lighting quality.  All the important parts of your scene, other than background elements (such as your skybox and distant scenery) should be within the lightmass importance volume.

Each scene should have exactly one lightmass importance volume. It should just be a box.  UDK doesn't currently (as of March 2012) support other shapes for lightmass important volumes, nor does it support multiples.  If you use another shape it will use the bounding box anyway.


The Light Source Radius Option

Most lights have an option for the light source radius.  It only affects lightmass static lighting.

The light source radius controls how big the area emitting light is. (The size of the lightbulb.)  It is represented by a yellow circle.  It has a strong effect on the shadow sharpness for static lighting.  Large numbers cause very soft shadows.  Keep in mind that small numbers will cause the shadows to look more like the sharper shadows created by dynamic lights.

Be careful not to have the light source so large that it intersections with other geometry that casts shadows. That would mean that half the light sources was behind a shadow caster, and the lighting would look very strange.

In the viewport menu, you can use:  show > advanced > light radius    to toggle display of the light radius.



Understanding And Working With Lightmaps


Lightmap UVs

By default, lightmaps use the second UV channel/set, which has the index "1".  Remember that the first UV  channel/set has index "0".  Most of the time, UV[0]  is used for regular texture mapping, and UV[1] is used for lightmapping.

UVs for lightmapping should all fall within the 0 to 1 range in both U and V. (eg. On the main grid/texture in the Maya UV Editor)  UVs should be non overlapping and unique.  Some stretching is ok for lightmapping, but seams should be avoided as much as possible.

Lightmap Resolution

The lightmap resolution controls the detail of the shadow. It is the size (in pixels) of the texture map that will be created as used as a lightmap

Larger lightmap resolutions will cause build time to go up a lot. (Whenever you use "build all" or "build lighting" the computer will spend a long time calculating the lighting.

Here are a couple examples of lightmap resolutions:

In general most objects will look good enough with lightmaps of 128 or 256.  Resolutions of 512 should be used quite rarely.

What resolutions you use are also largely defined by the platform you are running on.  Numbers given in the above examples are for a typical modern PC.

Lightmap Resolution can be controlled for both Static mesh actors and CSG/BSP geometry (geometry built in UDK). The methods for doing so are described below.


Controlling Lightmaps Quality On CSG/BSP Geometry

The default lightmap size on bsp geometry is very low quality.  You will likely want to turn it up significantly.

Select BSP surfaces, press F5 for the surface properties. Change the lightmap resolution.

Smaller numbers, give higher quality lightmap resolution.  Note that this is the opposite of how the resolution is controlled on other objects (where higher resolution means better quality).  Thus, for CGS/BSP geometry, turn the resolution down here for better quality.  Turn it up to improve lighting speed, and use less RAM for textures.

A setting of "4" looks great for important surfaces.  Farther away surfaces and less important ones can use the default settings.


Controlling Lightmap Quality For Most Objects

Every static mesh has settings for the lightmap resolution. The default lightmap size is extremely low.  It will cause artifacts on most meshes.

A resolution of 128 works well on most objects, if you can afford the time when building/lighting your scene. Values of 512 and beyond start causing extreme slowdown in the build system.  Very few objects should require lightmaps of such high sizes. If your lightmap needs to be that big, consider breaking your model up into smaller pieces.

For static mesh lighting, there are two main methods of controlling the resolution.

A useful strategy is to use fairly low resolutions in the static mesh editor, and then when nearing completion of the lighting in your scene, override those values with larger numbers.


Things To Watch Out For When Using Lightmaps

If you have one giant high poly static mesh (such as an entire house), it will all need to use one lightmap, of a very high resolution. This can be very problematic.

Attempt to split you objects up into modular components that can fit together.  A house that the player can walk up to should be made of several wall pieces, window pieces, and other small pieces.  A house far away in the background can of course be very low poly and use a small lightmap.

For any objects that are very small and simple or far away from the camera, consider using vertex lighting (a lightmap resolution of zero). In many cases it will look good enough and save texture map memory.


Lightmass Settings

Emmisive Materials with Lightmass

You can cause emmisive materials to actually illuminate the scene using lightmass. You need to turn the option on for each object in the scene that should cast light via it's emmisive texture.  Only static objects can be emmisive.  It won't work for animated/moving objects.

Static Mesh Actor
  Static Mesh Component
      Lightmass Settings
        Use Emissive For Static Lighting

Note that emmisive lighting can affect dynamic object in a way, since the light environment spherical harmonics do sample the global illumination system.  It's not entirely perfect, but it actually works reasonably well.


Controlling The Strength of Lightmass Global Illumination Lighting - Lightmass Boost Values

There are several places where you can change the strength of the lightmass.

The boost settings all multiply with each other. (So if they are all set to "1", the end result is "1", meaning regular intensity of lightmass lighting.)

Places to find boost settings:
  World Settings
  Static Mesh Itself

Diffuse Boost is set to 5 in many scenes (and in many default scenes).  It is recommended that you start by setting it to a value of 1 and adjust from there. In the World Properties Lightmass settings, check the "Diffuse Boost" and make sure it's not set to 5.  Such a high value would cause ultrabright lighting that would be too colorful. (Only useful for really stylized unrealistic lighting.)


Useful Properties Related To Lighting


Select Some Surfaces and use:   RMB > Surfaces >  Lighting >  Lightmap resolution

Indirect normal influence boost, found in World Properties

When this setting is too high (often anywhere above 0) it can cause artifacts in lightmass, such as dark patches on object lighting.  If you are having such a problem, try setting it to zero and using build > build all.



A Strategy For Lighting Your Scenes

Here are some examples of workflows you can use to work fast before lighting your scene, and speed up the process when you are finally ready to actually do the final lighting.

Please note:  This is not an artistic guide to lighting.  Just some workflow tips.

In the notes below, "Dynamic objects" mean any objects that can ever move during gameplay.  Doors, elevators, destructables, characters, physics rigidbodies, deforming objects, etc.

All the various light types available can be found in the content browser in the Actor Classes tab.  Find lights in the tree and open up that section to find them all.

Before lighting, when first building your level

While Lighting

All of these are just suggestions and starting points.  Since every scene is different, you'll need to use different settings for every scene.  However, in most scenes, the settings that look the best are similar to what is described above.


Teaching3D is a creation of Joe Crawford