Lightning setup problem for a planet with day cycles - what approach should I take?

I have a planet in the middle of the screen from UFO-like perspective, which I currently am lighting up with 4 directional lights, that rotate 360 degrees to give the planet a day/night cycle. One white light for daylight color, one blue tinted one for night facing opposite direction, then one orange for evening and one light blue for mornings.

Problem is, that because of the nature of directional lights, every building on the top of the planet will be getting lightning from the light sources “behind” the planet, thus, during the day, the night light is casting light at the bottom of the buildings through the planet. This can be stopped by making every light cast shadow, and the planet will then block the light completely. If I do that though, the buildings will be casting lights 4 time during the cycle, resulting in every lightsource swooping the shadowcycle of the objects from the start again and again. Only the day light “sun” should do that.

Nature of the directional lights is like this so I am wondering how to approach the situation. Spotlights arent really a valid choice to lighten the planet evenly. With only 1 directional light, the colour scheme of the night cycle is simply too bland, and player also needs to see during the night partions of the planet too.

Of course, one could be if I had a check for player camera position, and have the light dimmed that is on the other side of the planet. Hmm.

As a test, using null objects and “has been rendered recently” node I was able to turn the lights off when they go behind the planet.
This works when I am zoomed away from the planet and look it from a distance, the lights that are behind it blend out nicely (via timelines) and dont cause issues. Smooth.

Problems occur when I zoom in to the close distance, so that whole camera is filled with terrain, then all nulls are not in vision thus all lights go off, even though the lights at the same side of the planet as the camera should be still casting light, they dont since they are behind the camera.

Hmm back to the think-tank!

Some screenshots would help.

Maybe you can change the lighting channel of the buildings at runtime based on the camera position.

To turn off lights i would have used a direct line trace from the camera to the direcrional light.
its not very accurate/ you don’t get halos from it slightly dipping behind the planet, but turning it off based on its direct “visibility” is not a bad idea.

Another more expensive (performance with 4 lights and dynamic is already bad) solution that costs way less in time would be to set a sphere inside the planet that blocks the lights from getting through to the buildings.

The real issue is probably the same as we get with landscape and foliage. More often than not, that’s handled with a very large light blocking box set up under the terrain.
Thats because simply dimming the light is some times not enough.

So this is the planet. Its made from 3d objects and doesnt use landscape. You can rotate the camera all around it, and zoom in and out freely. It should block the lights behind the planet during day/night cycles.

If I zoom in a lot to demonstrate how light goes “through” it, it looks like this. The buildings and foliage are catching blue light they shouldnt now. The light comes from directional source, and thus is not “behind” the planet in reality, so the objects just catch light from that direction.

If I toggle the shadows on to all the lights, the blue will be blocked, since now the globe is in the way of the objects, and these wont be receiving light anymore, being in its shadow.

But as said, doing that will cause shadows to go from east to west multiple times a day, when they should only do so once.

As you said that performance with 4 lights is bad, are directional lights (without shadows) really that expensive? Ive found dynamical point lights with large radius and shadows being the expensive light source, not directional ones without shadows?

“Another more expensive (performance with 4 lights and dynamic is already bad) solution that costs way less in time would be to set a sphere inside the planet that blocks the lights from getting through to the buildings.”

I am kind of already trying that, as the sphere that blocks light should be the water layer of the planet, but since the directional light doesnt cast shadows, well, the sphere/planet will not block anything. The directional light is not really behind the planet, as it just casts light to desired direction and doesnt take position of itself into account.

Not sure on your approach.

But let me ask you this. Why not rotate the planet and keep the light constant instead of playing with many lights?

If you rotate the camera around the plant, the rotation of the planet itself shouldn’t matter / it can revolve freely and get lit naturally by 1 directional light.

Good question, but this was an issue I quite fast figured that its better to not rotate the planet. There is 1000s of dynamically made objects on it, 100s of skeletal meshes following different splines, and even 10s of different levels made for spawning foliage under different conditions. Rotating foliage etc. real time is really not an option, when the desired visual effect of day/night can be accomplished with just simple light rotation. Which, is not thaaaat simple after all, but still more manageable.

I can get it lit naturally with 1 light in this approach as well. The different lights are just for atmoshphere, colouring the evening/morning parts to be visually more intresting than 1 simple sunlight with ambient for night would do. I also have the cities lighted up during night via dynamical material changes to emission maps and point lights, but thats an different thing and doesnt really change here.