Download

[WIP] A new time of day blueprint

Hi,

I’ve been learning blueprints in Unreal Engine 4 and they’re fantastic!! It’s amazing how quickly you can get prototypes up and running.

Anyway, I’ve specifically been trying to create a more “full featured” time of day system for an open world game idea I’ve been toying with.

It’s still in early days but the features so far include:

  • A fully customization calendar system that keeps track of the current game second, minute, hour, day, month and year. Great for scheduling events to run at certain times of the day, or months of the year etc.
  • Fully dynamic sun and moon lighting as well as static ambient lighting (skylight). However the mechanics of the blueprint ensure that only one dynamic light is ever active at a time, for performance reasons. So if both the sun and the moon happen to be visible in the sky at the same time, the sun light trumps the moon light, obviously. When the sunlight fade out, the moon light fades in and the gap between the two is filled solely with the ambient lighting. So far this system seems to work well but I still need to fine tune the curves of all three lights.
  • Proper moon phases from full moon to new moon. The moon phase also affect the amount of moon light in the world. Obviously a new moon doesn’t reflect any light into the world.
  • User definable latitude and longitude of the world which affects the orbit of the sun, and a separate set of controls for the rotation axis the the moon and the orbit speed of the moon. For example you can set the moon to complete two orbits in a day or whatever you like.

There is still a lot to do such as the sky coloring and of course clouds. I have done some preliminary work on the cloud system but it’s still very early days and the cloud layer was switched off in the video below.

The goal is to make a nice looking “default” time of day system that also allows for a lot of artistic control if needed.

At the moment it’s a bit of a balancing act between curves and algorithm to control everything.

Ideally I’d like to get everything working as defaults purely with algorithms and then just use curves for artistic overrides, but I’m not quite at that stage yet.

Anyway here is a very rushed video showing some of the features so far. Apologies for the quality of the video. I was really rushing it to keep the video size down because I have an absolutely terrible upload speed and didn’t want the video getting too large.

https://youtube.com/watch?v=vm5pvNmB3eg

This looks really sweet.

got some comments:

The moon default is way bigger than the sun, looks a bit weird for me.
Your time scale goes from 1-100… why not 0-24? Just fix it with math.

Just nitpicking… this is really awesome

Thanks for the feedback. You’re absolutely right about the scale of the moon. I’ll shrink it’s default size.

The time scale (start time percent) just defines the time of day that the level starts on and is a percentage of the user defined length of a day which may or may not be 24 hours. That’s why I didn’t want to have a 0-24 slider but I take your point.

Whilst I’m aiming for a fairly realistic earth type of system as the default, I also want to keep thing flexible enough to create alien/fantasy styles as well which might for example have a 6 hour day and a really large moon etc.

Aaah… you think faster than I do, everything is accounted for :slight_smile:
Can you make the range of the slider dynamic to fit the length of day slider? Hmmmm.

Can you scale the sun?

I really love it

That’s what I first wanted to do but I couldn’t find a way to dynamically change the range of one slider based on the value of another slider. I ask about this over on AnswersHub but got no replies.

Would you know how to do that by any chance?

Sort of. At the moment it’s using the built-in Atmospheric Fog so you can sort of make the sun look bigger by increasing the bloom on it, but not the same as the moon. I’ll probably work on that at some stage.

What I’d really like to do is write my own sky/atmosphere shader as this would give me more options but I’m not that skilled yet :slight_smile:

Beat me to the moon i was planning on examining this benchmark and implement an environment system with a similar look and effect.

https://youtube.com/watch?v=muFYAF0M46I

I’ll be subing to this.

We seem to have lost a bunch of posts from the last day or so on this thread :frowning:

Whoa, yeah, we lost a ton!

Yeah, apparently there were server problems last night: https://forums.unrealengine.com/showthread.php?10781-UE-Forums-Outage-Data-Loss-Incident-Today

Not sure if you got my post from last night, where I explained the approach I’m taking with with keep track of in-game time and the cycles?

If not I will post again later on.

This looks really great! I’d love to see some documentation/tutorials or maybe source files later on whne it’s ready.

Hi icannotfly,

I whipped up a simple gizmo in my blueprint that helps me to better visualise the orbits of the sun and moon around the world with respect to the latitude and longitude. I’m more of a visual person and struggle to work purely in code :slight_smile:

Whilst I have reasonable understanding of the real world sun and lunar cycles and how that translates to the path of the sun/moon across the sky and the phases of the moon etc, I’m still really struggling to translate all of that into a game world where the sun revolves around the world instead of the other way around.

As I understand it (which isn’t very much) the two main aspects I have to play with is the orbital axes (I think that is the correct plural for axis) of both the sun and the moon. In theory, by rotating these axes over time in the correct way I should be able to simulate both the real world tilt of the earths axis in relation to it’s rotation around the sun, and I should also be able to simulate the phases of the moon. I also added an option to lock the phase of the moon to the position of the sun (rather than just having it manually set by the user) so that I could experiment with the above theory.

Does all that sounds like a reasonable assumption to you? Is that basically what you are doing?

I was planning on looking at your code again but sadly we lost it last night :frowning:

I also added the option to change the pitch on the moon phase (when in manual mode) which someone else commented about a while back. Sadly I cannot remember their name and that post was also one of the casualties of the server outage.

https://www.youtube.com/watch?v=J8IxQ8eT_8A

Wow, so much awesome stuff in this thread.

Whoa, that’s really awesome! How did you draw the shapes themselves, models? I wanna make something like this now.

Yeah, going from heliocentric to (simulated) geocentric was the hardest part for me, too.

Yup, as far as I can tell that’s correct. It’s not going to be accurate in an astronomical sense (can’t use it as an ephemeris, for instance), but it will be pretty **** close.
I’ll repost my code from earlier, but I’ve lost the explanation that went with it. Did anyone else subscribe to this thread? If so, could you try “restoring” some of the old posts from the subscription notification emails?


FRotator AicnfrpgSkyController::CalcSunPosition()
{
	FRotator SunPos;
	FVector SunEquinoxPath, SunAxialTiltWobble;
	float SunAdjustedLatitude;

	//TODO: move these to WorldSettings
	float LocalLatitude = 45.f;
	float PlanetAxialTilt = 25.f;

	float ToY = WorldTimestampPtr->ToY;
	float ToD = WorldTimestampPtr->ToD;

	SunAdjustedLatitude = 90.f - LocalLatitude;

	SunEquinoxPath.X = -1 * cos(SunAdjustedLatitude / 180.f * PI) * (cos(ToD * 2.f * PI));
	SunEquinoxPath.Y = -1 *                                          sin(ToD * 2.f * PI);
	SunEquinoxPath.Z =      sin(SunAdjustedLatitude / 180.f * PI) * (cos(ToD * 2.f * PI));

	SunAxialTiltWobble.X = cos(ToY * 2.f * PI) * cos(SunAdjustedLatitude / 180.f * PI) * cos(PlanetAxialTilt * 180.f * PI);
	SunAxialTiltWobble.Y = 0;
	SunAxialTiltWobble.Z = cos(ToY * 2.f * PI) * sin(SunAdjustedLatitude / 180.f * PI) * cos(PlanetAxialTilt * 180.f * PI);

	SunPos = (SunEquinoxPath + (SunAxialTiltWobble / 2.f)).Rotation();

	UE_LOG(TimeSystem, Verbose, TEXT("EquinoxPath: %s | AxialTiltWobble: %s | SunPos: %s"), *SunEquinoxPath.ToString(), *SunAxialTiltWobble.ToString(), *SunPos.ToString());

	return SunPos;
}

I’ll look through the UE3 code, too, to see if there’s anything interesting in there.

Yes the shapes are just simple models I created in Max.

Thanks for posting your code again. I will try to figure it out and replicate in blueprints this weekend.

Unfortunately I deleted a bunch of old emails (including previous posts form this thread) just prior to the server outage so I don’t have your previous explanation, nor mine for that matter.

Let me know if you want me repost anything about my blueprint set up and I’ll retype it.

It was quite interesting going back through parts of the blueprint that I put together weeks ago and trying to figure out exactly what I was doing at each step, and trying to remember why I did it that way.

Hi mrpdean. Congratulations on the project, is getting amazing. You are creating a plugin? We will have video tutorials teaching you how to create something like this?

Not sure about creating a plugin as I don’t know c++ much yet. At the very least I’ll release it as a ready to use blueprint.

Do you have a prediction for When will release?

Você tem uma previsão de quando irá liberar?

Unfortunately no. I haven’t had a chance to work on it since posting the last video due to other projects, but I hope to get back to this very soon.

Will keep you updated on progress via this thread.

Thanks.

OMG! I need this in my life and my game NOW! Do you have a rough estimate on if/when you are releasing this? I would just love having the basics with the moon included but the extra features you implemented are pretty eye popping as well. Bravo mrpdean really bravo!

Just wanted to show interest, this looks really awesome and I would love to see how you set up the blueprint.