How should I light a procedurally generated level?


The problem I face is that I do not know how I should light my level. I create basically everything dynamically at runtime with procedural generated meshes.

As you can see here, I have a room of a space station that I generated and the lights on the wall are dynamic lights that are spawned at runtime.


The nice thing about this is that it looks nice and I can adjust the lights one by one as it suits me. For example, if I wanted to simulate an outage, I can just disable the lights in the room.

But I did not realize HOW MUCH performance a dynamic light costs… just having as many lights as there are in the screenshot makes the game unplayable.
What could I do instead?

I tried using a stationary skylight and it illuminates the room alright, but it does not look as nice anymore and I can not adjust it during gameplay.


Is there anything else that I can do?
I thought about placing a lot of stationary point-lights all over the level and at runtime only turn on those that are inside a room. But that would probably look weird and would require hundreds of lights distributed in the level…

You’ll need to use movable spotlights and a movable skylight(not stationary.) Reduce the amount of spotlights by half and make sure their cones dont intersect with each other. The movable skylight will handle the dark spots(dont forget to recapture it every time you make a change with lights - even in run time.)

You can do that many lights, just make sure they aren’t casting shadows. As long as there aren’t more than 4 lights affecting a surface you can do a pretty large number of lights that don’t cast shadows.

You can try light function, this way 1 light can simulate 2-3. Or you can bake light intensity information into texture in max/maya, then use material with it as mask for emmisive channel.

For your game i would go with baked lights into texture per modular mesh. then I would make blueprints that have trigger and 1 dynamic light that is turned only when player is nearby (for shadows only), other lights would be faked with texture.

Ps. I am not sure but there may be method for baking all lights in unreal, then saving textures for use in runtime. This would give you most accurate results.

Thanks for the replies, I will post the results once I have tried it.

I think I will try darthviper’s method by disabling shadows and minimizing cone intersection, as it requires the least amount of work on my side ^^

The problem with a skylight is that it also illuminates the planet in the background, which should only receive light from the sun - is there a way to prevent that?

Also, I do not think that I can bake the lights into the texture, because each modular mesh is generated from a voxel volume at runtime (so in the above pictures, the room is constructed from about 10000 voxels).

If planet in background is background only you can make fake light material that is lit only from certain direction, and make whole planet unlit. Quite easy and cheap material. This way you separately can tune planet and level brightness. It also saves some resources.

Ok, here is what I did: I created a mobile skylight with a custom cubemap as light source (the scene capture did not work well because it had too much color from the nebulas in the galaxy). Then I changed my wall lights to point light with no more shadow and made sure that at most two lights can overlap with each other.

I also used Nawrot’s advice to create an unlit material for the planet - now the planet uses a layered material (daytime and nighttime) that is blended depending on the sun actor’s position in the game. If anybody is interested in it, then I can upload the material network.

This is the result, with a solid 120 FPS :slight_smile: Thank you!


Hi Cultrarius, I would be very interested to see your unlit material network - trying to do a somewhat similar thing to the shadows on that cube.

Thanks for any help.

Hey Doug,

sure, here is my exported layered material for the planet: (6.43 KB)
Kudos to ryanjon2040 who posted the original planet material here in the forum. If you want to see it in action you will need suitable textures for the planet, e.g. from here.

This is the blended material:

Note that it is unlit, so it only shows the emissive attribute from its layers. The layers (day/night) are blended depending on a vector parameter which represents the light source.

This is one of the layers, note that it only outputs to the emissive color attribute.

Thanks so much for taking the time to post this, really helpful! I have now got my emissive material working, my last question is how it affects meshes in your scene such as the cube. Do these have UV unwraps or is it all done dynamically from the emissive skybox?


I do not know if I understand your question correctly, but my mesh is not affected by the emissive material of the planet. I think the only way that an emissive material can affect the world is if it is used together with the Light Propagation Volume, which I do not use. Otherwise the emissive material can not affect dynamic actors such as in my scene.
It is however visible in reflection captures and screen space reflections on metallic surfaces.

OK makes sense, thanks again.