Easiest Way to make a "Night" time scene?

Hello, I am wondering if there is a quick or sensible way I may not be thinking of, to make a night time scene.

I want my scene to go from day to night in a sequence, which is currently does and works well, but at night the Earth is pitch black. I want to go for the look that there may be random lights on scattered across the land and for cities to light up. (I know this can’t be texture perfect [or can it?], but perhaps line the city with a material that is multiple windows and some are lit up.) I am viewing the city from a distance, so it does not need to be perfect. [Using Aerometrex Denver here]

Is there a means of adding this in and then having a fade transition to night time using sequencer?

Thanks!

-Brandon

Hi @VirtuosoCEO,

I’ve been wanting to try this out for a while so I experimented a bit. I’m pretty sure this is quite doable with the right material. That being said, you may not consider this solution quick or sensible :slight_smile: I created some materials and summed up my thoughts below. It’s by no means a perfect solution and could use a lot of work, but it may be suitable from a distance. Hopefully what I’ve written below is a good jumping off point to help you build what you need.

Overview

I created a material that adds procedural windows to tilesets. It’s pretty rough and could be improved in a lot of ways.
Here it is on the Denver tileset:

And here it is on OSM buildings:

Note that in my scene I have an additional directional light with an intensity of 0.4 lux - this might be a moon or other ambient light, but you’ll probably want at least one light source to turn on at night.
There is also a Post Process Volume with these exposure settings:
image
The Post Process volume is set to Infinite Extent. The Post Process volume is important for controlling the automatic exposure of the scene to make sure it isn’t too bright or too dark. You can read more about post processing volumes with Cesium here.

Procedural window material details

This material is largely based off of the grid material in the Cesium for Unreal Samples. That material creates a grid based on world position. The window material will do something similar, but inverted.

The Cesium for Unreal Material Editing tutorial might be helpful if you’re looking to learn more about material concepts with Cesium for Unreal.

Material Instance

The material instance is very simple. It uses a custom Material Layer and Material Layer blend, which are explained below. The Material Layer has a lot of parameters that can be tweaked to adjust the look and size of the windows.

Modifying WindowBrightness would let the windows appear to fade in over time, though depending on the light levels of your scene, you might not even need to animate this.

Material Layer

The material is a modified version of ML_CesiumGrid found in the Samples. The parameters you saw on the material instance are defined here. There are three main parts of the layer.


First, the windows are created with a Material Function named MF_Windows (that will be detailed in the next section.)


These nodes allow you to control the brightness and color of the windows. The color could be set to white, but I found yellow was just a better look.


The WorldAlignedBlend node is used to make sure the windows don’t appear on the tops of buildings or on the street. On horizontal surfaces, the window pattern will be replaced with black.

The output of the Lerp node is connected to the EmissiveColor of the material attributes.

Material Function


MF_Windows is a material function modified from MF_GridLines in the Samples. While MF_GridLines uses only the R and G channels of Absolute World Position for a horizontal grid, MF_Windows also uses the B channel. The R and G channels are multiplied by the WindowProportion input. When WindowProportion is set to 1, the windows will be square. Values lower than 1 will make vertical windows.
It also inverts the grid.

Material Layer Blend


The MLB is pretty straightforward. It multiplies the Emissive color of the Material Layer by the Base Color of the tileset. You could skip that altogether and just connect Emissive Color of Input Top layer directly to Emissive Color of the output, but multiplying by the base color might produce some nice variance.

Next Steps

As mentioned above, there are a lot of ways this could be improved. If you decide to try this out and see how you can improve the material, please let me know how it goes!

Limitations of the procedural window material

  • The windows are very uniform. You might be able to get some good variation by multiplying the window effect by noise textures, but it would likely involve a lot of tweaking to get it to look good.
  • The material has no awareness of what a building is, so windows might end up in odd places like trees, the sides of hills, and steep roofs.
  • The grid is world-aligned and world space. What this means functionally is that depending on the shape and orientation of the building, there may be visual issues like weirdly narrow or wide windows, windows that change shape along the building, or no windows at all. For example:

    One building in this image is on a slight slant compared to the world grid, so the left side of it is in a position where the “window padding” is, and appears to fade off. Further to the left, a side of a building is completely inside of the window padding, so no windows render at all.
    Photogrammetry might work better or worse with this, depending on it’s LOD and how it is triangulated.
  • Faraway windows may create flickering effects due to aliasing.

Lights on the land

You also mentioned wanting lights scattered across the land. One low-res but fairly geographically correct solution could be to use the Earth at Night imagery to drive the emissive channel of a material.
I tested this out and it works ok, but it’s so low res that it might not be useful to you.

You’d need to add a new Ion Raster Overlay to Cesium World Terrain. Set the Ion asset ID to 3812 and the Material Layer Key to the name of the material layer that you’ll be modifying.
From high over Colorado you can see it brightens up the areas near cities.


Up close, it’s not very precise, and some hard edges between pixels are visible.

Material Instance:

Material Layer Blend:

I hope this is helpful to you in some way - let me know if you have any further questions on this. I’d love to improve Cesium for Unreal’s night lighting.

-Alex

4 Likes

Wow, you are an absolute stellar legend for this. Thank you so much.

I will get on this and return with feedback and a video!

Thank you so much!!

1 Like

@agallegos So, I have finally gotten around to making this and I have to say, it is amazing! Thank you so much for this detailed explanation.

I never really messed with material layers in UE4 at all and I learned alot from this tutorial, as well as how Cesium can use this system very efficiently well.

Very cool. I have a sweet effect going so far that I wish to share, but before I consider this done, I have one more question:

Give this Scalar Parameter “Brightness” is in a blend asset and not the actual Material itself, how can I drive this parameter through Blueprint?

Thank you so much,

-Brandon

Hi @VirtuosoCEO,

Glad to hear this is working for you! I’d love to see what you’ve made.

You can move the “Brighness” parameter to the Material Layer, rather than the blend asset. I’m not sure if that will make it more accessible to blueprint or not. I’m not finding much info in a preliminary search, but at least in the Material Inspector, the parameters in blend assets and material layers are editable on the instance.

Have you tried to set the parameter with blueprint as you would a normal material?

-Alex

Hi there we are also trying to make the night scene lit enough to traverse, still keeping the feel of night but not losing visibility.
Is this still the most viable way of doing so?
Thanks!

Hi @MQS,

I think this is still the most viable way. CesiumSunSky renders pitch black at night, which we’re aware is confusing / unideal for a lot of users. Based on forum posts, I’ve written a Github issue for adding some sort of ambient nighttime lighting; feel free to chime in there if you have any other suggestions relevant to your use case!

Hi there, I have managed to built the whole scene and I have the C OSM buildings in my level without the blocks I don’t need. I have added my geometry and everything is looking great so far but the only issue I am having is adding the Metadata component to apply the windows materials. I have followed the main guide with the NY building example but tbh I am lost after that. I am following the Cesium for Unreal scene trying to rebuild mine like that but I am not sure what I ma doing now, do you have any advice on how I can setup the CesiumEncodedMetadad component properly? Thanks

Hi @Enzo_Luka, welcome to the community.

Have you seen level 10 in the Cesium for Unreal Samples project?

I think it does what you’re describing, including lit windows at night if you change the Solar Time property on the CesiumSunSky. You can take a look at how that is put together and even grab Materials and other resources from it as needed.

1 Like

Hi Kevin thanks a lot, it really helped. But you solve one issue and then encounter a new one. The challenge I have now is that once I applied the window material the clipping removing the blocks I don’t need in the scene seems not working. I wonder if there is something I need to add in the material layer? hope this make sense. Thanks again.

Might I also add that a great video tutorial series to follow for making a night sky to go along with the night side globe discussed here can be found by looking for insertnamehere game dev’s series on day/night cycle for UE5.
It will get you everything, including a highly editable moon as well as teach you what all those settings do. You can expand that to give Earth multiple moons and suns if you felt like it.

I applied the techniques there to extend the cesium sun/sky. I skipped the day/night cycle timer as I am using real time or a fixed time for what I’m doing right now.

I am in no way affiliated with the author of the video tutorial.

Here is the first one:

The challenge I have now is that once I applied the window material the clipping removing the blocks I don’t need in the scene seems not working. I wonder if there is something I need to add in the material layer?

The example material in the Samples project doesn’t have a “Clipping” layer. If you open up the MI_ProceduralWindowsMetadata material instance from the Samples and look at the “Layer Parameters” tab, you’ll see this:

So this material incorporates a base glTF (Background), a single raster overlay (Overlay0), and the window effect (Windows).

Compare that to the default material used to render tilesets (MI_CesiumThreeOverlaysAndClipping), which looks like this:

That top layer labeled Clipping is the one that is missing from the windows material. If you add a layer just like that to MI_ProceduralWindowsMetadata, you should be in business.

Unreal’s material system, while extremely powerful, is a bit inflexible in that it allows very few changes at runtime. So that forces us to either have giant materials that do everything and run fairly slowly (and inevitably run into shader limits on certain hardware), or have an exponentially growing number of materials for all the different combinations.

Instead of going down either of those paths completely, we try to make most things work out of the box, and we try to make it easy for users to do more unusual things (like add windows) by piecing together layers. That’s what you’re seeing here. This tutorial is the best overview of how the material system works:

1 Like

@Kevin_Ring Thank you so much for your explanation. I really appreciate it—I can’t believe it was that simple!