Search Unity

How to get good performance with realtime lighting on mobile

Discussion in 'General Graphics' started by Vefery, Apr 27, 2019.

  1. Vefery

    Vefery

    Joined:
    Feb 23, 2018
    Posts:
    119
    Hi, I'm developing low-poly 3d side scroller on mobile. Now I have one realtime dir. light and both realtime lighting and mixed lightning disabled in lightning settings. Scene isn't big, no terrain, since it's low poly, every object use the same material, so everything batched. And still I can get 60 fps only on lowest settings in HD resolution. On medium settings in FHD (my phone's native resolution) fps drops to 30 and on Ultra with shadows and FHD it drops to ~25.
    But my phone had snapdragon 625, which is quite powerful CPU. I can run games such as CASE: Animatronics on Ultra with FHD, GTA SA in Ultra, etc.
    I don't use backed lighting because of size problem, the game suppose to have 50+ levels and baking light for every level wouldn't be effective.
    Does anyone have experience in developing realtime lighting mobile games?
     
  2. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,610
    Mobile devices are normally capped at 60 fps.

    Unless you want to turn the phone to a heater and drain the battery really fast, you should target 30 fps or lower instead. Newer phones feature something named thermal throttling, means if you run your game at 60 fps, it becomes really warm and then the performance is throttled to lets say 20 fps. Nothing you can do against, thus you want to avoid running in thermal issues.

    Running games at 30 fps or lower where possible it what mobile games often do. You still want to optimize the hell out of it to be able to run at 60 fps in theory, but then limit it to 30 fps instead. This way your game is 50% in idle and hopefully won't cause the device to heat up. Epic did this with Fortnite mobile, see video below.

    Lectures of interest...

    Starts at 12:13

     
    Last edited: May 7, 2022
    petey, anycolourulike and Vefery like this.
  3. BattleAngelAlita

    BattleAngelAlita

    Joined:
    Nov 20, 2016
    Posts:
    400
    Reltime shadows?
     
  4. Vefery

    Vefery

    Joined:
    Feb 23, 2018
    Posts:
    119
    Thanks for reply!
    I didn't mean that I want more than 60 fps, I want stable 60 fps on low-medium settings
    Also I've never seen 3d games capped at 30 fps, it usually runs at 60
     
  5. Vefery

    Vefery

    Joined:
    Feb 23, 2018
    Posts:
    119
    Only on the highest quality settings
     
  6. BattleAngelAlita

    BattleAngelAlita

    Joined:
    Nov 20, 2016
    Posts:
    400
    Realtime shadows and standard shader are most often cause performance problems on mobile.
     
  7. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    I've been doing mobile games since 2010 so some experiences:
    • baking lightmaps for every level is the correct way to do mobile. crunch and other compression strategies reduce lightmaps to almost nothing, especially if you use small lightmaps or light using lightprobes (saves even more).
    • transparency is OK on mobile but attempt to reduce overlaps (few big is better than lots of small) and ensure the shader for any transparent rendering is kept very, very simple - just vert/frag minimal.
    • Post effects should either be custom or made by yourself.
    • I did this app with full spec with my own pbr invention just by multiplying combined maps together with some made up math. Stripped down custom shaders are the best for performance. Vignetting is 4 meshes in the corners with vert colouring:
     
  8. Vefery

    Vefery

    Joined:
    Feb 23, 2018
    Posts:
    119
    Thanks for tips! Could you share your experience about lightmap baking? Because I've tried to bake level with progressive lightmaper, lowest settings, compressed lightmap and awful result, I've got 17mb lightmap. It's too big for 50+ levels game
     
  9. Vefery

    Vefery

    Joined:
    Feb 23, 2018
    Posts:
    119
    Forgot to mention - I use Mobile/Diffuse shader
     
  10. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,610
    Why don't you just connect a CPU and GPU Profiler to your game and let those tools tell you exactly what is causing this performance issue?
     
  11. Vefery

    Vefery

    Joined:
    Feb 23, 2018
    Posts:
    119
    Because it shows me that rendering image uses almost nothing, about 5% of all power. But in built I can see the opposite
     
  12. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,610
    Can you elaborate on this?

    You connect those Profiler tools to your game, that is running on the target device (phone) and it reports 5% is spent in "rendering image"? 5% where, CPU or GPU? Where are the remaining 95% being spent? Where do you get those "opposite" numbers from?
     
  13. Deleted User

    Deleted User

    Guest

    1. You should use legacy diffuse shader to optimize gpu, also don't use post processing.
    2. If is not gpu, try to get scripts optimized for cpu perfomance: try to use less GetComponent and GameObject.Find. Also comparing tags is less powerfull than GetComponent, so use it to check collisions. Try to kepp everything from Update in the FixedUpdate. Use get, set instead of checking value changed every frame.
    3. If there are many static objects, combine it to one mesh. The way i did it is using a fbx exporter to export fbx file of scene and then import it to blender and export to obj format. The less objects cast shadow, the more perfomance you get.
    4. If you are using physics, go to the project settings, then physics, optimize you layer collision matrix, for example if you have big triggers, that check triggerEnter only for same triggers, take them to new layer and make it don't collides with default layer. If you don't need very good physics quality, set world subbdivisions and default slover iterations to smallest value. Try to keep more colliders on static objects and less on rigidbody. Never use mesh colliders.
    5. Setup quality in project settings. Mostly shadows. This is my values:
    Pixel Light Count - 1
    Texture Quality - Full Res
    Anisotropoc - Disabled
    Anti Aliasing - Disabled
    Soft Particles - False
    Realtime Reflection Probes - False
    Resolution Scaling - 1
    Texture Streaming - False
    Shadowmask Mode - Shadowmask
    Shadows - Hard Shadows
    Shadow Resolution - Medium
    Shadow Projection - Close Fit
    Shadow Distance - Set here the less value you possable, i have 27 because of top-down camera, and you can have performance with not bad realtime shadows.
    In other
    VSync - False
    Other values are default on lowest settings.
    6. Setup Player Settings - Other
    If you dont have to many objects - disable dynamic batching.
    If you use new version of unity, then enable Graphics Jobs (Experemental), i don't know what is it, but i hear you should enable it to speed up your game.
    Set scripting backend to IL2CPP
    7. If you use good quality textures, then compress it.
    With following this, we get stable 60 fps on small low poly scenes with realtime light on a not powerfull mobile (in fact Huawei Y6 2019).
    P. S. Sorry for my english.
     
    Lorrak, BrandyStarbrite and Vefery like this.