Wednesday, April 8, 2015

Why not to use Baked GI in Unity3D

Originally, we knew nothing about lighting. We controlled all scene lighting with ambient light. Later I read about Unity's deferred lighting path. http://docs.unity3d.com/Manual/RenderTech-DeferredLighting.html  Because we have several rotating spotlights that need to shine in real time, the cost of each light and what it hits is linear with deferred lighting. That is legacy lighting now because Unity has replaced deferred lighting with deferred shading. http://docs.unity3d.com/Manual/RenderTech-DeferredShading.html

For a while, we tried to make Baked Lightmaps. These were supposed to give us some lighting for "free" at the cost of having to bake them a bit beforehand. We set up light probes around the scene for animating characters and objects. Firstly, those baked lightmaps took around 100mb of storage, which we were storing with git. That got quite bloated and made our git repo start to push it's 1 GB (GitHub imposed limit on a repository) limit. When we upgraded to Unity 5, we noticed several dumb things we were doing. For instance, we had two directional lights in opposing directions. Directional lights have no starting position, they just start from the outermost edge of your scene boundaries and extend to the other. This was how we did it for about 2 years because we were focused on coding up a better experience rather than the visual appearance of the room. We wanted to take advantage of the new Global Illumination, so we needed to use real indoor lighting instead of directional lights.

Once we upgraded to Unity 5, we noticed that the majority of our lighting was not taking advantage of the Global Illumination. We did a complete revamp of our lighting. Firstly, we removed our directional lights and replaced it with a chandelier that had one point light and an emissive material. When we went to use our Baked GI, there were horrible splotches. I tried increasing the resolution, changing the materials, turning on Final Gather. Usually one thing would fix and another would break. I decided to turn of Baked GI and go only with precomputed realtime (essentially it bakes the paths the light will travel, but that is all).  Because of deferred lighting, we haven't noticed any issues, and now we can bake the precomputed light path in only a few seconds

We're going to need to see how it works on the crappiest laptops, but we won't be going back to Baked GI. Look forward to seeing you in Club Consortya (Preview) releasing summer 2015.