Search Unity

Official Unite Now - Optimization Tips for Maximum Performance – Part 2

Discussion in 'General Discussion' started by AskCarol, Jun 10, 2020.

  1. AskCarol

    AskCarol

    Joined:
    Nov 12, 2019
    Posts:
    234
    Feel free to post your questions before, after and during the session.


    Unite Now Session

    Unity evangelist @ArturoNereu shares real-world best practices for optimizing game performance. He’ll provide useful tips on Graphics, Audio, and UI, so you can get the most out of Unity and your game.




    When
    Thu, June 25, 9:00 AM PT




    Where
    You can watch the session here!
    Make sure to sign up to get access to all Unite Now content.


    ______________________


    A team of product experts from across Unity will be available during and after the session. Our Community team will continue to field questions to foster an ongoing discussion with the community. Please feel free to ask your questions in this thread.


    Some basic rules

    • Only questions related to the topics of the session are permitted.


    • All questions will be fielded by our Community Managers (@LeonhardP and @AskCarol)
      • Replies will have to be approved by the moderators to show up in the thread.


      • Once approved, the questions will be forwarded to the relevant experts.

    We really look forward to hearing from the community.

    Thank you!
     
    Last edited: Jul 2, 2020
    Peter77 likes this.
  2. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,609
    A direct link to the session would have been nice. The video is unfortunately marked as unlisted, so I can't seem to find and watch it on my TV.
     
    AskCarol and Noisecrime like this.
  3. Kamyker

    Kamyker

    Joined:
    May 14, 2013
    Posts:
    1,087
  4. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,609
    I have some questions :)

    Avoid mobile native resolution

    I've experimented with this a while ago and I found some issues that I wasn't able to solve. Perhaps you've solved them.

    Question 1

    How can I render a native resolution UI on top of the lower res 3d scene? Just using Screen.SetResolution affected both in my tests.

    I then started to come up with a custom render setup. I kept the screen at native resolution, but rendered the 3D camera to a lower-res RenderTexture. I then stretch-blit the lower-res RenderTexture and draw the UI afterwards.

    This did work, but 1. didn't make it faster and 2. caused all sorts of Physics screen to world issues.

    Question 2

    I noticed using Screen.SetResolution to lower the resolution caused on some android devices actually performance problems. Or let's say it made it slower and not faster.

    It's been a while and I can't remember why. I guessed Unity perhaps just renders to a lower-res RenderTexture and then stretch-blits it to the native-res frame-buffer? Like the setup I described above. Is that the case? Have you seen such worse performance on some devices too?

    How can I solve the above two issues?
     
    Last edited: Jun 27, 2020
    AskCarol likes this.
  5. Batuhan13

    Batuhan13

    Joined:
    Apr 9, 2017
    Posts:
    117
    @AskCarol Hi mate could I ask you a out of topic question. Will be summer sales in asset store in next days?
     
  6. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,728
    Use built-in rp. Render "main" camera to a render texture with a resolution of your choosing, render UI camera on top normally without any post. This is still viable, even though it is becoming slower to do in later version of Unity (maybe to prove their point that stacking cameras is slow?).

    With that said, if you are mindful of your fillrate (which generally means avoiding any Unity provided shaders and post effects), you can render at native resolution everything just fine, with AA on even. Just turn off as many Unity features as you can.
     
  7. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,609
    That's pretty much what I described above I ended up doing, but it didn't make things faster, hence the question :)
     
    AcidArrow likes this.
  8. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,728
    Then you were not fillrate bound? In fillrate bound devices (like say, Samsung Galaxy S6) limiting the resolution for the main cam was a clear win for us. If you are not seeing performance gains, then you were not fillrate bound, which means lowering resolution does little for you (and is why "don't use native resolution" as general advice is not very useful)
     
    Last edited: Jun 29, 2020
    Peter77 likes this.
  9. Sansidiok

    Sansidiok

    Joined:
    Mar 19, 2013
    Posts:
    5


    on 3D Camera,

    OnPreRender,set a smaller camera rect.
    OnRenderImage,setback rect before blit to dest
     
  10. Neto_Kokku

    Neto_Kokku

    Joined:
    Feb 15, 2018
    Posts:
    1,751
    On ultra low end devices (like granny Mali 400), blitting off-screen can have a significant overhead, which can outweigh the cost of of rendering at native res. But those GPUs are usually far too slow to run any effect that would benefit from a lower resolution anyway.

    The advice is valid for more modern, but not premium GPUs, specially if your game is in the business of using per pixel lighting, shadows, and post effects.

    Mobile games which target "console like" graphics simply cannot do native rendering even on the very best mobile GPUs, because those are often paired with ludicrous high resolution screens.

    Using dynamic resolution on your camera and setting your UI canvases to overlay did the trick for us: 3D rendering resolution can be changed at any time and UI is always at full res. Works like a charm on consoles too.
     
    Peter77 likes this.
  11. Ferazel

    Ferazel

    Joined:
    Apr 18, 2010
    Posts:
    517
    Why are you recommending Low Quality texture compression? My understanding (which may be wrong) is that the textures will be the same disk/file size but that the texture compression processor will have different settings set on it depending on the quality setting. Certain quality settings may use an unsupported texture compression (BC7 vs DXT5) but I am not aware of why the texture compression would matter in any optimization other than editor import times as long as the target compression is supported on the target device.
    upload_2020-7-6_14-33-15.png
     
  12. ArturoNereuUnity

    ArturoNereuUnity

    Unity Technologies

    Joined:
    Sep 4, 2014
    Posts:
    17
    Hello, thanks for your question.

    Disk space is saved if you have a more aggressive (Low Quality) and on mobile devices (sorry for the generalization) runtime performance is also a benefit you can get by having fewer bits per pixel stored. But as you mention, it's not a silver bullet because it depends on formats, platforms, etc.

    Here's more information, I hope is useful. https://docs.unity3d.com/Manual/class-TextureImporterOverride.html#default-formats

    Thanks again!
     
  13. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,728
    What? That’s false. It’s only true if you’re using ASTC which isn’t the default for any mobile platform.

    Edit: I guess iOS switches to 2bit pvr if you set it to low, so I guess there is a valid use case.
     
    Ferazel likes this.
  14. GameAdvanced

    GameAdvanced

    Joined:
    Aug 30, 2020
    Posts:
    4
    This thread is really useful I got to catch up those techniques