Day/night switch – unity3d lightmaps switching made simple and easy

Posted by admin on July 10, 2014 in Unity3d |

I have recently made a research on day/night cycle Unity assets. There are plenty of them both commercial and free.
The most interesting and advanced one can be seen on this demo:!/content/5674
and one of the free ones based on runtime shadows and skybox transitions can be found here:

However there were no free assets based on unity3d lightmaps switching or transitions at runtime.
Instead I have found a LightMapSwitcher script on wiki and that was the starting point.

A case was I had two scenes: a day one with day lights  and day lightmaps and a night  with night lights and night lightmaps. The lightmaps have to be baked with the lock atlas option.

I packed everything into three streamed scenes:

  • a loading scene with all the scripts
  • a day scene with all the models and day lightmaps and day light and
  • a night scene with night lights and lightmaps only

The day/night switch swaps the lightmaps and sets the appropriate lights active or inactive.

The setup has also involved some tagging job. I have tagged all the day specific objects from the day scene with the “day” tag and all the night specific objects from the night scene with the “night” tag.
I have also tagged all the models in the night scene that go exported with the first scene with the “EditorOnly” tag so they won’t be exported again, leaving only the lights and the lightmaps container.

Once the first scene loads, the download of the second one starts on the Start function of a DayNightSwitch script and the “day” tagged lights get collected into the dayObjects array.  The camera data including the skybox, fog, and background color has to be collected into 2 elements camera settings array for later switching. Once the night scene loads a DayNightSwitch script just supplements the night lightmaps in the LightMapSwitcher component, nightObjects array, night camera settings and the day/night switch can get enabled.


unity3d lightmaps switching

1 Comment

Leave a Reply

Copyright © 2011-2024 virtualPlayground All rights reserved.
VP based on Desk Mess Mirrored v1.8.3 theme from