Post news RSS DevBlog #2 – Unity 5 DynamicGI

Developer Blog about dynamic GI in Unity and toggling emissive lights.

Posted by on

We switched over to Unity 5 fairly early on in the development of Cave In. This was due in large part to the new PBR system and dynamic global illumination. Over all we’re not doing anything too fancy with the usage of dynamic global illumination, but the first section of Cave In involves getting some generators up and running to get the lights back on.

Turning all the lights and having nice global illumination would have been a bit tricky in Unity 4.6 as it would have involved having to switch between lightmaps. In Unity 5 we can just switch the lights on and off and it just works… mostly. I ran in to a problem recently when I was trying to implement the level light controller for handling the switch between lit and unlit.

We have 3 different light models in the first area and 2 of them have a physical light component attached. The third light model makes use of the emission property of the standard shader. I’m using PlayMaker to control the individual lights and do a simple material swap for On/Off states of the light model object as well as toggling the light component for the two that use one.

Testing the physical lights worked as expected, but the emission material was not updating the lighting when toggled On/Off. After doing some research I manged to resolve the problem.

Unity DynamicGI API

For performance reasons the DynamicGI system in Unity 5 doesn’t constantly check to see if there have been changes automatically. In order to get the lighting to update I had to manually tell the system to do so. I could have written a custom action for PlayMaker (which I’ve done for various other things), but ended up writing a simple utility script that PlayMaker calls to upon toggling the light On/Off.

The above PlayMaker action calls the UpdateMaterial method in my UpdateMaterialGI utility script. The script itself is pretty simple and straight foward and utilizes theDynamicGI.UpdateMaterials method which invokes the DynamicGI to do an update. The below script is attached to the GameObject that contains the renderer component I want updated which in this case is the light model.

Post a comment
Sign in or join with:

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.