Unity 5 Mobile Lighting Optimization

  • lighting-demo-62
  • lighting-demo-61
  • lighting-demo-60
  • lighting-demo-59
  • lighting-demo-58
  • lighting-demo-57
  • lighting-demo-56
  • lighting-demo-55
  • lighting-demo-54
  • lighting-demo-53
  • lighting-demo-52
  • lighting-demo-51
  • Lightmap bake failed
  • lighting-demo-49
  • lighting-demo-48
  • lighting-demo-47
  • lighting-demo-46
  • lighting-demo-45
  • lighting-demo-44
  • lighting-demo-43
  • lighting-demo-42
  • lighting-demo-41
  • lighting-demo-40
  • finished lightmap
  • lighting-demo-34
  • lighting-demo-33
  • lightmap
  • lighting-demo-38
  • lighting-demo-37
  • lighting-demo-36
  • lighting-demo-35
  • Suppress lightmapping task priorities
  • lighting-demo-29
  • lighting-demo-28
  • lighting-demo-27

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:

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.

lighting-demo-27 lighting-demo-28 lighting-demo-29

( 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.

Suppress lightmapping task priorities

Suppress lightmapping task priorities


lighting-demo-35 lighting-demo-36



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.





lighting-demo-33 lighting-demo-34

Non directional GI settings


finished lightmap

finished lightmap


lighting-demo-40 lighting-demo-41

Still slow, hrm, looks nice though =)



Profiler.  Lots of time in EnlightenmentRuntimeManager.UpdateEnvironmentalLighting


lighting-demo-43 lighting-demo-44

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





Lightmap bake failed

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.


lighting-demo-54 lighting-demo-55 lighting-demo-56

Console, saving lightmaps



Unity lightbake Nom nom nom SSD drive again.  Fix with NTFS junction to my RAID.


lighting-demo-58 lighting-demo-59 lighting-demo-60 lighting-demo-61 lighting-demo-62

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.

Leave a reply

Your email address will not be published. Required fields are marked *