multiple_resolutions.rst 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. .. _doc_multiple_resolutions:
  2. Multiple resolutions
  3. ====================
  4. The problem of multiple resolutions
  5. -----------------------------------
  6. Developers often have trouble understanding how to best support multiple
  7. resolutions in their games. For desktop and console games, this is more or less
  8. straightforward, as most screen aspect ratios are 16:9 and resolutions
  9. are standard (720p, 1080p, 1440p, 4K, …).
  10. For mobile games, at first, it was easy. For many years, the iPhone and iPad
  11. used the same resolution. When *Retina* was implemented, they just doubled
  12. the pixel density; most developers had to supply assets in default and double
  13. resolutions.
  14. Nowadays, this is no longer the case, as there are plenty of different screen
  15. sizes, densities, and aspect ratios. Non-conventional sizes are also becoming
  16. increasingly popular, such as ultrawide displays.
  17. For 3D rendering, there is not much of a need to support multiple resolutions.
  18. Thanks to its vector-based nature, 3D geometry will just fill the screen based
  19. on the viewport size. For 2D and game UIs, this is a different matter,
  20. as art needs to be created using specific pixel sizes in software such
  21. as Photoshop, GIMP or Krita.
  22. Since layouts, aspect ratios, resolutions, and pixel densities can change so
  23. much, it is no longer possible to design UIs for every specific screen.
  24. Another method must be used.
  25. One size fits all
  26. -----------------
  27. The most common approach is to use a single *base* resolution and
  28. then fit it to everything else. This resolution is how most players are expected
  29. to play the game (given their hardware). For mobile, Google has useful `stats
  30. <https://developer.android.com/about/dashboards>`_ online, and for desktop,
  31. Steam `also does <https://store.steampowered.com/hwsurvey/>`_.
  32. As an example, Steam shows that the most common *primary display resolution* is
  33. 1920×1080, so a sensible approach is to develop a game for this resolution, then
  34. handle scaling for different sizes and aspect ratios.
  35. Godot provides several useful tools to do this easily.
  36. .. seealso::
  37. You can see how Godot's support for multiple resolutions works in action using the
  38. `Multiple Resolutions and Aspect Ratios demo project <https://github.com/godotengine/godot-demo-projects/tree/master/gui/multiple_resolutions>`__.
  39. Base size
  40. ---------
  41. A base size for the window can be specified in the Project Settings under
  42. **Display → Window**.
  43. .. image:: img/screenres.webp
  44. However, what it does is not completely obvious; the engine will *not*
  45. attempt to switch the monitor to this resolution. Rather, think of this
  46. setting as the "design size", i.e. the size of the area that you work
  47. with in the editor. This setting corresponds directly to the size of the
  48. blue rectangle in the 2D editor.
  49. There is often a need to support devices with screen and window sizes
  50. that are different from this base size. Godot offers many ways to
  51. control how the viewport will be resized and stretched to different
  52. screen sizes.
  53. .. note::
  54. On this page, *window* refers to the screen area allotted to your game
  55. by the system, while *viewport* refers to the root object (accessible
  56. from ``get_tree().root``) which the game controls to fill this screen area.
  57. This viewport is a :ref:`Window <class_Window>` instance. Recall from the
  58. :ref:`introduction <doc_viewports>` that *all* Window objects are viewports.
  59. To configure the stretch base size at runtime from a script, use the
  60. ``get_tree().root.content_scale_size`` property (see
  61. :ref:`Window.content_scale_size <class_Window_property_content_scale_size>`).
  62. Changing this value can indirectly change the size of 2D elements. However, to
  63. provide a user-accessible scaling option, using
  64. :ref:`doc_multiple_resolutions_stretch_scale` is recommended as it's easier to
  65. adjust.
  66. .. note::
  67. Godot follows a modern approach to multiple resolutions. The engine will
  68. never change the monitor's resolution on its own. While changing the
  69. monitor's resolution is the most efficient approach, it's also the least
  70. reliable approach as it can leave the monitor stuck on a low resolution if
  71. the game crashes. This is especially common on macOS or Linux which don't
  72. handle resolution changes as well as Windows.
  73. Changing the monitor's resolution also removes any control from the game
  74. developer over filtering and aspect ratio stretching, which can be important
  75. to ensure correct display for pixel art games.
  76. On top of that, changing the monitor's resolution makes alt-tabbing in and
  77. out of a game much slower since the monitor has to change resolutions every
  78. time this is done.
  79. Resizing
  80. --------
  81. There are several types of devices, with several types of screens, which
  82. in turn have different pixel density and resolutions. Handling all of
  83. them can be a lot of work, so Godot tries to make the developer's life a
  84. little easier. The :ref:`Viewport <class_Viewport>`
  85. node has several functions to handle resizing, and the root node of the
  86. scene tree is always a viewport (scenes loaded are instanced as a child
  87. of it, and it can always be accessed by calling
  88. ``get_tree().root`` or ``get_node("/root")``).
  89. In any case, while changing the root Viewport params is probably the
  90. most flexible way to deal with the problem, it can be a lot of work,
  91. code and guessing, so Godot provides a set of parameters in the
  92. project settings to handle multiple resolutions.
  93. .. tip::
  94. To render 3D at a lower resolution than 2D elements (without needing
  95. separate viewports), you can use Godot's
  96. :ref:`resolution scaling <doc_resolution_scaling>` support. This is a good way
  97. to improve performance significantly in GPU-bottlenecked scenarios.
  98. This works with any stretch mode and stretch aspect combination.
  99. Stretch settings
  100. ----------------
  101. Stretch settings are located in the project settings and provide several options:
  102. .. image:: img/stretchsettings.webp
  103. Stretch Mode
  104. ~~~~~~~~~~~~
  105. The **Stretch Mode** setting defines how the base size is stretched to fit
  106. the resolution of the window or screen. The animations below use a "base
  107. size" of just 16×9 pixels to demonstrate the effect of different stretch
  108. modes. A single sprite, also 16×9 pixels in size, covers the entire viewport,
  109. and a diagonal :ref:`Line2D <class_Line2D>` is added on top of it:
  110. .. image:: img/stretch_demo_scene.png
  111. .. Animated GIFs are generated from:
  112. .. https://github.com/ttencate/godot_scaling_mode
  113. - **Stretch Mode = Disabled** (default): No stretching happens. One
  114. unit in the scene corresponds to one pixel on the screen. In this
  115. mode, the **Stretch Aspect** setting has no effect.
  116. .. image:: img/stretch_disabled_expand.gif
  117. - **Stretch Mode = Canvas Items**: In this mode, the base size specified in
  118. width and height in the project settings is
  119. stretched to cover the whole screen (taking the **Stretch Aspect**
  120. setting into account). This means that everything is rendered
  121. directly at the target resolution. 3D is unaffected,
  122. while in 2D, there is no longer a 1:1 correspondence between sprite
  123. pixels and screen pixels, which may result in scaling artifacts.
  124. .. image:: img/stretch_2d_expand.gif
  125. - **Stretch Mode = Viewport**: Viewport scaling means that the size of
  126. the root :ref:`Viewport <class_Viewport>` is set precisely to the
  127. base size specified in the Project Settings' **Display** section.
  128. The scene is rendered to this viewport first. Finally, this viewport
  129. is scaled to fit the screen (taking the **Stretch Aspect** setting into
  130. account).
  131. .. image:: img/stretch_viewport_expand.gif
  132. To configure the stretch mode at runtime from a script, use the
  133. ``get_tree().root.content_scale_mode`` property (see
  134. :ref:`Window.content_scale_mode <class_Window_property_content_scale_mode>`
  135. and the :ref:`ContentScaleMode <enum_Window_ContentScaleMode>` enum).
  136. Stretch Aspect
  137. ~~~~~~~~~~~~~~
  138. The second setting is the stretch aspect. Note that this only takes effect if
  139. **Stretch Mode** is set to something other than **Disabled**.
  140. In the animations below, you will notice gray and black areas. The black
  141. areas are added by the engine and cannot be drawn into. The gray areas
  142. are part of your scene, and can be drawn to. The gray areas correspond
  143. to the region outside the blue frame you see in the 2D editor.
  144. - **Stretch Aspect = Ignore**: Ignore the aspect ratio when stretching
  145. the screen. This means that the original resolution will be stretched
  146. to exactly fill the screen, even if it's wider or narrower. This may
  147. result in nonuniform stretching: things looking wider or taller than
  148. designed.
  149. .. image:: img/stretch_viewport_ignore.gif
  150. - **Stretch Aspect = Keep**: Keep aspect ratio when stretching the
  151. screen. This means that the viewport retains its original size
  152. regardless of the screen resolution, and black bars will be added to
  153. the top/bottom of the screen ("letterboxing") or the sides
  154. ("pillarboxing").
  155. This is a good option if you know the aspect ratio of your target
  156. devices in advance, or if you don't want to handle different aspect
  157. ratios.
  158. .. image:: img/stretch_viewport_keep.gif
  159. - **Stretch Aspect = Keep Width**: Keep aspect ratio when stretching the
  160. screen. If the screen is wider than the base size, black bars are
  161. added at the left and right (pillarboxing). But if the screen is
  162. taller than the base resolution, the viewport will be grown in the
  163. vertical direction (and more content will be visible to the bottom).
  164. You can also think of this as "Expand Vertically".
  165. This is usually the best option for creating GUIs or HUDs that scale,
  166. so some controls can be anchored to the bottom
  167. (:ref:`doc_size_and_anchors`).
  168. .. image:: img/stretch_viewport_keep_width.gif
  169. - **Stretch Aspect = Keep Height**: Keep aspect ratio when stretching
  170. the screen. If the screen is taller than the base size, black
  171. bars are added at the top and bottom (letterboxing). But if the
  172. screen is wider than the base resolution, the viewport will be grown
  173. in the horizontal direction (and more content will be visible to the
  174. right). You can also think of this as "Expand Horizontally".
  175. This is usually the best option for 2D games that scroll horizontally
  176. (like runners or platformers).
  177. .. image:: img/stretch_viewport_keep_height.gif
  178. - **Stretch Aspect = Expand**: Keep aspect ratio when stretching the
  179. screen, but keep neither the base width nor height. Depending on the
  180. screen aspect ratio, the viewport will either be larger in the
  181. horizontal direction (if the screen is wider than the base size) or
  182. in the vertical direction (if the screen is taller than the original
  183. size).
  184. .. image:: img/stretch_viewport_expand.gif
  185. .. tip::
  186. To support both portrait and landscape mode with a similar automatically
  187. determined scale factor, set your project's base resolution to be a *square*
  188. (1:1 aspect ratio) instead of a rectangle. For instance, if you wish to design
  189. for 1280×720 as the base resolution but wish to support both portrait and
  190. landscape mode, use 720×720 as the project's base window size in the
  191. Project Settings.
  192. To allow the user to choose their preferred screen orientation at runtime,
  193. remember to set **Display > Window > Handheld > Orientation** to ``sensor``.
  194. To configure the stretch aspect at runtime from a script, use the
  195. ``get_tree().root.content_scale_aspect`` property (see
  196. :ref:`Window.content_scale_aspect <class_Window_property_content_scale_aspect>`
  197. and the :ref:`ContentScaleAspect <enum_Window_ContentScaleAspect>` enum).
  198. .. _doc_multiple_resolutions_stretch_scale:
  199. Stretch Scale
  200. ~~~~~~~~~~~~~
  201. The **Scale** setting allows you to add an extra scaling factor on top of
  202. what the **Stretch** options above already provide. The default value of ``1.0``
  203. means that no additional scaling occurs.
  204. For example, if you set **Scale** to ``2.0`` and leave **Stretch Mode** on
  205. **Disabled**, each unit in your scene will correspond to 2×2 pixels on the
  206. screen. This is a good way to provide scaling options for non-game applications.
  207. If **Stretch Mode** is set to **canvas_items**, 2D elements will be scaled
  208. relative to the base window size, then multiplied by the **Scale** setting. This
  209. can be exposed to players to allow them to adjust the automatically determined
  210. scale to their liking, for better accessibility.
  211. If **Stretch Mode** is set to **viewport**, the viewport's resolution is divided
  212. by **Scale**. This makes pixels look larger and reduces rendering resolution
  213. (with a given window size), which can improve performance.
  214. To configure the stretch scale at runtime from a script, use the
  215. ``get_tree().root.content_scale_factor`` property (see
  216. :ref:`Window.content_scale_factor <class_Window_property_content_scale_factor>`).
  217. .. _doc_multiple_resolutions_stretch_scale_mode:
  218. Stretch Scale Mode
  219. ~~~~~~~~~~~~~~~~~~
  220. Since Godot 4.2, the **Stretch Scale Mode** setting allows you to constrain the
  221. automatically determined scale factor (as well as the manually specified
  222. **Stretch Scale** setting) to integer values. By default, this setting is set to
  223. ``fractional``, which allows any scale factor to be applied (including fractional
  224. values such as ``2.5``). When set to ``integer``, the value is rounded down to
  225. the nearest integer. For example, instead of using a scale factor of ``2.5``, it
  226. would be rounded down to ``2.0``. This is useful to prevent distortion when
  227. displaying pixel art.
  228. Compare this pixel art which is displayed with the ``viewport`` stretch mode,
  229. with the stretch scale mode set to ``fractional``:
  230. .. figure:: img/multiple_resolutions_pixel_art_fractional_scaling.webp
  231. :align: center
  232. :alt: Fractional scaling example (incorrect pixel art appearance)
  233. Checkerboard doesn't look "even". Line widths in the logo and text varies wildly.
  234. This pixel art is also displayed with the ``viewport`` stretch mode, but the
  235. stretch scale mode is set to ``integer`` this time:
  236. .. figure:: img/multiple_resolutions_pixel_art_integer_scaling.webp
  237. :align: center
  238. :alt: Integer scaling example (correct pixel art appearance)
  239. Checkerboard looks perfectly even. Line widths are consistent.
  240. For example, if your viewport base size is 640×360 and the window size is 1366×768:
  241. - When using ``fractional``, the viewport is displayed at a resolution of
  242. 1366×768 (scale factor is roughly 2.133×). The entire window space is used.
  243. Each pixel in the viewport corresponds to 2.133×2.133 pixels in the displayed
  244. area. However, since displays can only display "whole" pixels, this will lead
  245. to uneven pixel scaling which results in incorrect appearance of pixel art.
  246. - When using ``integer``, the viewport is displayed at a resolution of 1280×720
  247. (scale factor is 2×). The remaining space is filled with black bars on all
  248. four sides, so that each pixel in the viewport corresponds to 2×2 pixels in
  249. the displayed area.
  250. This setting is effective with any stretch mode. However, when using the
  251. ``disabled`` stretch mode, it will only affect the **Stretch Scale** setting by
  252. rounding it *down* to the nearest integer value. This can be used for 3D games
  253. that have a pixel art UI, so that the visible area in the 3D viewport doesn't
  254. reduce in size (which occurs when using ``canvas_items`` or ``viewport`` stretch
  255. mode with the ``integer`` scale mode).
  256. .. tip::
  257. Games should use the **Exclusive Fullscreen** window mode, as opposed to
  258. **Fullscreen** which is designed to prevent Windows from automatically
  259. treating the window as if it was exclusive fullscreen.
  260. **Fullscreen** is meant to be used by GUI applications that want to use
  261. per-pixel transparency without a risk of having it disabled by the OS. It
  262. achieves this by leaving a 1-pixel line at the bottom of the screen. By
  263. contrast, **Exclusive Fullscreen** uses the actual screen size and allows
  264. Windows to reduce jitter and input lag for fullscreen games.
  265. When using integer scaling, this is particularly important as the 1-pixel
  266. height reduction from the **Fullscreen** mode can cause integer scaling to
  267. use a smaller scale factor than expected.
  268. Common use case scenarios
  269. -------------------------
  270. The following settings are recommended to support multiple resolutions and aspect
  271. ratios well.
  272. Desktop game
  273. ~~~~~~~~~~~~
  274. **Non-pixel art:**
  275. - Set the base window width to ``1920`` and window height to ``1080``. If you have a
  276. display smaller than 1920×1080, set **Window Width Override** and **Window Height Override** to
  277. lower values to make the window smaller when the project starts.
  278. - Alternatively, if you're targeting high-end devices primarily, set the base
  279. window width to ``3840`` and window height to ``2160``.
  280. This allows you to provide higher resolution 2D assets, resulting in crisper
  281. visuals at the cost of higher memory usage and file sizes.
  282. Note that this will make non-mipmapped textures grainy on low resolution devices,
  283. so make sure to follow the instructions described in
  284. :ref:`doc_multiple_resolutions_reducing_aliasing_on_downsampling`.
  285. - Set the stretch mode to ``canvas_items``.
  286. - Set the stretch aspect to ``expand``. This allows for supporting multiple aspect ratios
  287. and makes better use of tall smartphone displays (such as 18:9 or 19:9 aspect ratios).
  288. - Configure Control nodes' anchors to snap to the correct corners using the **Layout** menu.
  289. - For 3D games, consider exposing :ref:`doc_resolution_scaling` in the game's options menu
  290. to allow players to adjust the 3D rendering resolution separately from UI elements.
  291. This is useful for performance tuning, especially on lower-end hardware.
  292. **Pixel art:**
  293. - Set the base window size to the viewport size you intend to use. Most pixel
  294. art games use viewport sizes between 256×224 and 640×480. 640×360 is a good
  295. baseline, as it scales to 1280×720, 1920×1080, 2560×1440, and 3840×2160 without
  296. any black bars when using integer scaling. Higher viewport sizes will require
  297. using higher resolution artwork, unless you intend to show more of the game
  298. world at a given time.
  299. - Set the stretch mode to ``viewport``.
  300. - Set the stretch aspect to ``keep`` to enforce a single aspect ratio (with
  301. black bars). As an alternative, you can set the stretch aspect to ``expand`` to
  302. support multiple aspect ratios.
  303. - If using the ``expand`` stretch aspect, Configure Control nodes' anchors to
  304. snap to the correct corners using the **Layout** menu.
  305. - Set the stretch scale mode to ``integer``. This prevents uneven pixel scaling
  306. from occurring, which makes pixel art not display as intended.
  307. .. note::
  308. The ``viewport`` stretch mode provides low-resolution rendering that is then
  309. stretched to the final window size. If you are OK with sprites being able to
  310. move or rotate in "sub-pixel" positions or wish to have a high resolution 3D
  311. viewport, you should use the ``canvas_items`` stretch mode instead of the ``viewport``
  312. stretch mode.
  313. Mobile game in landscape mode
  314. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  315. Godot is configured to use landscape mode by default. This means you don't need
  316. to change the display orientation project setting.
  317. - Set the base window width to ``1280`` and window height to ``720``.
  318. - Alternatively, if you're targeting high-end devices primarily, set the base
  319. window width to ``1920`` and window height to ``1080``.
  320. This allows you to provide higher resolution 2D assets, resulting in crisper
  321. visuals at the cost of higher memory usage and file sizes. Many devices have
  322. even higher resolution displays (1440p), but the difference with 1080p is
  323. barely visible given the small size of smartphone displays.
  324. Note that this will make non-mipmapped textures grainy on low resolution devices,
  325. so make sure to follow the instructions described in
  326. :ref:`doc_multiple_resolutions_reducing_aliasing_on_downsampling`.
  327. - Set the stretch mode to ``canvas_items``.
  328. - Set the stretch aspect to ``expand``. This allows for supporting multiple aspect ratios
  329. and makes better use of tall smartphone displays (such as 18:9 or 19:9 aspect ratios).
  330. - Configure Control nodes' anchors to snap to the correct corners using the **Layout** menu.
  331. .. tip::
  332. To better support tablets and foldable phones (which frequently feature
  333. displays with aspect ratios close to 4:3), consider using a base resolution
  334. that has a 4:3 aspect ratio while following the rest of the instructions
  335. here. For instance, you can set the base window width to ``1280`` and the
  336. base window height to ``960``.
  337. Mobile game in portrait mode
  338. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  339. - Set the base window width to ``720`` and window height to ``1280``.
  340. - Alternatively, if you're targeting high-end devices primarily, set the base
  341. window width to ``1080`` and window height to ``1920``.
  342. This allows you to provide higher resolution 2D assets, resulting in crisper
  343. visuals at the cost of higher memory usage and file sizes. Many devices have
  344. even higher resolution displays (1440p), but the difference with 1080p is
  345. barely visible given the small size of smartphone displays.
  346. Note that this will make non-mipmapped textures grainy on low resolution devices,
  347. so make sure to follow the instructions described in
  348. :ref:`doc_multiple_resolutions_reducing_aliasing_on_downsampling`.
  349. - Set **Display > Window > Handheld > Orientation** to ``portrait``.
  350. - Set the stretch mode to ``canvas_items``.
  351. - Set the stretch aspect to ``expand``. This allows for supporting multiple aspect ratios
  352. and makes better use of tall smartphone displays (such as 18:9 or 19:9 aspect ratios).
  353. - Configure Control nodes' anchors to snap to the correct corners using the **Layout** menu.
  354. .. tip::
  355. To better support tablets and foldable phones (which frequently feature
  356. displays with aspect ratios close to 4:3), consider using a base resolution
  357. that has a 3:4 aspect ratio while following the rest of the instructions
  358. here. For instance, you can set the base window width to ``960`` and the
  359. base window height to ``1280``.
  360. Non-game application
  361. ~~~~~~~~~~~~~~~~~~~~
  362. - Set the base window width and height to the smallest window size that you intend to target.
  363. This is not required, but this ensures that you design your UI with small window sizes in mind.
  364. - Keep the stretch mode to its default value, ``disabled``.
  365. - Keep the stretch aspect to its default value, ``ignore``
  366. (its value won't be used since the stretch mode is ``disabled``).
  367. - You can define a minimum window size by calling ``get_window().set_min_size()`` in a
  368. script's ``_ready()`` function. This prevents the user from resizing the application
  369. below a certain size, which could break the UI layout.
  370. .. UPDATE: Planned feature. When manually override the 2D scale factor is supported,
  371. .. update this note.
  372. .. note::
  373. Godot doesn't support manually overriding the 2D scale factor yet, so it is
  374. not possible to have hiDPI support in non-game applications. Due to this, it
  375. is recommended to leave **Allow Hidpi** disabled in non-game applications to
  376. allow for the OS to use its low-DPI fallback.
  377. hiDPI support
  378. -------------
  379. By default, Godot projects are considered DPI-aware by the operating system.
  380. This is controlled by the **Display > Window > Dpi > Allow Hidpi** project setting,
  381. which should be left enabled whenever possible. Disabling DPI awareness can break
  382. fullscreen behavior on Windows.
  383. Since Godot projects are DPI-aware, they may appear at a very small window size
  384. when launching on an hiDPI display (proportionally to the screen resolution).
  385. For a game, the most common way to work around this issue is to make them
  386. fullscreen by default. Alternatively, you could set the window size in an
  387. :ref:`autoload <doc_singletons_autoload>`'s ``_ready()`` function according to
  388. the screen size.
  389. To ensure 2D elements don't appear too small on hiDPI displays:
  390. - For games, use the ``canvas_items`` or ``viewport`` stretch modes so that 2D
  391. elements are automatically resized according to the current window size.
  392. - For non-game applications, use the ``disabled`` stretch mode and set the
  393. stretch scale to a value corresponding to the display scale factor in an
  394. :ref:`autoload <doc_singletons_autoload>`'s ``_ready()`` function.
  395. The display scale factor is set in the operating system's settings and can be queried
  396. using :ref:`screen_get_scale<class_DisplayServer_method_screen_get_scale>`. This
  397. method is currently only implemented on macOS. On other operating systems, you
  398. will need to implement a method to guess the display scale factor based on the
  399. screen resolution (with a setting to let the user override this if needed). This
  400. is the approach currently used by the Godot editor.
  401. The **Allow Hidpi** setting is only effective on Windows and macOS. It's ignored
  402. on all other platforms.
  403. .. note::
  404. The Godot editor itself is always marked as DPI-aware. Running the project
  405. from the editor will only be DPI-aware if **Allow Hidpi** is enabled in the
  406. Project Settings.
  407. .. _doc_multiple_resolutions_reducing_aliasing_on_downsampling:
  408. Reducing aliasing on downsampling
  409. ---------------------------------
  410. If the game has a very high base resolution (e.g. 3840×2160), aliasing might
  411. appear when downsampling to something considerably lower like 1280×720.
  412. To resolve this, you can :ref:`enable mipmaps <doc_importing_images_mipmaps>` on
  413. all your 2D textures. However, enabling mipmaps will increase memory usage which
  414. can be an issue on low-end mobile devices.
  415. Handling aspect ratios
  416. ----------------------
  417. Once scaling for different resolutions is accounted for, make sure that
  418. your *user interface* also scales for different aspect ratios. This can be
  419. done using :ref:`anchors <doc_size_and_anchors>` and/or :ref:`containers
  420. <doc_gui_containers>`.
  421. Field of view scaling
  422. ---------------------
  423. The 3D Camera node's **Keep Aspect** property defaults to the **Keep Height**
  424. scaling mode (also called *Hor+*). This is usually the best value for desktop
  425. games and mobile games in landscape mode, as widescreen displays will
  426. automatically use a wider field of view.
  427. However, if your 3D game is intended to be played in portrait mode, it may make
  428. more sense to use **Keep Width** instead (also called *Vert-*). This way,
  429. smartphones with an aspect ratio taller than 16:9 (e.g. 19:9) will use a
  430. *taller* field of view, which is more logical here.
  431. Scaling 2D and 3D elements differently using Viewports
  432. ------------------------------------------------------
  433. Using multiple Viewport nodes, you can have different scales for various
  434. elements. For instance, you can use this to render the 3D world at a low
  435. resolution while keeping 2D elements at the native resolution. This can improve
  436. performance significantly while keeping the HUD and other 2D elements crisp.
  437. This is done by using the root Viewport node only for 2D elements, then creating
  438. a Viewport node to display the 3D world and displaying it using a
  439. SubViewportContainer or TextureRect node. There will effectively be two viewports
  440. in the final project. One upside of using TextureRect over SubViewportContainer is
  441. that it allows enable linear filtering. This makes scaled 3D viewports look
  442. better in many cases.
  443. See the
  444. `3D viewport scaling demo <https://github.com/godotengine/godot-demo-projects/tree/master/viewport/3d_scaling>`__
  445. for examples.