Mastering Unreal Engine 4.X
上QQ阅读APP看书,第一时间看更新

Building lightmaps for a level

Lightmap is a term used for a lighting concept, where all the light data is saved in maps and the lights themselves are disabled at runtime. This means that there will not be a real-time lighting for those baked objects. This is widely used in games in order to reserve GPU calculations for something else.

The process of building a lightmap (lightmass) itself is not complex; it is just a case of hitting the Build button. But what takes some time is the tweaking done before the button is pressed.

The rule of lightmaps is that only static objects can be baked into lightmaps, which means any movable item at the level will not be written to lightmaps, and that includes, but is not limited to, characters and enemies. This means that you have to make sure that the Mobility setting inside the Details panel for all the items that are not meant to move in your scene is set to Static.

That takes us half-way to lightmaps. The other important setting is the resolution of the lightmap of an object. As we mentioned, lightmaps are like images with light values, which means that they have a resolution. The lower the resolution, the less detail and quality you will get, but with faster building time and VRAM resources usage. The higher the resolution, the better quality and detail you will get, but with more building time and a higher risk of texture streaming crashes with some players. Therefore, you have to balance its value and define what matters and will be seen closely by the players and what is out of reach.

Each object has a Lighting section in the Details panel, where you can set some values for light-related settings and tweak them.

Once everything is OK and you are good with the chosen values for your static meshes, just hit the Build button from the top bar and this will build everything (including the navigations, if any). For faster results, you can hold this button to choose one of the suboptions, which is basically Build Lighting Only.

Now, the level looks even prettier and its performance and rending cycles are faster. It is time now to add one more detail to the level, which is water. As the water will look live and moving, it will not need to be included into the lightmaps, so let's add it now.

Creating water surfaces

When it comes to creating an entire game from scratch, you have to be productive and smart about consuming time and resources. Sometimes, you have to rely on things that are already made with Unreal. For example, we could build this game based on a Third Person Game template. This might have saved us the time we spent creating the player controller, but we managed to create it from scratch in order to build it in a way that fits our needs.

But there are other things that were made by the Epic team for us in order to make life easier and faster, just like the popular Ocean shader that was made and shared during Unreal's live streams.

We could spend lots of time trying to create this shader from scratch, but eventually we will end up with something not very close to it. This shader can be found with many Unreal free examples in the Learning section of the launcher, and it is free to use for all types of projects; it is really used in a wide range of games.

Fortunately, this shader is one of the Infinity Blade assets we have imported into our game in Chapter 1, Preparing for o Big Project. This means we already have the shader material within the project. You can easily find it by typing its name M_Plains_Ocean at the content browser search tab.

Once you find it, I would highly recommend spending some time understanding it, just in case you want to add more details or even changes in order to adapt the visuals of your map.

Now, let's come back to creating the water surface. Creating a water surface is a matter of creating surfaces that hold the Ocean shader, which means that you can create a plan mesh or cube, and apply this shader to it. Or you can even create a custom mesh in Maya or 3dsMax and export it to Unreal. It doesn't matter what type of mesh, but eventually, you have to create a mesh with a sizable number of vertices and just drag and drop the Ocean shader on it.

In my case, I used a plain mesh, scaled it to fit the level boundaries and even a little more, and then applied the Ocean shader to it.