Search Unity

Discussion Unity 5 to Unity 2024 android performance tips

Discussion in 'Android' started by UnityLighting, Oct 23, 2016.

  1. Karmate

    Karmate

    Joined:
    Aug 30, 2014
    Posts:
    45
    oh i see, thanks. what about texture compression settings ? which format do you use for gui, rgb and rgba ?
     
  2. UnityLighting

    UnityLighting

    Joined:
    Mar 31, 2015
    Posts:
    3,874

    I don't know anything about texture formats. But you should always turn on Generate mip maps option for in level textures for better performance
     
    Karmate likes this.
  3. sledgeman

    sledgeman

    Joined:
    Jun 23, 2014
    Posts:
    389
    Hey all.

    I compared U4.72 and U5.34, U5.38 & U5.62. My performance results are interesting, because the difference between U4.7 and U5.6 is really big ! U5.6 doesn´t seems to have a chance against U4.7. I turned everything off inside U5.6. Like environment, Gi, etc. I even don´t have Physics3D / 2D inside my project. So you can exclude this. What i´ve noticed is, that simple movements inside U5 are slaggish and stuttering. U4.7 does not has any stutters at all, and the movements are really good & smooth. My Project is about simple sidescroller prototype with use of the sprite system. So no big meshes here. The build size out of U5.6 is plus 5mb in comparison to U4.7, so it gets bigger file size :-(

    You can only test this, notice it, on some older Android devices. That have a max. of 2 cores and KitKat OS. If i test it on my newer device with 8x cores and Android 5.1 you can´t notice this difference between U5.6 & U4.7, so good. This is why i went to a lower specs device.

    Has someone go through same expiriences here, with simple movements, simple sidescroller mechanics and only the use of the sprite system ?
     
  4. UnityLighting

    UnityLighting

    Joined:
    Mar 31, 2015
    Posts:
    3,874
    Change all shaders to legacy diffuse. Don't forget terrain shader
     
  5. sledgeman

    sledgeman

    Joined:
    Jun 23, 2014
    Posts:
    389
    Ok, will try it out.

    Best way to change it is inside: Edit -> Project Settings -> Graphics -> ... right here. Right ?
     
  6. UnityLighting

    UnityLighting

    Joined:
    Mar 31, 2015
    Posts:
    3,874
    No
    select each object and change his shader from material settings
    also select terrain and change its shader from terrain settings tab to Legacy Diffuse
     
  7. sledgeman

    sledgeman

    Joined:
    Jun 23, 2014
    Posts:
    389
    Hm,

    in my project i have only sprite objects. They have per default their own material, i can´t access or override. If i am not wrong.
     
  8. UnityLighting

    UnityLighting

    Joined:
    Mar 31, 2015
    Posts:
    3,874
    I'm talking about a 3D game
     
  9. sledgeman

    sledgeman

    Joined:
    Jun 23, 2014
    Posts:
    389
    Ok. And i was just talking about a 2D Game with a sprite system. And still here, where you don´t have these big performance needs, U4.72 is far better than U5.62 on simple transformation movements. Unbelieveable, but true.
     
  10. UnityLighting

    UnityLighting

    Joined:
    Mar 31, 2015
    Posts:
    3,874
    First of all ,apply all my preferred settings in the first posts

    Then you should know that the main difference between u4 and 5 is just shaders. All shaders has been upgraded to the next level and is compatible with the mid range devices that's used OpenGL Es3.0+..

    So you must change all shaders to legacy one to ensure about shaders performance on low-end es2 devices.

    For example you must unchecked Realtime GI in lighting settings or remove default sky box from your scene or just replace its with legacy 6-sided skybox.

    Also you can switch to 2D mode from Edit->Project->Editor

    Don't forget to remove all dynamic lights from your scene and switch to Fastest quality from Edit->Project->Quality (android section)

    I already tested a big project that was upgraded from U4 to 5. the performance was same after applying all settings.

    In unity 4 you didn't needs to change anything. all settings are already suitable for low-end devices.

    Also i planned to make an editor tool to automatically change all unity 5 settings according to unity 4 for low-end devices + log system to show some warning about advance settings for mobile targets that's used es2
     
  11. sledgeman

    sledgeman

    Joined:
    Jun 23, 2014
    Posts:
    389
    Yep,

    done allready everything. Also in the Build-Settings: oGLES2.0. As said, fancy stuff was deactivated, like Gi and so on. No light at all in my scene. The only thing i cant change ist the shaders inside the sprite property. But maybe i change my sprites to simple textures, just for testing it. In my case it could be that the sprites uses high-level shaders instead of legacy shaders.
     
  12. Karmate

    Karmate

    Joined:
    Aug 30, 2014
    Posts:
    45
    Hello again @aliyeredon2, i wrote a script to change resulotion wtihout changing aspect ratio, i am not good at english, i can't describe, check the code, you will unsterstand. I hope it is useful.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class ResolutionManager : MonoBehaviour
    6. {
    7.     public float resPref;
    8.     Vector2 size;
    9.  
    10.     void Start ()
    11.     {
    12.         size.x = Screen.width;
    13.         size.y = Screen.height;
    14.  
    15.         SetResolution (resPref);
    16.     }
    17.  
    18.     public void SetResolution (float f)
    19.     {
    20.         Screen.SetResolution ((int)(size.x * f), (int)(size.y * f), true);
    21.     }
    22. }
    resPref:
    0.6f (low settings)
    0.8f (mid settings)
    1.0f (high settings)
     
  13. sledgeman

    sledgeman

    Joined:
    Jun 23, 2014
    Posts:
    389
    After a while i got very interesting news for everybody who suffered with bad performance by using unity 5.6 to publish to android. There is a hidden checkbox that should be activated: Disable Depth and Stencil ! Now if you publish your APK it runs smooth on your old Android Device as with Unity 4.7. Glad i figured it out. I hope it can help someone with same issues.
     
  14. xxhaissamxx

    xxhaissamxx

    Joined:
    Jan 12, 2015
    Posts:
    134
    WOW thanks for all tips but i want to ask about
    Per-Layer camera clipping what is it ??? is this unity setting or asset ??
     
  15. sylon

    sylon

    Joined:
    Mar 5, 2017
    Posts:
    246
  16. UnityLighting

    UnityLighting

    Joined:
    Mar 31, 2015
    Posts:
    3,874
    Per-Layer camera clipping
    is a asset in asset store.it's free
     
    xxhaissamxx likes this.
  17. xxhaissamxx

    xxhaissamxx

    Joined:
    Jan 12, 2015
    Posts:
    134
    thanks again and i will test it
     
  18. xxhaissamxx

    xxhaissamxx

    Joined:
    Jan 12, 2015
    Posts:
    134
    did u tried multithreaded rendering , gpu skinning , Disable Depth and Stencil
     
  19. UnityLighting

    UnityLighting

    Joined:
    Mar 31, 2015
    Posts:
    3,874
    not yet
     
  20. xxhaissamxx

    xxhaissamxx

    Joined:
    Jan 12, 2015
    Posts:
    134
    i will wait your review :D thanks man i bookmarked your Thread
     
  21. UnityLighting

    UnityLighting

    Joined:
    Mar 31, 2015
    Posts:
    3,874
    I already made a set of tools to do all steps automatically.
    Batch Material Converter
    Batch Model Importer
    Batch Texture Importer
    Mobile Optimizer

    It's not free but will be very useful. Basically is made for my own projects. My target was low-end android devices.
     

    Attached Files:

    • 3.jpg
      3.jpg
      File size:
      163.2 KB
      Views:
      1,490
    • 43.jpg
      43.jpg
      File size:
      157.5 KB
      Views:
      1,676
  22. xxhaissamxx

    xxhaissamxx

    Joined:
    Jan 12, 2015
    Posts:
    134
    wow looks great u will upload to asset store ?
     
  23. UnityLighting

    UnityLighting

    Joined:
    Mar 31, 2015
    Posts:
    3,874
    Yes. Uploaded yesterday
     
  24. John3D

    John3D

    Joined:
    Mar 7, 2014
    Posts:
    441
    Where is this hidden checkbox located? Can you post a screenshot please?
    Thanks!
     
  25. UnityLighting

    UnityLighting

    Joined:
    Mar 31, 2015
    Posts:
    3,874
    Edit->Player->Android->Resolution and Pres...
     
    John3D likes this.
  26. Karmate

    Karmate

    Joined:
    Aug 30, 2014
    Posts:
    45
    any good tutorial or information for "android texture compression methods"?
    which one to choose for interface, important textures or with alpha textures ?

    theese are examples, how do you handle compression for best performance with support maximum device count
     
    Last edited: Jul 31, 2017
    xxhaissamxx likes this.
  27. ShadowMagnus

    ShadowMagnus

    Joined:
    Aug 26, 2016
    Posts:
    5
    This asset is awesome. Is there a chance of also having support for Unity 5.5.0f3?
     
  28. UnityLighting

    UnityLighting

    Joined:
    Mar 31, 2015
    Posts:
    3,874
    Which asset ?
     
  29. ShadowMagnus

    ShadowMagnus

    Joined:
    Aug 26, 2016
    Posts:
    5
    The Mobile Optimizer, sorry :)
     
  30. mostafanastary

    mostafanastary

    Joined:
    Oct 4, 2015
    Posts:
    31
    Hi Ali, Thank you for share your experiences.
     
  31. Altair12121

    Altair12121

    Joined:
    Dec 21, 2016
    Posts:
    7
    What mobile or legacy shader should I use if I want to use normal maps and a simple spec effect (do not use spec map) and most importantly, that it supports baked lights.
     
  32. UnityLighting

    UnityLighting

    Joined:
    Mar 31, 2015
    Posts:
    3,874
    All specular shaders are performance killer on mobiles (related to realtime lights and not shaders)
    you can use :
    1. my custom specular shader (similar to standard shader) with higher performance compare to standard shader with similar result
    2. create custom shader with cubemaps instead of realtime specular effect

    You can use specular shaders on important object or small objects:
    important: Road
    Small : Weapon
    Untitled.jpg
     

    Attached Files:

    AshwinTheGammer, mgyanm and Deeeds like this.
  33. UnityLighting

    UnityLighting

    Joined:
    Mar 31, 2015
    Posts:
    3,874
    f.jpg

    s.jpg

    c.jpg
     
    Last edited: Apr 25, 2018
    Deeeds likes this.
  34. UnityLighting

    UnityLighting

    Joined:
    Mar 31, 2015
    Posts:
    3,874
    Description (based on above screenshots):

    We have 3 lighting models in unity 5 2017-2018:
    1. Standard Specular or Standard Metallic (known as PBR) (since unity 5 )
    2. Lambert (since unity 1 2 3 4)
    3. Blinn-Phong ( since unity 1 2 3 4 )

    Lambert is the most optimized one. Only supports : Albedo,Emission and normal map (without specular)

    Blinn-Phong is after lambert from performance side. supports : Albedo,Emission,NormalMap,Specular,Gloss
    all specular shaders in unity 4 was Blinn-Phong

    Standard (PBR) is most advanced and complete shader but has lower performance compare to others

    So i have simulated standard shader look (only albedo and specularity) in Blinn-Phong and Lambert shader model. SO you can see same look shader with higher performance.

    Note: Specularity is very heavy in performance . SO you can always bake your lights into lightmap and simulate specularity using texture's alpha :

    https://forum.unity.com/attachments/c-jpg.276078/
     
    Deeeds likes this.
  35. Altair12121

    Altair12121

    Joined:
    Dec 21, 2016
    Posts:
    7
    Thank you very much for answering and for the shader. I will certainly use them.
     
  36. LunguM

    LunguM

    Joined:
    Jul 19, 2012
    Posts:
    17
    Oh I can't express how happy I am you shared this. I've been struggling for a week to optimize my mobile game, went as far as to write more optimized shaders to use and when even those couldn't offer the increase I wanted I started to think it was over. With this I was able to jump from a stable 40 fps to 60 fps (capped at 60).
     
  37. PRINCESAHIL57

    PRINCESAHIL57

    Joined:
    Jul 6, 2018
    Posts:
    2
    Hi i am new in unity i just want to ask one thing that when i bake lights it gives me more then 50 directional or in-directional lightmaps size more then 100mb, how can i fix please helpme thankyou
     
  38. PRINCESAHIL57

    PRINCESAHIL57

    Joined:
    Jul 6, 2018
    Posts:
    2
    Hi i am new in unity i just want to ask one thing that when i bake lights it gives me more then 50 directional or in-directional lightmaps size more then 100mb, how can i fix please helpme thankyou
     
  39. UnityLighting

    UnityLighting

    Joined:
    Mar 31, 2015
    Posts:
    3,874
    Decrease the resolution of the lightmap .
     
  40. GreeneMachine

    GreeneMachine

    Joined:
    Jul 3, 2015
    Posts:
    126
    Hey

    Thanks for maintaining this really informative thread... Had good read and got some great tips and insight.

    I'm having some trouble with performance on Android.

    Here's where I'm at:

    My game runs at 60fps on IOS (iPhone 6, 7, Ipad Air 2, Ipad 2017). No fps drops below.. screen stuttering etc.

    I built same game for Android.. and am testing on a Samsung J6 & S8... both running Android V 8.

    Specs are here:
    https://www.gadgetsnow.com/compare-mobile-phones/Samsung-Galaxy-J6-vs-Samsung-Galaxy-S8-Plus

    Game runs sweet on the S8... 60fps.. no trouble.

    Struggling to maintain 30fps on J6... which is half the screen res. as S8!

    Doin my nut in now.. .I've optimised quite a bit, but not sure why its running so bad compared to the S8.

    Looking at the specs of both these devices, does this sound odd to you guys?

    Thanks
     
    JamesArndt likes this.
  41. Rahd

    Rahd

    Joined:
    May 30, 2014
    Posts:
    324
    J6 Gpu has 1 to 4 shader cores , and Configurable 32KB-256KB L2 Cache.
    S8 Gpu has 1 to 32 shader cores , and Configurable Configurable 128KB-2048KB L2 Cache.
    see https://developer.arm.com/ip-products/graphics-and-multimedia/mali-gpus/mali-t820-and-mali-t830-gpus For J6.
    https://developer.arm.com/ip-products/graphics-and-multimedia/mali-gpus/mali-g71-gpu For S8.

    that's a huge difference i think .
    my tips :
    Shaders :

    -a good way to get more performance . is to have all shaders written fragment vertex .
    and limit the number of textures in each shader ,
    -Terrain : use atlasing and Vertex colors . example you have a terrain and it uses a splatmap and height map .
    you can get rid of both by converting the terrain to a mesh terrain and lose the height map , and with vertex colors , you can replace the splatmap .
    -LODS and Tris count
    to reduce a model Tris count and keep details, Simplygon is the best tool out there and it will rearrange uv and textures to gain more space for texture atlasing .
    -UI :
    Ui can be a real pain in the *** , so pack all of the images used in the ui in one texture if you can it will drop from 200 draw call in 1 draw call if your ui has 200 images for example.
    -Skinned mesh and animations :
    Skinned mesh :
    if you use skinned meshes for players , and you want to add clothing or armor in runtime , to keep the draw calls low try combining the skinned meshes after a change in runtime it will freeze for a second or 2 but it will save drawcalls for the future.
    Animations :
    you can throw the animation clip all together and just use shaders !! Example :
    to have large mobs of zombiles , you can use vertex shader to animate them with a texture Not clips .and For the Ai try to have one script for each 5 zombies for example , and have one raycast for all 5 .
    Vertex animations can be used without texture too, but with vertex colors and math :D example :



    Mats and models :
    Combine as much as you can models and materials and you can even have the same model use 4 versions of textures without changing the textures or the models :
    example you have a wall , you make 4 textures for it , then atlas them all in one texture , then depending the the vertex color of the model the shader will chose one of the atlas , you can even change the vertex colors in runtime .( this will break the batching for static of dynamic . .)
    this can be used for damage as well , example you have a robot and you make 2 textures one for new robot and the other for damaged one. using vertex colors you can damage specific parts at runtime example :




    dynamic batching can help if you keep all the models below 300 verts and have some cheap shaders .however Do not abuse it it will lead to cpu bottlenecks.
    you can static batch at runtime too !!
    example :


    Same goes for shader samplers for textures , you can reuse a sampler to have more texture per shader , but reuse them too much and the gpu will bottleneck.


    a good way to fix the heat issue is to have an automatic frame target changer using SystemInfo.processorFrequency that will detect Cpu cores frequency and if it's lower than the starting frequency it will drop the frames to cool off the phone . (example you have a phone with 4 cores cpu each can boost to 2.4 ghz when you first run the game the phone will boots to that cool frequency , you save the value in a script and when it drops , lower the frame target to 24 until the cool frequency is back )SystemInfo.processorFrequency can sometimes return 0 or never change depending on the phone so use it with fail safes in mind .


    Particles and effects :
    you can reuse the same particle system to have different effects , you can even pool each particle , i think unity made a tutorial about this 2 years ago .

    object pooling can save alot , but dont do it too much .

    running the garbage collector at the times of no load is better that waiting for unity to run it when poop hits the fan .



    Stay away from projectors ,dynamic lights , AO camera filters and blur ... most of the screen camera effects ,unity Terrains !! , and skinned mesh , and for sure normal maps , like don't ever try to use more than 4 normal maps at any giving frame not sure why :p .



    To recap this nonsense google :
    shadowgun unity project download for Fake BRDF shaders.
    Bake animation to texture Vertex animation .
    terrain to mesh , vertex color splat .
    Texture atlasing shaders .
    combine meshes , skinned mesh at runtime .
    Simplygon unity .



    i have found out that vertex colors are unused and always present on every model . using them can unlock a huge range of effect and performance gains from thin air .
    a lot of Vertex shader operations can replace Cpu intensive components like skinned mesh and animator /animation . try to keep a balance between loads on the cpu and the gpu , since one of them can limit the other until you find that sweet spot .





    here's an example using runtime vertex color edit and mesh deformation on mobile S5 , to deform the terrain
    the terrain is 2048 *2048 and the maps are all at 2048 or 4096 (max setting) , but it was converted to a mesh before build to 4096 chunks and each chunk is 169 Vert .
    i use a this script i made to change the resolution depending on the phone (Not perfect)


    example :
    id 0 = third of the screen resolution
    (
    originalwidth = Screen.width;
    originalheight = Screen.height;
    )
    public void DPIChange(int id)
    { QualitySettings.vSyncCount = 0;

    switch (id) {
    case 0:
    Screen.SetResolution (originalwidth/3, originalheight/3, true );


    break;
    case 1:
    Screen.SetResolution ((originalwidth/5) *2, (originalheight/5)*2, true );


    break;
    case 2:
    Screen.SetResolution ((originalwidth/2) , (originalheight/2), true );


    break;
    case 3:
    Screen.SetResolution ((originalwidth/5) *4, (originalheight/5)*4, true );


    break;
    case 4:

    Screen.SetResolution (originalwidth, originalheight, true );


    break;
    }
    // this part will stop any bugs when changing screen resolutions at runtme .
    // disable the main camera and enable it so you wont have to reload the scene again.
    cam.SetActive (false);
    cam.SetActive (true);
    Application.targetFrameRate = FpsTarget; sets the frame target again
    QualitySettings.vSyncCount = 0; / disable Vsync
    ScreenResolution.text =Screen.width.ToString()+"x"+Screen.height.ToString(); // just to show new resolutions



    }


    it's been 2-3 years making and open world game for mobile , i faced alot of issues with mobile but there's always a work around each and every limitation !! you just have to keep trying and trying . Try not to use the texture quality settings since unity default quality changer can screw up your textures , i never use Lods , since i'm making a Topdown isometric game ... look up dynamic resolution as well i think there's a good plugin on the assets store .
     
    Last edited: Sep 25, 2019
    Meceka likes this.
  42. Rahd

    Rahd

    Joined:
    May 30, 2014
    Posts:
    324
    here's a terrain with one Texture but it has some fake BRDF and triplanar texturing:

     
    JamesArndt likes this.
  43. mukki014

    mukki014

    Joined:
    Jul 30, 2017
    Posts:
    164
    C
    Can you please make a tutorial for how to create a graphic setting UI for android for turning on off image effect , change quality setting and change resolution
    Thank you
     
    salex1 likes this.
  44. mukki014

    mukki014

    Joined:
    Jul 30, 2017
    Posts:
    164
    You can use 'ETC2' OR ETC1 it supports all open gl GPU. Etc2 is only for opengl es 3.0 and above. ASTC is another one with best quality and texture compression but it takes lot time to import texture in project also it supports open gl es 3.1 and above.
     
  45. UnityLighting

    UnityLighting

    Joined:
    Mar 31, 2015
    Posts:
    3,874
  46. mukki014

    mukki014

    Joined:
    Jul 30, 2017
    Posts:
    164
  47. newlife

    newlife

    Joined:
    Jan 20, 2010
    Posts:
    1,080
    Hello,
    is there a feasible way to generate and compress a texture runtime on Android / iOS?
    We have a decal system for our racing game that generates a texture runtime with the decals selected by the player.
    Since we are using Texture2D.ReadPixels() to read from a an orthographic camera, we cant use any compressed format.
    In this way the generated texture (1024x1024) is 5.3 MB in ARGB32 format. Compressed in ETC format it would be 1.3MB.
     
  48. Yamin-Nather

    Yamin-Nather

    Joined:
    Dec 31, 2014
    Posts:
    5
    Thanks man u helped me fix my game
    I'm making a casual mobile game which worked fine with my Poco but when I tried it in a Lenovo k8 note there was a lot of stuttering.
    I thought that reducing the render scale in URP would be the same as reducing the resolution but still was experiencing the stuttering issue b4 reducing the render scale.
    After seeing ur post I decided to just set the resolution by code and all the stuttering was gone. Thank you bro @LightingBox2 .

    So anyways moral of my story i guess is render scale and resolution dont work the same.
     
  49. UnityLighting

    UnityLighting

    Joined:
    Mar 31, 2015
    Posts:
    3,874
    Hi
    This is my test on T720 MP2 gpu in 720 resolution
    Built-In pipeline tested target + android
    Gif compare:
     
    JamesArndt likes this.
  50. UnityLighting

    UnityLighting

    Joined:
    Mar 31, 2015
    Posts:
    3,874
    Up for new users ...