variable_rate_shading.rst 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. .. _doc_variable_rate_shading:
  2. Variable rate shading
  3. =====================
  4. What is variable rate shading?
  5. ------------------------------
  6. In modern 3D rendering engines, shaders are much more complex compared to
  7. before. The advent of physically-based rendering, real-time global illumination
  8. and screen-space effects has increased the number of *per-pixel* shading that
  9. must be performed to render each frame. Additionally, screen resolutions also
  10. have increased a lot, with 1440p and 4K now being common target resolutions.
  11. As a result, the total shading cost in scene rendering usually represents
  12. a significant amount of the time taken to render each frame.
  13. Variable rate shading (VRS) is a method of decreasing this shading cost by
  14. reducing the resolution of *per-pixel* shading (also called *fragment* shading),
  15. while keeping the original resolution for rendering geometry. This means geometry
  16. edges remain as sharp as they would without VRS. VRS can be combined with any
  17. :ref:`doc_3d_antialiasing` technique (MSAA, FXAA, TAA, SSAA).
  18. VRS allows specifying the shading quality in a local manner, which makes it
  19. possible to have certain parts of the viewport receive more detailed shading
  20. than others. This is particularly useful in virtual reality (VR) to achieve
  21. *foveated rendering*, where the center of the viewport is more detailed than the
  22. edges.
  23. Here's a scene rendered with rate shading disabled then enabled, using the
  24. density map linked at the bottom of this page:
  25. .. figure:: img/variable_rate_shading_textured_disabled.webp
  26. :align: center
  27. :alt: Variable rate shading disabled in textured scene
  28. Variable rate shading disabled in textured scene
  29. .. figure:: img/variable_rate_shading_textured_enabled.webp
  30. :align: center
  31. :alt: Variable rate shading enabled in textured scene (lower quality, but higher performance)
  32. Variable rate shading enabled in textured scene (lower quality, but higher performance)
  33. When used in scenes with low-frequency detail (such as scenes with a
  34. stylized/low-poly aesthetic), it's possible to achieve similar performance gains,
  35. but with less reduction in visual quality:
  36. .. figure:: img/variable_rate_shading_untextured_disabled.webp
  37. :align: center
  38. :alt: Variable rate shading disabled in untextured scene
  39. Variable rate shading disabled in untextured scene
  40. .. figure:: img/variable_rate_shading_untextured_enabled.webp
  41. :align: center
  42. :alt: Variable rate shading enabled in untextured scene (lower quality, but higher performance)
  43. Variable rate shading enabled in untextured scene (lower quality, but higher performance)
  44. Hardware support
  45. ----------------
  46. Variable rate shading is only supported on specific GPUs:
  47. **Desktop:**
  48. - NVIDIA Turing and newer (including GTX 1600 series)
  49. - AMD RDNA2 and newer (both integrated and dedicated GPUs – including Steam Deck)
  50. - Intel Arc Alchemist and newer **(dedicated GPUs only)**
  51. - Intel integrated graphics do not support variable rate shading.
  52. **Mobile SoCs:**
  53. - Snapdragon 888 and newer
  54. - MediaTek Dimensity 9000 and newer
  55. - ARM Mali-G615 and newer
  56. As of January 2023, Apple and Raspberry Pi GPUs do not support variable rate shading.
  57. Using variable rate shading in Godot
  58. ------------------------------------
  59. .. note::
  60. Both Forward+ and Mobile renderers support variable rate
  61. shading. VRS can be used in both pancake (non-XR) and XR display modes.
  62. The Compatibility renderer does **not** support variable rate shading.
  63. For XR, you can use :ref:`foveation level <doc_openxr_settings_foveation_level>`
  64. as an alternative.
  65. In the advanced Project Settings, the **Rendering > VRS** section offers settings
  66. to control variable rate shading on the root viewport:
  67. - **Mode:** Controls the variable rate shading mode. **Disabled** disables
  68. variable rate shading. **Texture** uses a manually authored texture to set
  69. shading density (see the property below). **XR** automatically generates a
  70. texture suited for foveated rendering in virtual/augmented reality.
  71. - **Texture:** The texture to use to control shading density on the root
  72. viewport. Only used if **Mode** is **Texture**.
  73. For custom viewports, the VRS mode and texture must be set manually to the
  74. :ref:`class_Viewport` node.
  75. .. note::
  76. On unsupported hardware, there is no visual difference when variable rate
  77. shading is enabled. You can check whether hardware supports variable rate
  78. shading by running the editor or project with the ``--verbose``
  79. :ref:`command line argument <doc_command_line_tutorial>`.
  80. Creating a VRS density map
  81. ^^^^^^^^^^^^^^^^^^^^^^^^^^
  82. If using the **Texture** VRS mode, you *must* set a texture to be used as a
  83. density map. Otherwise, no effect will be visible.
  84. You can create your own VRS density map manually using an image editor, or
  85. generate it using another method (e.g. on the CPU using the Image class, or on
  86. the GPU using a shader). However, beware of performance implications when
  87. generating a VRS image dynamically. If opting for dynamic generation, make sure
  88. the VRS image generation process is fast enough to avoid outweighing the
  89. performance gains from VRS.
  90. The texture must follow these rules:
  91. - The texture *must* use a lossless compression format so that colors can be
  92. matched precisely.
  93. - The following VRS densities are mapped to various colors, with brighter colors
  94. representing a lower level of shading precision:
  95. +----------------------+--------------------------------+---------------------------------+
  96. | Density | Color | Comment |
  97. +======================+================================+=================================+
  98. | 1×1 (highest detail) | ``rgb(0, 0, 0) - #000000`` | |
  99. +----------------------+--------------------------------+---------------------------------+
  100. | 1×2 | ``rgb(0, 85, 0) - #005500`` | |
  101. +----------------------+--------------------------------+---------------------------------+
  102. | 2×1 | ``rgb(85, 0, 0) - #550000`` | |
  103. +----------------------+--------------------------------+---------------------------------+
  104. | 2×2 | ``rgb(85, 85, 0) - #555500`` | |
  105. +----------------------+--------------------------------+---------------------------------+
  106. | 2×4 | ``rgb(85, 170, 0) - #55aa00`` | |
  107. +----------------------+--------------------------------+---------------------------------+
  108. | 4×2 | ``rgb(170, 85, 0) - #aa5500`` | |
  109. +----------------------+--------------------------------+---------------------------------+
  110. | 4×4 | ``rgb(170, 170, 0) - #aaaa00`` | |
  111. +----------------------+--------------------------------+---------------------------------+
  112. | 4×8 | ``rgb(170, 255, 0) - #aaff00`` | Not supported on most hardware. |
  113. +----------------------+--------------------------------+---------------------------------+
  114. | 8×4 | ``rgb(255, 170, 0) - #ffaa00`` | Not supported on most hardware. |
  115. +----------------------+--------------------------------+---------------------------------+
  116. | 8×8 (lowest detail) | ``rgb(255, 255, 0) - #ffff00`` | Not supported on most hardware. |
  117. +----------------------+--------------------------------+---------------------------------+
  118. For example, this VRS density texture provides the highest shading density in
  119. the center of the viewport, and the lowest shading density in the corners:
  120. .. figure:: img/variable_rate_shading_texture_example.webp
  121. :align: center
  122. :alt: Example VRS density map texture, simulating foveated rendering
  123. Example VRS density map texture, simulating foveated rendering
  124. There are no size or aspect ratio requirements for the VRS density texture.
  125. However, there is no benefit to using a VRS density map that is larger than the
  126. viewport resolution divided by the GPU's *tile size*. The tile size is what
  127. determines the smallest area of pixels where the shading density can be changed
  128. separately from other tiles. On most GPUs, this tile size is 8×8 pixels. You can
  129. view the tile size by running Godot with the ``--verbose`` command line
  130. argument, as it's printed in the VRS debugging information.
  131. Therefore, sticking to a relatively low resolution such as 256×256 (square) or
  132. 480×270 (16:9) is recommended. Depending on your use cases, a square texture may
  133. be more suited compared to a texture that matches the most common viewport
  134. aspect ratio in your project (such as 16:9).
  135. .. tip::
  136. When using variable rate shading, you can use a negative
  137. :ref:`texture mipmap LOD bias <doc_resolution_scaling_mipmap_bias>`
  138. to reduce blurriness in areas with reduced shading rate.
  139. Note that the texture LOD bias is set globally, so this will also affect
  140. areas of the viewport with full shading rate. Don't use values that are too
  141. low, or textures will appear grainy.
  142. Performance comparison
  143. ^^^^^^^^^^^^^^^^^^^^^^
  144. To give an idea of how much VRS can improve performance in theory, here's a
  145. performance comparison with the textured example scene shown at the top of this
  146. page. The VRS density map example present on this page is used.
  147. Results were captured on a GeForce RTX 4090 with the NVIDIA 525.60.11 driver.
  148. +---------------------+--------------+-------------+-------------------------+
  149. | Resolution | VRS disabled | VRS enabled | Performance improvement |
  150. +=====================+==============+=============+=========================+
  151. | 1920×1080 (Full HD) | 2832 FPS | 3136 FPS | +10.7% |
  152. +---------------------+--------------+-------------+-------------------------+
  153. | 2560×1440 (QHD) | 2008 FPS | 2256 FPS | +12.3% |
  154. +---------------------+--------------+-------------+-------------------------+
  155. | 3840×2160 (4K) | 1236 FPS | 1436 FPS | +16.2% |
  156. +---------------------+--------------+-------------+-------------------------+
  157. | 7680×4320 (8K) | 384 FPS | 473 FPS | +23.1% |
  158. +---------------------+--------------+-------------+-------------------------+
  159. In terms of performance improvements, variable rate shading is more beneficial
  160. at higher target resolutions. The reduction in visual quality is also less
  161. noticeable at high resolutions.
  162. .. note::
  163. For non-VR games, you will probably have to use a less aggressive VRS texture
  164. than what was used in this example. As a result, the effective performance
  165. gains will be lower.