Author Topic: Interaction of UI root resolution vs game resolution  (Read 3968 times)

bac9

  • Full Member
  • ***
  • Thank You
  • -Given: 2
  • -Receive: 4
  • Posts: 113
    • View Profile
Interaction of UI root resolution vs game resolution
« on: October 25, 2014, 01:24:10 PM »
Can someone comment on how resolutions of the UI and of the Unity viewport interact? Let's consider three cases:

  • Viewport resolution of 1280x720, UI resolution of 1280x720
  • Viewport resolution of 1280x720, UI resolution of 3840x2160
  • Viewport resolution of 3840x2160, UI resolution of 3840x2160

Provided we follow proper auto layout practices advocated by Google, Apple, NGUI and everyone else who has tried to develop for multiple screens, all those three cases should look absolutely identical when rendered into a 1280x720 screenshot. Now, what I'm interested in is not how the end result looks, but how difficult it was to render it from UI standpoint. I'm not interested in actual per-pixel shader cost, it's obvious that with viewport resolution going up, your GPU will have more work to do. I'm interested in performance hit of UI resolution.

From what I'm seeing so far, UI resolution affects only the scaling of objects inside UI root, and consequentially, controls the scale of pixel unit in relation to real pixels of your screen. That alone is extremely unlikely to cause any different in performance, I would guess. You don't get performance hits from changing transform scales and saving higher values into your int variables. Okay, what else... labels, textures, sprites. From what I am seeing, true type labels in NGUI are rasterized at the viewport resolution, never at UI resolution, so it's reasonable to guess that performance hit of labels is not at all different between the cases 1 and 2. Sprites and textures, as well as bitmap font labels, are already rasterized, all that happens in runtime is your GPU sampling them, and between the cases 1 and 2 that will have absolutely identical flat cost no matter how high or low the UI resolution is.

With that in mind, am I correct in assuming that cases 1 and 2 will have absolutely identical performance on every device? Essentially I'm asking if I overlooked any per-pixel calculations NGUI might perform in UI resolution space with performance impact proportional to that resolution. So far I'm seeing none.

Reason I'm asking about that is simple - I would like to adopt DP instead of pixels, keep one high-res atlas and use root scaling to influence size of the elements in proportion to the screen, in line with how native UIs in Android and iOS do it depending on the DPI of the device. Knowing I can run 4k UI root without any performance impact would relieve a great burden from my mind there. :)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Interaction of UI root resolution vs game resolution
« Reply #1 on: October 25, 2014, 03:00:23 PM »
The UI won't look the same. UI's look depends on the resolution of the camera used to draw it. 720p is very different from 2160p, unless you set UIRoot to be fully Constrained.

bac9

  • Full Member
  • ***
  • Thank You
  • -Given: 2
  • -Receive: 4
  • Posts: 113
    • View Profile
Re: Interaction of UI root resolution vs game resolution
« Reply #2 on: October 25, 2014, 03:06:45 PM »
Ignoring pixel perfect snapping and the difference in widget sizes - let's assume that everything is done through anchors with no pixel-based offsets, that makes it identical no matter the resolution. Still, is there any performance influence hit I might be overlooking?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Interaction of UI root resolution vs game resolution
« Reply #3 on: October 25, 2014, 03:12:25 PM »
If you're going down that route, you really should just stick to a Constrained UIRoot. Then the screen resolution truly won't matter.

There is no performance difference.

bac9

  • Full Member
  • ***
  • Thank You
  • -Given: 2
  • -Receive: 4
  • Posts: 113
    • View Profile
Re: Interaction of UI root resolution vs game resolution
« Reply #4 on: October 25, 2014, 03:40:12 PM »
Great to hear that!

As about the mode, I'm not really sure what benefit will Constrained mode give. I'm not actually planning to run 4k resolution in a 1280x720 viewport, just researching the options.


Ideally, I want to replicate what native UIs are doing: they are absolutely pixel perfect on the whole range of pixel densities and resolutions. They do that by never using true pixels as a scale of anything: instead, they have floating units (like DP) that are incremented depending on screen density of a device, and for raster elements, they swap the atlases to ones rasterized at the resolution of the currently selected multiplier. This allows you to have pixel perfect UI both on a 640x1136 iPhone screen, on a gigantic ultra-dense Samsung phablet and on an old low-res Android phone - just by virtue of values like "8dp" translating into different (nicely proportional) pixel values on different devices - 3x on one, 1x on another. If I were to do that, it makes sense to use pixel perfect NGUI mode with trickery of atlas switching and widget rescaling stacked on top. Will require some work, but I think it's feasible and would really improve how UI situation in Unity in comparison to native apps. Not sure if experimental DPI scaling option does what I need for that, but will check that out too.

The whole situation of UI resolution ending up bigger than rendering resolution mostly happens in the editor where you are forced to work with limiting viewports.
« Last Edit: October 25, 2014, 05:20:43 PM by bac9 »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Interaction of UI root resolution vs game resolution
« Reply #5 on: October 26, 2014, 09:14:54 PM »
NGUI doesn't work like that. Native UI is often rasterized, while NGUI uses atlases. They are different systems.