Implementing Day/Night Lighting in 2D

Hi all,

I’ve been looking into implementing Day/Night lighting in a game I’m working on. I have a basic proof of concept but was hoping to get some recommendations for improving simplicity/scalability.

The way I’m implementing it currently, I have a sub-graph which takes in texture/normal info as well as data about the sun (direction, color, etc…).

This gets added to whatever material needs to be lit and works pretty well:
8156591--1060055--DayNight.gif

My concern is mostly with scalability. This requires that I update each material that needs to be lit or implement some sort of messaging for objects with instanced materials.

I’m very new to shaders and graphics in general, so it’s likely I’m missing a simple solution. Some of the other things I’ve tried are.

  • Using a Freeform light at an arbitrarily large distance with no falloff (This is promising, but wasn’t sure how it would look with camera movement)
  • Using a post-processing blit (I could not figure out how to pass normal map data to the shader if that is even possible)

Any suggestions to improve this would be appreciated. Like I said, I’m pretty new to this, so it’s likely I’m just completely unaware of a simple solution here.

You may play with post-processing to make a day-night cycle, I’m pretty sure it will be more convenient to use.

I had seen that one. It seems pretty close to what I’d want to implement as far as the overall lighting goes. But I’d also like to give a feel for the sun’s direction using the sprite normal maps, which it doesn’t look like he covers here. Any idea if it’s possible to implement something like that?

You can un-expose your SunDirection variable. That will remove it from the material properties UI, but will allow you to set it as a Global Property using Shader.SetGlobalVector - that way you only need to update it once instead of updating it on every material. :slight_smile:

2 Likes

That was exactly what I was looking for! Thank you so much, that works perfectly.