Since what we know so far about coding Hololens in Unity might involve light sources, I threw together a little demo project to try to show off all the different lighting features in Unity.
To create the scene I:
- started with the Stonehenge asset from https://www.assetstore.unity3d.com/en/#!/content/32591
- added a reflecty sword in the middle https://www.assetstore.unity3d.com/en/#!/content/876
- and gave it a glowy emissive material sphere in the hilt, with a glowy particle effect to soften the edge and make it look more like a light and less like a glowing ball.
- then I followed the http://twiik.net/articles/simplest-possible-day-night-cycle-in-unity-5 implementation
- finally, added some emissive materials to the clock and quickly had something that looked pretty neat
I put the camera on autorotate, hit play, and I quickly had a neat little really showed off what the lighting system could do.
Then I tried it on my low end Android tablet. Ugh.
( Pretty much the same deal on the galaxy s3 and Nexus 7 too )
Started to play around more with the settings to see if I can optimize the mobile experience. I dunno if everyone has this issue or it is something peculiar to my machine, it is a pretty beefy I7 desktop but for whatever reason complicated light map bakes with final gather kills it. It hard locked at one point requiring a hard boot. Even if it doesn’t lock up completely, not being able to use the machine and have the desktop be so unresponsive for upwards of an hour is kinda lame.
Unity spawns processes to occupy all your CPU cores, if you find these processes and set them to low priority fast enough you can get use of the machine back. The problem is that they finish their work and Unity spawns new processes to do the next set of work. You cannot set the priority of these processes ahead of time, at least that I have found, so I created a service that I can run that will just loop for 30 min looking for these processes to deprioritize. Whee.
With that out of the way, back to playing around with the lighting settings to see if we can get better FPS out of the Android devices.
Non directional GI settings
Still slow, hrm, looks nice though =)
Profiler. Lots of time in EnlightenmentRuntimeManager.UpdateEnvironmentalLighting
Testing performance impact of turning off realtime lighting completely
Better! But you want some realtime lighting for your realtime objects to cast shadows.
Ambient GI = Baked This seems to be important to reducing realtime engine load. But baked ambient light doesn’t let you update skybox lighting, so we can’t have a night day cycle if we bake the lightmap ahead of time… or maybe can we save the lightmaps and swap them out later? <= Does that count as baking a foreshadow… ? 😛
More Lighting settings
Looking good, performance not terrible
Doh! Lightmap baked failed (my SSD ran out of space ) Baking lightmaps is so much more resource intensive in Unity 5 vs Unity 4.
Profiler, not spending time in EnlightenmentRuntimeManager, hooray!
Setting the lightmap to ‘Custom’ and enabling ‘R/W’ so that it can be read into code and persisted somewhere else. Wired up the demo to swap lightmaps on click or when you hit spacebar or tap the screen.
Lightmap folder, saved for time of day. Initially I saved these as PNG but the texture maps do not translate well to different devices and changed to using raw format.
Console, saving lightmaps
Unity lightbake Nom nom nom SSD drive again. Fix with NTFS junction to my RAID.
Saved two lightmaps ( I am not doing the full day for the demo 😛 ) and toggling between them. The last one has the skybox / sun either just rising or just setting, but it is mapping the light map for the sun being further along the day. Weird effect having shadows at night, a full implementation would map every skybox position and swap out the lightmaps as the sun move through the day rather than just toggling between two states.
Looks good, performs well, seems like a win getting lighting to work on low end mobile. One could expand on this system and create a full lightmap manager that scans for and saves all lighting related settings alongside the baked light map, allowing you to toggle lots of different effects in realtime without the performance hits of the Enlightenment realtime engine. You could use a technique like this to make some emmisive materials pulse or flash for alarm lights, or allow lights in rooms to be flipped on / off, or any sort of change to the scene lighting could be lightmapped ahead of time.