Search Unity

QualitySettings.resolutionScalingFixedDPIFactor is not updating

Discussion in 'General Graphics' started by Mhmd-Subhi, Mar 2, 2018.

  1. Mhmd-Subhi

    Mhmd-Subhi

    Joined:
    Mar 13, 2015
    Posts:
    28
    Hello every one,

    I am using fixed DPI resolustion of about 250 in the player settings, and I am trying to implement a power saving mode using lower frame rates, lower texture resolution and a lower resolutionScalingFixedDPIFactor,

    The problem is that when changing to the lower quality settings, lower texture resolution does apply but resolutionScalingFixedDPIFactor does not apply its changes, and It was tested several times on a mobile phone (android nexus 6P),

    It only applies when restarting the game, Also, I have tried changing QualitySettings.resolutionScalingFixedDPIFactor = 0.7 form scripts but got nothing,

    Do you have any ideas how to make it work,
    Thanks for your time
     
    Serge144 likes this.
  2. Antony-Blackett

    Antony-Blackett

    Joined:
    Feb 15, 2011
    Posts:
    1,778
    I'm experiencing the same behaviour. It only updates the resolution on app suspend and resume.
    Unity version 217.3.0p3

    And here another slightly off topic but a related question that can hopefully be answered at the same time:

    I'm also looking into dynamic resolution scaling and I'm wondering how it's meant to work given that different devices have different DPI to start with. If I set target dpi to 300 but someone is using an old android with 200 dpi, would that not slow their device down?

    This method might result in a most consistent image but could vary wildly in terms of performance. I would like a target dpi -> native dpi option.
     
  3. RadialGames

    RadialGames

    Joined:
    Jan 31, 2017
    Posts:
    11
    I'm seeing this behaviour as well and would love a fix!

    @Antony-Blackett :

    They took this into account; the function:
    QualitySettings.resolutionScalingFixedDPIFactor

    takes a float from 0..1 which equates to percentage of screen size.

    So a DPIFactor of 1 == native resolution,

    a DPIFactor of 50% == half resolution (and better perf) on all devices.

    If a device already has low DPI you might not want to scale it further down, for that you can check Screen.dpi if you like.
     
    Conferno likes this.
  4. Mhmd-Subhi

    Mhmd-Subhi

    Joined:
    Mar 13, 2015
    Posts:
    28
    @Antony-Blackett ,
    @RadialGames ,

    Thanks for the answers and for the interesting related question that Antony put, I will make some tests on this topic after our game release and hopefully will able to come up will a system that gives a consistent results, and post it here for future if any one needs it.
     
  5. o1o101

    o1o101

    Joined:
    Jan 19, 2014
    Posts:
    639
    @Mhmd-Subhi I am having this same issue, very frustrating.
     
  6. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,028
    Hi!
    Please submit a bug report.
     
  7. PuzzledBoy

    PuzzledBoy

    Joined:
    Sep 9, 2014
    Posts:
    23
    Same issue here.
     
  8. PixelJ

    PixelJ

    Unity Technologies

    Joined:
    Nov 1, 2018
    Posts:
    216
    Did anyone ever submit a bug? I just ran into this as well. It seems
    QualitySettings.resolutionScalingFixedDPIFactor does absolutely nothing on iOS.
     
  9. thelittlegamefactory

    thelittlegamefactory

    Joined:
    Jan 27, 2015
    Posts:
    22
    I have submitted a bug report.
     
    PixelJ likes this.
  10. pistoleta

    pistoleta

    Joined:
    Sep 14, 2017
    Posts:
    539
    Same problem here on iOS, link to bug report?
     
  11. thelittlegamefactory

    thelittlegamefactory

    Joined:
    Jan 27, 2015
    Posts:
    22
  12. pistoleta

    pistoleta

    Joined:
    Sep 14, 2017
    Posts:
    539
    Me too, thanks, lets see if they do something :D
     
  13. o1o101

    o1o101

    Joined:
    Jan 19, 2014
    Posts:
    639
    Is this seriously still not fixed or are we missing something? Surely they would't add a feature that literally doesn't work... ?
     
  14. thelittlegamefactory

    thelittlegamefactory

    Joined:
    Jan 27, 2015
    Posts:
    22
  15. pistoleta

    pistoleta

    Joined:
    Sep 14, 2017
    Posts:
    539
    S*** we work on iOS, we will test it soon on 2019.3.
    Thanks for the news guys.
     
  16. christopheAS

    christopheAS

    Joined:
    Jun 25, 2019
    Posts:
    18
    We are working on an iPad port of our latest game (Crying Suns - https://store.steampowered.com/app/873940/Crying_Suns/). We are using 2018.4 and do not plan to move to 2019 at the moment (waiting for LTS version next year).

    Is this possible to fix this for iOS also and backport it to 2018.4? I have experienced it on several iOS devices and my only alternative solution is to use an intermediary render texture to reduce the pixel count, but it is cumbersome and unncessary.
     
  17. christopheAS

    christopheAS

    Joined:
    Jun 25, 2019
    Posts:
    18
    @PixelJ Any news on this topic? Is this fixable for 2018.4?
     
  18. pistoleta

    pistoleta

    Joined:
    Sep 14, 2017
    Posts:
    539
  19. RenanSylvestre

    RenanSylvestre

    Joined:
    Jan 15, 2018
    Posts:
    1
    I was having the same problem here on Android, but by accident I found that when using QualitySettings.resolutionScalingFixedDPIFactor with a value up to 1, and disable the full screen mode and reactivate with the commands Screen.fullScreen = false and then Screen.fullScreen = true, the game resolution has been successfully changed on Android in real time. I left Resolution Scaling Mode as Fixed DPI and Target DPI at 250. In some cases, I had to restart the game for the change to take effect. In others not. See the result:

    Before
    https://drive.google.com/open?id=1cBaQiC5UIiHSZhC0sXLaBiWXjakx4xMU

    After
    https://drive.google.com/open?id=12L5DXsqVHwfSJk1s-_HvFPblcESJUkrf
     
    meichen8050753 and DominatorDuck like this.
  20. christopheAS

    christopheAS

    Joined:
    Jun 25, 2019
    Posts:
    18
  21. christopheAS

    christopheAS

    Joined:
    Jun 25, 2019
    Posts:
    18
    However, for those interested, we have found a fix for iOS, but it requires modifying a method in the DisplayManager.mm on the fly during the build process.

    Please note our goal was to match a screen resolution 720 pixels high, and that only. So adapt for your own target resolution.

    Code (CSharp):
    1. extern "C" float UnityScreenScaleFactor(UIScreen* screen)
    2. {
    3.     // NOTE: All views handled by Unity have their contentScaleFactor initialized
    4.     // to value returned by this function.
    5.  
    6.     // we should query nativeScale if available to get the true device resolution
    7.     // this way we avoid unnecessarily large frame buffers and downscaling.
    8.     //   e.g. iPhone 6+ pretends to be a x3 device, while its physical screen is x2.6 something.
    9.     // it is available on iOS 8.0+, tvOS 9.0+
    10.     // for older ios versions we add this selector ourselves (AddNewAPIImplIfNeeded in UnityAppController.mm)
    11.  
    12.     // On AppleTV screen.nativeScale returns NaN when device is in sleep mode and starting from tvOS 10 (?) it returns 0.
    13.     if (isnan(screen.nativeScale) || (screen.nativeScale == 0))
    14.         return 1.0f;
    15.     else
    16.     {
    17.         float nativeWidth = screen.bounds.size.width;
    18.         float nativeHeight = screen.bounds.size.height;
    19.         float aspectRatio = nativeWidth / nativeHeight;
    20.        
    21.         float thresholdAspectRatio = 16.0f / 9.0f;
    22.         if (aspectRatio > thresholdAspectRatio) {
    23.             float targetHeight = 720;
    24.             return targetHeight / nativeHeight;
    25.         }
    26.         else {
    27.             float targetWidth = 1280;
    28.             return targetWidth / nativeWidth;
    29.         }
    30.     }
    31. }
    32.  
     
  22. pistoleta

    pistoleta

    Joined:
    Sep 14, 2017
    Posts:
    539
    Do you use this for low end devices or is it because your graphics are too much for certain devices?
    We were interested on this feature once, whenever we had performance issues but once solved and targeting 6plus and newer we didnt need it.
    Still, I'm curious what's the use you're making of it.

    Thanks
     
    BenWilles likes this.
  23. christopheAS

    christopheAS

    Joined:
    Jun 25, 2019
    Posts:
    18
    We have a pixel art game (Crying Suns) and have a lot of light effects that can be taxing on the device. So we decided for mobile platforms to go for a "fixed" target resolution of 720 pixels in height (no matter the width). So we had to control the resolution scale precisely.
     
  24. meichen8050753

    meichen8050753

    Joined:
    Jan 16, 2017
    Posts:
    37
    I't worked at android but not work at ios, my unity version is 2018.4.23
     
  25. meichen8050753

    meichen8050753

    Joined:
    Jan 16, 2017
    Posts:
    37
    It can be fixed at ios(unity 2018.4.23), Android is working.
    I compar the ios export code from 2020.1.17f1c1 to 2018.4.23
    I found that 2020 get scaleFactor at the method recreateRenderingSurfaceIfNeeded in UnityVIew.mm, if the scaleFactor not same as the native, then update surfaceSize. but 2018 do nothing like that.
    QQ20201231-150804.png
    So I copy this code from 2020 to 2018, QualitySettings.resolutionScalingFixedDPIFactor can updating at runtime.

    in unity 2018.4.23
    Ios use Screen.SetResolution to change screen Resolution it can produce a final blit cost,
    But I profile Android and compair between Screen.SetResolution and DPIFactor, It seems nothing defferent. so I think in android case, just use Screen.SetResolution is fine.
     
    Last edited: Dec 31, 2020
  26. jtate5

    jtate5

    Joined:
    Jan 13, 2014
    Posts:
    24
    Is there any hope that this fix will make it into 2019 LTS?
     
    Serge144 and MaykeBr like this.
  27. Serge144

    Serge144

    Joined:
    Oct 2, 2018
    Posts:
    65
    Is there any quick fix for Android? Using 2019.2 and having the same issue...
     
  28. Serge144

    Serge144

    Joined:
    Oct 2, 2018
    Posts:
    65
    I can see quality changes when I switch to other quality level (which has other resolutionScalingFixedDPIFactor) but only when I do the following:
    1) either restart the game.
    2) put the unity game to background and then to foreground again.

    How can I quick fix this? Any help? There might be a small trick which forces it to update without having to do 1) and 2).

    I'm currently using 2019.2. I can see from previous posts that this issue was fixed in 2019.3 or 2020. (I did try in 2019.3 did not work). I did not wanted to update my project to a newer Unity version because it seems like many smalls things break in my game mostly because of the LWRP -> URP conversion. ( https://forum.unity.com/threads/why...p-to-urp-when-using-2019-3-and-above.1062704/ ) . Maybe in the future I will attempt to do so with more time and if there's really no other option to fix or work-around this issue in 2019.2.