Best way to do and script day/night cycle

Hi

What is the best way to do “day/night cycle” with lightmaps for models in Unity.

(maybe) Have one light for the sun and maybe 3 different sky boxes - but what about the lightmaps on second UV for each model - would these have to be updated too and would this not be very slow?

I have started playing around with this with the new simulator I am working. I am able to change the skyboxes etc. but I would like to know how to fade the skyboxes into each other instead of using the cheesy trick of having a player drive through a tunnel and trigger the change that way.

Plus, we are using clouds and I have a sad hack that is changing the alpha channel values on each of the materials, this is really ugly and would love to hear some other solutions or ideas.

Wiki has Unity 1 shader for skybox that blends from one texture to another:

I haven’t tested the shader in Unity 2, but it should be possible rewrite if it does not work.

Another option is to use a shader that handles multiple textures. One is used to darken the sky by changing the alpha.

In Lies and Seductions (www.liesandseductions.com) we did change from the day to night using texture animation. It is bit heavy and you can see the steps, but for some reason we didn’t go for either the above solutions. The source code of Lies can be downloaded at www.mlab.taik.fi/~plankosk/blog/?p=308

I am giving it a shot now. No issue have shown up yet.

Just need to make a nice night time skybox. :slight_smile:

Then have a script manage the blend based on a time value.

Danke!

I will post a sample project when I am done.

Question?

How can you access the Blend of a Shader in a non assigned Skybox?

I assigned the Skybox shader to the RenderSettings Skybox. Is it possible to modify the Blend value when it is assigned into the Main Project’s Render Settings Skybox?

Suggestions?

Haven’t test this, but you could try:

public Material skyboxMaterial;
...
skyboxMaterial.SetFloat("_Blend", blendVal);

Attach (in inspector the) the material to skyboxMaterial that you have attached to “Skybox Material” in Renderer settings.

I have a day/night script used in conjunction with the blended skybox shader in the wiki - just access RenderSettings.skybox

RenderSettings.skybox.SetFloat("_Blend",(time+1.0)/2.0);