Day/night switch – unity3d lightmaps switching made simple and easy
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: http://youtu.be/YWLBMqY2SRQ.
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.
Leave a Reply
You must be logged in to post a comment.
Very nice article, thanks !
I’m just wondering, isnt the change of lightmap a bit abrupt ?
Doesnt seem smooth to me. Am i wrong ?