Search Unity

Unity Universal Render Pipeline causing massive slow down on 2d Mobile Project

Discussion in 'Universal Render Pipeline' started by tuqire, Feb 11, 2020.

  1. tuqire

    tuqire

    Joined:
    Mar 3, 2019
    Posts:
    10
    Hi,

    I hope you are all well.

    I have been building a 2D game in Unity and it was going great. I was building it on my Pixel 4XL phone and getting frame rates of about 60fps. However, since updating to Unity .3, and introducing Universal Render Pipeline, the frame rate has dropped right down to about 10 fps. I am quite new to Unity - this is my first game - is there some obvious setting that is supposed to be off / on for 2D mobile games when using Universal Pipeline?

    I have stripped the scene right back to have only 3 sprites on scene with some colliders and basic scripts and I am still having the same issue.

    Any help would be greatly appreciated. Thank you.
     
    Devil_Inside likes this.
  2. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    257
    Are you using the 2D Renderer or the Forward Renderer?
     
  3. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    Hi! To tell what's going on, we also need to know the which version of Unity and which version of URP you are using.
     
  4. tuqire

    tuqire

    Joined:
    Mar 3, 2019
    Posts:
    10
    Hi,

    Thanks for the replies.

    I am using the 2D renderer.

    I am using Unity version "2019.3.0f3 Personal" and URP version "7.1.6".
     
  5. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    We had a big performance regression but that was fixed in 7.1.3, so what you're experiencing is something else. Can you send us your simple repro project (the one with only 3 sprites)?
     
  6. tuqire

    tuqire

    Joined:
    Mar 3, 2019
    Posts:
    10
    Hi,

    Sorry for the delay.

    I pushed the stripped down game to: https://github.com/tuqire/scaled-back-unity

    The scene is made up of 3 sprites and the player animation. I've removed all the excess prefabs and sprites. I left some basic scripts in there, but I can also remove them if needed.

    The render pipeline stuff is in "Assets/Render Pipeline".
     
  7. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    Thanks! I'll take a look.
     
    tuqire likes this.
  8. wagenheimer

    wagenheimer

    Joined:
    Jun 1, 2018
    Posts:
    323
    Is there any update on this?

    I have the same problem... It's just a scene with a background, a player (2D sprite) and some 2d lights using URP and I'm getting massive low fps on a Moto G5 (3 fps) and even on Mi A2 it's mostly unplayable!

    Is this expected? @tuqire Did you managed to improve the overall performance?
     
    Devil_Inside likes this.
  9. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    This is definitely not expected. May I know how many sorting layers do you have in your project?
     
  10. tuqire

    tuqire

    Joined:
    Mar 3, 2019
    Posts:
    10
    @wagenheimer Unfortunately not, my game is currently in early development so I'm just working on other parts of the game. I've noticed reducing the 2D lights count to a single global light seems to improve performance for the time being.
     
  11. elkmoradowitzky

    elkmoradowitzky

    Joined:
    Oct 12, 2018
    Posts:
    1
    Same issue here
     
    hendryshaikh2004 likes this.
  12. tuqire

    tuqire

    Joined:
    Mar 3, 2019
    Posts:
    10
    Hi @yuanxing_cai , just wondering if there is an update to this? Have you checked the repo and reproduced the issue? any ideas if the issue is related to Unity or my own code / setup?

    thanks in advance.
     
  13. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    Hey! I did take a look at the project and I think the culprit for bad performance is you have way too many sorting layers (25+). With our current implementation of the lighting system, each unique sorting layer adds significant overhead to the render pipeline, so having more than 25 layers is a big no go even for desktop platforms, let alone mobile.

    I'm pretty sure you can manage the sorting of your sprites with much fewer sorting layers, by using the Order in Layer property of the Sprite Renderer.
     
    tuqire likes this.
  14. tuqire

    tuqire

    Joined:
    Mar 3, 2019
    Posts:
    10
    Hi @yuanxing_cai, I have my scene working fine now with 4 layers and it is working great. Thank you so much!

    What do you think is a max number for mobile? Just to make sure I don't go over it.
     
  15. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    There's no gold standard on this. As I said in the previous post, each sorting layer adds quite a lot of overhead to the system, so use as few as you possibly can.
     
    tuqire likes this.
  16. drazuerg

    drazuerg

    Joined:
    Jan 31, 2014
    Posts:
    62
    Hello there !

    I also went from the regular render pipeline to the URP (2D renderer, not forward).
    What I would like to do is apply Bloom only to certain sprites of my main scene. I found this tutorial that describes it pretty well :

    However, using Bloom from a Global Volume seems pretty bad for perfs.



    This is strange as I used before the Bloom from the Post Processing Stack v2, and didn't have these fps impacts ... Issue is that with this method I had to apply the Bloom to the whole screen, couldn't find a way to apply it only to specific sprites.

    Also I took good notes from the sorting layer advice.
    Reduced it from 6 to just one.

    Is it known that the Bloom effect from the URP is affecting performances a lot @yuanxing_cai ?
    Maybe it's because the Bloom from PPStackv2 has a "Fast Mode" ? Would it be possible to have the same on URP ?

    Using Unity 2019.3.7f1 / URP 7.3.1

    (Note : updating the URP version already improved quite a bit the performance, but it's still affecting it ...)
     
    DungDajHjep likes this.
  17. rxmarccall

    rxmarccall

    Joined:
    Oct 13, 2011
    Posts:
    353
    Just wanted to chime in and say that I'm seeing 25 fps average using URP and getting 45 fps using standard built in pipeline on the Nintendo Switch...... Add me as another frustrated developer that heard the call that URP was going to be higher performance and yet it's almost running 50% slower :(

    I currently have 6 sorting layers, so I might try to trim that down and see if it helps performance, but it seems ridiculous that I see such a major performance drop simply switching to URP with no modifications.

    I'm running 2019.3.5f1, URP 7.1.8, with the 2D Renderer.
     
  18. DGSpartanWolf

    DGSpartanWolf

    Joined:
    Jul 27, 2017
    Posts:
    5
    same problem here, unity 2019.3.6 , latest versions of URP and sorting layers are 3 ,using 2d renderer. performance on android is terrible
     
    wlwl2 likes this.
  19. DGSpartanWolf

    DGSpartanWolf

    Joined:
    Jul 27, 2017
    Posts:
    5
    now I've just lowered the number of layers to 1 , and the problem still exists.I have another scene with no materials (Just UI elements) and it works like a charm.but this one is with lit materials and of course with some lights,and the performance is so bad
     
    Last edited: Apr 16, 2020
    hendryshaikh2004 and DungDajHjep like this.
  20. DGSpartanWolf

    DGSpartanWolf

    Joined:
    Jul 27, 2017
    Posts:
    5
    ok,now changed all the materials to unlit and turned off all the lights.the frame rate is good but I need lights and shadows,so I'm going to experiment a little more to see the problem is with materials or lights
     
  21. DGSpartanWolf

    DGSpartanWolf

    Joined:
    Jul 27, 2017
    Posts:
    5
    after some experiments I found out that the problem is with 2d lights and not the materials.no matter what settings and how many lights you use, they are very slow for mobiles
     
    DungDajHjep likes this.
  22. drazuerg

    drazuerg

    Joined:
    Jan 31, 2014
    Posts:
    62
    On my side I have perfs degradation even with no light in the scene :(
     
  23. NikoBay

    NikoBay

    Joined:
    Aug 15, 2018
    Posts:
    39
    So according to what you guys reported, current version of 2d light of URP is no good for mobile? I wish Unity could make it more transparent on this performance issue so devs like us can save time instead of scratching our heads thinking we did s.t wrong. T~T
    Still love the 2d light of Unity, wish it could be complete in near future.
     
    LilGames and DungDajHjep like this.
  24. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    If you don't use any 2D lights then we have added a faster code path for unlit scenes. Try updating URP to 7.3.x.
     
    rxmarccall likes this.
  25. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    I'm glad you like the 2D Lights!

    The 2D graphics team is solely focused on optimizing the performance of the 2D Renderer for mobile platforms right now. We won't remove the preview tag from this feature until we and our users are pleased with the performance.

    To give you an idea on what's coming:
    • We'll have an option for you to split sprites into opaque and transparent parts, so that sprites that are mostly opaque are less costly to render.
    • Make our render pipeline and shaders more friendly to mobile GPUs.
     
    NikoBay likes this.
  26. LeifStro

    LeifStro

    Joined:
    Mar 23, 2015
    Posts:
    29
    Im having serious performance loss with URP as well. I set up a basic toggle system to switch between 2 states:

    State 1) Universal Render Pipeline (URP), all renderer (non-UI) materials in scene use a shared material - SimpleLit Shader. Quality = default, no shadows
    State 2) Standard Render Pipeline, all renderer (non-UI) materials in scene use a shared material - MobileBumpDiffuse Shader. Quality = default, no shadows

    Result: URP is about 50% slower (or worse) on both test devices - Galaxy S3, Galaxy S5

     

    Attached Files:

    lclemens, harrybouch96, wlwl2 and 2 others like this.
  27. DungDajHjep

    DungDajHjep

    Joined:
    Mar 25, 2015
    Posts:
    202
    LWRP with post processing is x2 performance compared to URP, so maybe i will drop unity light2d. Why don't we have the independent 2D light package?
     
  28. akasabutski

    akasabutski

    Joined:
    Nov 7, 2018
    Posts:
    12
    I also have problems with performance when I have at least 1 light on. I made a very simple test and I can share the files if you want it.

    Setup: Latest Unity today (2020.2.0a15.1993), URP 8.1.0 released on April 24th (that means no public release since your comment yet [9.0 is still private it seems]). I am working with 2019 Unity, but I wanted to get the latest available features to ensure that I am not missing anything.

    Target device: Samsung Galaxy S6 which is currently very sensitive to any performance changes. It's not afraid to get hot.

    Sanity test: fps counter UI (just one TextMeshProUI and one Update() function). Application framerate set to 60. In Graphics URP assets assigned with default 2D renderer data in it. PostProcessing and shadow booleans are disabled in the main camera (turns out those two flags destroy performance in my project even when no postprocessing or shadow casting presented).
    After 10 mins: regular temperature, stable ~60fps.

    Test0: add sprite with Sprite-Lit-Default shader and texture in it. Covers ~30% of the screen. Image size (626x571). Without any lights, it's just a black image in the center of the screen.
    After 10 mins: regular temperature, stable ~60fps.

    Test1: add global 2d light. There is only one sorting layer - default. Now sprite is lit.
    Before 5 mins: appears to be regular temperature, stable ~60fps
    After 5 mins up to 10 mins: slightly warmer (noticeable, but barely), stable ~50fps, doesn't go higher, ever.

    Tested 3 times.
    Achieving 30fps in the final product on such low-end device would be okay to me but in my experience every frame matters. Losing 10fps in the naked scene because of single global light and one sprite seems a little extreme.

    Test2: add point 2d light circling around the sprite. Global and point lights get blended.
    Before 2 mins: appears to be regular temperature, stable ~60fps
    After 2 mins up to 10 mins: slightly warmer (noticeable, but barely), 45-47fps.

    Test3: same as test2, but default blending texture scale set to 0.01. The quality is unusable, this is done purely for testing.
    Before 2 mins: appears to be regular temperature, stable ~60fps
    After 2 mins up to 10 mins: noticeably warmer, 55-56fps.

    I expected the phone to get really hot before the fps drop, but it got warmer just slightly in most cases. When I was testing the screen fill rate, the phone was getting extremely hot.
    I am waiting for 9.0 URP release to try it out, but until then, can you comment on this? What optimizations could be currently made? Is URP 9.0 expected to provide better performance for global 2d light or blending? Is Sprite-Lit-Default the right choice for mobile platforms?
     
  29. agmcorp

    agmcorp

    Joined:
    Jul 25, 2019
    Posts:
    3
    I'm working with Unity 2019.4.11f1, "Universal Render Pipeline" with "Lightweight RP" (package version 7.5.1).
    I defined a "2D Renderer Data" to work with 2D Lights.
    In my game I have four 2D lights:
    - Two "Point" 2DLights (each point light has 3 target sorting layers)
    - Two "Global" 2DLights. One of them with 3 target sorting layers (lights up my whole game except characters) and the other with 1 sorting layer (Illuminates only my characters).

    I'm developing a 2D mobile game for kids and using 2D lights to decorate.
    Only ONE "Point" 2DLight is turned on at the same time.
    The "Global" light, which illuminates my characters, is always turned on.
    The "Global" light, which illuminates my whole game (except characters), is ON only when the point light is OFF.

    At certain times in my game, I turn on/off "Point" lights and "Global" light with the above restriction already described.

    Everything works great until I use shadows on my characters.
    When I use shadows, the frame rate is dropped right down to about 10 fps otherwise it's about 27.

    My 2D game is pretty simple. My characters are round sprites (like a coin), so shadows are ridiculously simple.
    To gain in performance, I set "Renderer Texture Scale" to 0.4 (insted of default value 1) in the object 2D Renderer Data.
    While the performance has greatly improved after that, it is still low.

    Each character (above 10 on screen, moving around) has a "Shadow Caster 2D (Experimental)" component and checkbox "Cast shadows" selected.

    What else can I do to improve performance? I've done a lot of research and can't figure out what else I can do.
     
  30. DungDajHjep

    DungDajHjep

    Joined:
    Mar 25, 2015
    Posts:
    202

    The script 2dCastShadow code is written temporarily and generates a lot of garbage, currently the only way is you have to get that code from the package and improve it.
     
  31. johannig

    johannig

    Joined:
    Apr 22, 2015
    Posts:
    27
    Big up to this thread. A few 2D lights and the performance takes a HUGE hit. A few 2D lights with a few sorting layers and the performance becomes completely unbearable.
     
  32. stevenx

    stevenx

    Joined:
    Jun 7, 2015
    Posts:
    11
    I've got the same problem here, it's not about how many sorting layers and draw calls or 2D lights, the performance is simply horrible on PCs and Macs with onboard graphics cards.
    Unity doesn't seem to respond to this problem anymore....
     
  33. weiping-toh

    weiping-toh

    Joined:
    Sep 8, 2015
    Posts:
    192
    My performance problem is only limited to the SRP batcher not batching for my custom shaders when running on GLES3, even on the latest package.
    The same exact shaders have the batcher working on Metal for iPhones and when built for Vulkan on Android. The problem is Android phones suffer a GPU computation performance hit of about 0.2ms when running on Vulkan. Switching to GLES3 saw an improvement in the computation but now suffers from SRP batcher not batching.
     
  34. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    Hi All! I want to let you know that we have implemented quite a number of performance improvements to the 2D Renderer for Unity 2021. One of them is optimized GPU memory bandwidth usage, which should help with frame rates on mobile devices.
     
  35. johannig

    johannig

    Joined:
    Apr 22, 2015
    Posts:
    27
    Good news! Going to give this a try today. Does this also apply to desktop or did you mostly focus on mobile (feel like I read that before). Also any timeframe/ideas when this will leave Alpha, typically?
     
  36. johannig

    johannig

    Joined:
    Apr 22, 2015
    Posts:
    27
    Tried it today & I'm seeing BIG improvements. All my scenes are running smoothly now - on my Mac mini 2020 and MacBook Pro 2017. I'm very happy to see this and now I can continue with my project - thanks so much!

    One note, though. I was going to compare performance on my MacBook Pro 2010 - but I can't open the builds due to several error messages that all start with: ERROR: Shader Hidden/Universal Render Pipeline/Blit shader is not supported on this GPU (none of subshaders/fallbacks are suitable)

    The bold part is what changes. Basically a lot of shaders are not supported. Does this just mean that these shaders won't run on older models? The MacOS is High Sierra.
     
    DungDajHjep and rxmarccall like this.
  37. weiping-toh

    weiping-toh

    Joined:
    Sep 8, 2015
    Posts:
    192
    Are you on Metal or OpenGLCore?
    Some shaders might not be OpenGLCore compatible on Mac as Apple GPU discontinued support for OpenGL since OpenGL 4.1.
     
  38. johannig

    johannig

    Joined:
    Apr 22, 2015
    Posts:
    27
    Hey! I'm using Metal actually. Unity crashes the entire macOS if you try to play with OpenGL in editor :confused:
     
  39. weiping-toh

    weiping-toh

    Joined:
    Sep 8, 2015
    Posts:
    192
    Most likely the shaders will not run on older Mac models that do not have Metal support. URP shaders require use of features that is available in Metal and OpenGl 4.3 onwards.
     
  40. yuanxing_cai

    yuanxing_cai

    Unity Technologies

    Joined:
    Sep 26, 2014
    Posts:
    335
    Glad to see that you got some benefits from the latest updates! May I know the exact model of your GPU?
     
  41. johannig

    johannig

    Joined:
    Apr 22, 2015
    Posts:
    27
    Sure thing! I'll just paste the whole thing - the more you know the better, eh? :)

    Intel HD Graphics:
    Chipset Model: Intel HD Graphics
    Type: GPU
    Bus: Built-In
    VRAM (Dynamic, Max): 288 MB
    Vendor: Intel
    Device ID: 0x0046
    Revision ID: 0x0012
    Automatic Graphics Switching: Supported
    gMux Version: 1.9.21
    Displays:

    Color LCD:
    Display Type: LCD
    Resolution: 1440 x 900 (Widescreen eXtended Graphics Array Plus)
    UI Looks like: 1440 x 900
    Framebuffer Depth: 24-Bit Color (ARGB8888)
    Main Display: Yes
    Mirror: Off
    Online: Yes
    Rotation: Supported
    Automatically Adjust Brightness: No

    Video Card: GeForce GT 330M* VRAM Type: GDDR3
    Details: *This system has dual graphics processors -- a NVIDIA GeForce GT 330M with 256 MB of dedicated GDDR3 SDRAM and Intel HD Graphics with 256 MB of DDR3 SDRAM shared with main memory. The system automatically switches between graphics systems based on use (when applications use OpenGL, Core Graphics or other graphically demanding technologies, the system will use the dedicated graphics card, otherwise it will use Intel HD Graphics to conserve battery life).
     
  42. weiping-toh

    weiping-toh

    Joined:
    Sep 8, 2015
    Posts:
    192
    From what I read of the official specs, the GT330M only supports up to OpenGL 3.3 / DX10.1.
    It is below the expected target of the Shader.
     
  43. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    Been wondering, if I have say 5 sorting layers and all of my 2d lights uses the one target sorting layer, is there overhead for having more than 1 sorting layers?

    Or is it dependent on the number of different target sorting layers that lights uses per frame?
     
  44. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    257
    Since URP 10, if the lights visible on-screen are identically affecting contiguous layers, then those layers will be rendered together as though they are a single layer.

    For example, if you have layers 0,1,2,3,4. If 2,3,4 all have the same set of on-screen lights affecting them they will be rendered together.

    What that means in terms of performance is that 5 lights that cast onto all 5 of your layers is more performant than 5 lights each casting onto different layers.
     
    Last edited: Jan 31, 2021
    madara5555 and HariharanVN5 like this.
  45. RuneShiStorm

    RuneShiStorm

    Joined:
    Apr 28, 2017
    Posts:
    264

    Could you tell me What the difference between 2D Renderer or the Forward Renderer is?
    Would you recommend using 2D Renderer for a 2d Project? Is it better performance in that case?
    Im having performance issues too and I just realized im using Forward Renderer...
    I managed to fix some performance by changin RenderScale to 0.2 - no idea what it means but it helped :S
     
  46. weiping-toh

    weiping-toh

    Joined:
    Sep 8, 2015
    Posts:
    192
    RenderScale is just scaling the resolution of rendertextures used when rendering.
    So if your default device resolution is 1024x768 => your rendering rendertextures would be about 205x153.

    I am not totally sure what is the difference between the 2D Renderer and the Forward Renderer without inspecting the source. According to my memory(since the last time I made my own custom renderer for my previous project while referencing both renderers), the lighting passes used are different as 2D is mostly simplified to using light mappings while Forward still sends in the light data when rendering hence, the difference in memory bandwidth used per-vertex. And I believe some passes are omitted from the 2D Renderer since most sprites would expect back-to-front rendering as alpha-blending is needed, so the "default" opaque pass is omitted too.