UE4 | Cycle day and night | SkySphere modification

  • Tutorial
The change of day and night often rises among users. And if by itself the movement of the sun is quite simple to organize, then it is much more difficult to achieve a more or less realistic work *** SkySphere ***.

In this article, I do not plan to show all sorts of ways to change the orientation of DirectionalLight with the seasons and precession. On this topic, in my opinion, there is enough material. Someone does this through Blueprint , but I use C ++ , so that the clock ticks on the server and periodically (once every few seconds) synchronizes the client's clock. In this case, no movement occurs on the server. Not a lordly thing, moving the sun across the sky.

Next, I will talk about emerging issues and show my version of upgrading the standard BP_Sky_Sphere to work correctly with the daily cycle.

Before modification, it will be quite useful to copy the entire contents of the EngineSky folder into your directory, so as not to spoil the standard Blueprint and the resources connected to it.

First of all I want to talk about the bug (or features) of the standard sphere. Attached StaticMesh for a sphere has a scale of 400. If you change it to 1, it seems that nothing will change, but if you run a little ahead you will feel like in the movie “The Truman Show”. Yes, this sphere, though huge, has its limits. An obvious problem for open worlds, which is very easy to fix by forcing the sphere to move with the player.

Of course, as an alternative, you can make the sphere even bigger, but I don’t really like this idea.

The next item is setting up a normal night. I categorically do not like that the stars appear only at midnight, and the rest of the time - it's just some kind of long evening.

It is also quite simply solved by setting the existing curves and adding new ones.

Curve example

The next problem is light attenuation for DirectionalLight and SkyLight . It is strange to observe that at night you can see no worse than during the day. It is also solved very simply by adding and adjusting the curves.

Changing lighting levels

Well, for dessert ... The stars do not move! If the night is long and full of horror , then the player may not notice it. But we are for a serious approach?

First, I made the stars move by adding additional variables to the material.

Something like that

While the sun is moving along the equatorial plane, everything is in order. But when imitating high latitudes, mathematical complexity begins and the reluctance of the texture to curl as we like. But we are for a serious approach? :)

In the end, I decided to make two celestial spheres. One with clouds, the sun and the sky, and the second, a little larger, with stars. I connected the additional sphere to the same BP_Sky_Sphere and politely asked it to rotate with the sun ...

And the most interesting part! Make the smaller celestial sphere partially transparent. Just by connecting the logic of the material to the Opacity , of course I got wonderful stars shining through the black night clouds. Therefore, again I had to modify the material with a file, actually drawing two skies. One with black night clouds for visuals. And second, with always white clouds, for Opacity . Plus he added many, many whites during the daytime, actually making the sky opaque, so that the translucent blue does not frighten with its depth.


The picture is clickable


Now everything works as intended by the Creator, in this case by me. It remains only to fine-tune the control curves, but overall it looks pretty good.

If you have an idea how to make it easier, please share it. I will be grateful.

Also popular now: