Swap lightmaps at runtime?

Hi Everyone,

We have a scenario where we have a level (umap) that we have different versions of for different times of day. (Daytime, night etc). The level is lightmapped, and everything about the level is the same except for the lighting settings. All our models, textures, materials etc are the same for all variants. I know the lightmaps for each level are contained in the .umap file, so I don’t know of a way how we could basically get the lightmaps from one umap and swap them out. (which is why I’m asking :slight_smile: )

At the moment when we want to go to a different variant of the same level, the old map gets unloaded and the new map is loaded up. This takes quite a while considering all we basically need to change is the lighting. What we were expecting to happen is that the engine would detect that it already had all the textures/models etc already loaded into memory, and wouldn’t bother unloading and reloading them, but that doesn’t seem to be the case. We’re using ServerTravel to load our maps.

We’ve also found that even if we load into exactly the same map via server travel, this unloading of the whole level, and loading of the whole level will occur, which surprised us quite a bit as we expected the engine to be super smart about this kind of thing. (We’ve taken steps to not reload a level that we are already in ourselves now)

So I have a few questions:

  1. Without modifying the engine code, is there a way of simply swapping out lightmaps?
  2. If it would require engine changes, would it be straightforward to do or a massive amount of work?
  3. If we did something with level streaming, where we would stream in and out our level variants, would that give us a way to work around the issue? For example, if player was playing in daytime, but then wanted to play at night, could we stream in the night variant (hopefully the engine then would realise it has all the models/textures etc in memory and wouldn’t need to unload/reload) and then stream out the day variant? Does that (or something like that) sound like a plausible workaround?
  4. Is there any other potential way we could make sure all our textures/models etc aren’t unloaded and reloaded everytime we change level?

Thanks everyone,

Matt

Hi,

This post from the AnswerHub may be of help as well: Lighting streamed levels located at the same place - Rendering - Epic Developer Community Forums

In it I provided a sample project that shows how I setup different lightmaps for streamed levels.

There is no way to swap these out in that sort of way. Using the level streaming method from the post above will work though. But swapping out the Lightmap Texture is not an option I’m aware of.

I’m not aware of any way to not unload/reload the assets when the level changes.

I know I’ve not been very helpful with some of this, but it is possible to have different light bakes for your levels via level streaming.

Thanks!

Tim

Thanks Tim,

Your sample project and answer is exactly the kind of thing we need. Our main concern was with multiplayer but the origin shifting problem mentioned in the level streaming documentation shouldn’t cause us any problems, especially if our levels are centred on the same spot as mentioned in the AnswerHub thread you answered.

So I have a few follow up questions before we dive right into doing this:

  1. I assume for example, if we have a three variants of the same map, that the shared models/textures etc would be resident in memory (once, shared between the three levels), along with 3 sets of unique lightmaps belonging to each of the map variants. Is that assumption correct?
  2. Presumably using level streaming in the above example would increase the ‘base’ loading time of going into a level, but reduce the amount of time when going from one level to the other? So if at the moment it takes us 10 seconds to load into the day variant, and then 10 more seconds to load into the night variant, using level streaming would take >10 seconds to load into the day variant, but <10 seconds to subsequently load into the night variant?

We will use your day-night swapping example project to do some timings and see exactly how much we would benefit from doing it that way.

Thanks for all your help and effort on this Tim,

Cheers,

Matt

Maybe you could try what they did in Portal 2? Load both a light and dark version of the map and then teleport the player? I guess this would only work if your game was singleplayer as well.

  1. Each level will have it’s own meshes that are loaded and unloaded from what I could see in my tests with “Stat SceneRendering.” This would make sense as well since each level will have its own specific settings and meshes, no matter their placement being the same as the other levels, it will generate the same draw call specified that they are in fact the same map just using different lightmaps.

  2. Honestly, I can’t say for certain since anything I’ve tested has usually been in a smaller scale than an actual game level. In my latest testing though, I used the foliage tool and placed a couple of thousand trees that is a definite FPS killer. I did switching between levels with minimal load in and out using level streaming, and then I used “open level” node and loaded the map by itself which loaded only a second or so behind what the streaming would do. Obviously using normal game development techniques with culling, and LODs will help in the performance area with FPS and provide a smoother transition.

I’m not positive on the load times you’ve used as an example, again since I’ve not really messed with anything on that scale with level streaming personally, but I would say that since the map is unloading and reloading in the assets along with the lightmaps for that variant that there may be the same wait time. As you said, using the test project as a testing base would probably be the best solution to see what the load times are turning out to be. Optimizing lightmap resolutions, LODs, and culling may further help reduce the load time as well.

Thanks!

Tim

Thanks again Tim,

We’ll post back here when we’ve got done some tests and timings. Others might find it useful.

Cheers,

Matt

Yeah no problem at all.

I’d be interested myself in the results and I do think this would be extremely helpful for other users in the community as well. :slight_smile:

Tim

Hi all. level streaming method is cool but have 2 causes for me. First, is long loading(need use loading screen for hide this process). Second, this is not smoothly process( I can’t use this for daytime cycle). This is work of future?
I see 2 ways:
Lightmap states (global rebulds lightmaps and control from postprocess volume)
Lightmap output for material (not emissive output) for use custom LM files.

Yes, I am a beginner with Unreal Engine and I quickly ran into this problem with my particular project as well. Currently there is no way to have a day and night scenario other than reloading the whole scene or perhaps use stationary lights for the directional light which imposes a greater cost.

I would also very much vote to add this feature to a future version of the Engine.