Light-mapping for the Unreal Engine used to be an extremely tedious process, as it could only be prepared in an external program such as Max or Maya. Well, thankfully there is a solution! In the first of our Unreal Dev Kit tutorials, Jarlan Perez walks us through how to first prepare a model, and then setup light-mapping entirely within the UDK itself.
Additional Files/ Plugins:
In the RefFiles.zip file you will find two folders : package and scene. Both the start and end file for this tutorial have been provided inside the scene folder.
Let’s get started. Launch the UDK and opening up the LightMapping_Start.udk located inside your scene folder. This is a very simple scene consisting of a subtracted cube and a single spotlight as shown below.
Go ahead and open up the Content Browser and load the LightMapping.upk package located in the package folder, as shown below. Inside you will find two static meshes, a cube named base which we will be using for the floor where our shadows are going to be projecting, and a circular tube shaped mesh named tube which will be the mesh casting the shadows.
Select that base mesh and drag it over to your scene.
Next we’re going to drag the tube into the scene. Make sure that you leave a reasonable amount of space between the two meshes so that we can get a pretty clear shadow in the final scene.
Let’s go ahead and test the lighting and see what we get. Make sure to turn off the Use Lightmass option, as simulating GI will greatly reduce your build time and at this point we don’t really have much use for it! Use the settings shown below :
You should get something similar to the image below. We're currently getting extremely soft, subtle shadows, and why are there no shadows on our base mesh? That’s what we’re going to explore.
Every single static mesh that is imported into Unreal has its own unique UV set that is used to apply textures. To get the desired, lightmapping effect that we’re looking for we’re going to have to make a brand new UV set that will be used to save the shadows of your Lightmap. As you can see this object only currently has one UV map or channel.
To create our new UV map, first go to Mesh > Generate Unique UVs, as shown below :
This will open a small submenu for UV generation. Since these UV maps are only going to be used for capturing shadows, there is no longer any need to export your models to an external program in order to create a new UV channel.
Unreal reads UV channels starting from 0 (e.g. the very first UV channel will be Channel 0.) We're creating a new map in addition to the existing one, so make sure to set the UV channel to save results to dropdown to 1.
For now, leave the Limit maximum stretching (0-1) at the “0.500000” default value. That's seemed to work great for me in the past, and I really never found much of a reason to change it. When you have all of the settings in place, as shown below, hit Apply.
Let’s take a look at our results. You can clearly see that Unreal has created a 2nd UV set, and now we just have to let Unreal know that we're going to be using this new UV set for light-mapping.
To do this, go to the field titled Light Map Coordinate Index and set that to our new UV set's channel, which was 1.
Now we have to set up the resolution for our light maps. Go to the field titled Light Map resolution and set that to 512, which should give us pretty good looking shadows. (If we need to increase shadow detail in the future, we can always double this value to 1024.)
Now there’s just one thing left to do - let the engine know which of the meshes we want to receive shadows. The reason we select specific meshes (and don't just calculate light-mapping on everything), is to prevent unnecessary processing and save on overall build time. For instance, you could have 50 of the same Meshes in a scene but only want 10 to have very detailed light-mapped shadows. You would designate these 10 items to receive shadows based on your UV map, and the rest would be calculated using Unreal’s default shadow system.
Designating light maps is very simple. Right click on your object and bring up its properties (or you could use the shortcut F4.) Click the StaticMeshActor label, and then in it's properties section, click the StaticMeshComponent label.
In here we’re only going to be adjusting two things; first of all we want to make sure that Override Light Maps is checked on, and then we want to set the value for the Overridden Light Map field to match the resolution of our UV map, in our case 512.
Now hit the Build Light button and use the same settings as in step 5 above. Your final image should look something like that below :
And that's how to set up light-mapping using only the UDK! I hope this demonstration was helpful, and if you have any questions please feel free to leave them in the comments below!
Envato Tuts+ tutorials are translated into other languages by our community members—you can be involved too!Translate this post