variable_rate_shading.rst 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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 Plus and Forward Mobile rendering methods support variable rate
  61. shading. VRS can be used in both pancake (non-XR) and XR display modes.
  62. The Compatibility rendering method does **not** support variable rate
  63. shading.
  64. In the advanced Project Settings, the **Rendering > VRS** section offers settings
  65. to control variable rate shading on the root viewport:
  66. - **Mode:** Controls the variable rate shading mode. **Disabled** disables
  67. variable rate shading. **Texture** uses a manually authored texture to set
  68. shading density (see the property below). **XR** automatically generates a
  69. texture suited for foveated rendering in virtual/augmented reality.
  70. - **Texture:** The texture to use to control shading density on the root
  71. viewport. Only used if **Mode** is **Texture**.
  72. For custom viewports, the VRS mode and texture must be set manually to the
  73. :ref:`class_Viewport` node.
  74. .. note::
  75. On unsupported hardware, there is no visual difference when variable rate
  76. shading is enabled. You can check whether hardware supports variable rate
  77. shading by running the editor or project with the ``--verbose``
  78. :ref:`command line argument <doc_command_line_tutorial>`.
  79. Creating a VRS density map
  80. ^^^^^^^^^^^^^^^^^^^^^^^^^^
  81. If using the **Texture** VRS mode, you *must* set a texture to be used as a
  82. density map. Otherwise, no effect will be visible.
  83. You can create your own VRS density map manually using an image editor, or
  84. generate it using another method (e.g. on the CPU using the Image class, or on
  85. the GPU using a shader). However, beware of performance implications when
  86. generating a VRS image dynamically. If opting for dynamic generation, make sure
  87. the VRS image generation process is fast enough to avoid outweighing the
  88. performance gains from VRS.
  89. The texture must follow these rules:
  90. - The texture *must* use a lossless compression format so that colors can be
  91. matched precisely.
  92. - The following VRS densities are mapped to various colors, with brighter colors
  93. representing a lower level of shading precision:
  94. +----------------------+--------------------------------+---------------------------------+
  95. | Density | Color | Comment |
  96. +======================+================================+=================================+
  97. | 1×1 (highest detail) | ``rgb(0, 0, 0) - #000000`` | |
  98. +----------------------+--------------------------------+---------------------------------+
  99. | 1×2 | ``rgb(0, 85, 0) - #005500`` | |
  100. +----------------------+--------------------------------+---------------------------------+
  101. | 2×1 | ``rgb(85, 0, 0) - #550000`` | |
  102. +----------------------+--------------------------------+---------------------------------+
  103. | 2×2 | ``rgb(85, 85, 0) - #555500`` | |
  104. +----------------------+--------------------------------+---------------------------------+
  105. | 2×4 | ``rgb(85, 170, 0) - #55aa00`` | |
  106. +----------------------+--------------------------------+---------------------------------+
  107. | 4×2 | ``rgb(170, 85, 0) - #aa5500`` | |
  108. +----------------------+--------------------------------+---------------------------------+
  109. | 4×4 | ``rgb(170, 170, 0) - #aaaa00`` | |
  110. +----------------------+--------------------------------+---------------------------------+
  111. | 4×8 | ``rgb(170, 255, 0) - #aaff00`` | Not supported on most hardware. |
  112. +----------------------+--------------------------------+---------------------------------+
  113. | 8×4 | ``rgb(255, 170, 0) - #ffaa00`` | Not supported on most hardware. |
  114. +----------------------+--------------------------------+---------------------------------+
  115. | 8×8 (lowest detail) | ``rgb(255, 255, 0) - #ffff00`` | Not supported on most hardware. |
  116. +----------------------+--------------------------------+---------------------------------+
  117. For example, this VRS density texture provides the highest shading density in
  118. the center of the viewport, and the lowest shading density in the corners:
  119. .. figure:: img/variable_rate_shading_texture_example.webp
  120. :align: center
  121. :alt: Example VRS density map texture, simulating foveated rendering
  122. Example VRS density map texture, simulating foveated rendering
  123. There are no size or aspect ratio requirements for the VRS density texture.
  124. However, there is no benefit to using a VRS density map that is larger than the
  125. viewport resolution divided by the GPU's *tile size*. The tile size is what
  126. determines the smallest area of pixels where the shading density can be changed
  127. separately from other tiles. On most GPUs, this tile size is 8×8 pixels. You can
  128. view the tile size by running Godot with the ``--verbose`` command line
  129. argument, as it's printed in the VRS debugging information.
  130. Therefore, sticking to a relatively low resolution such as 256×256 (square) or
  131. 480×270 (16:9) is recommended. Depending on your use cases, a square texture may
  132. be more suited compared to a texture that matches the most common viewport
  133. aspect ratio in your project (such as 16:9).
  134. .. tip::
  135. When using variable rate shading, you can use a negative
  136. :ref:`texture mipmap LOD bias <doc_resolution_scaling_mipmap_bias>`
  137. to reduce blurriness in areas with reduced shading rate.
  138. Note that the texture LOD bias is set globally, so this will also affect
  139. areas of the viewport with full shading rate. Don't use values that are too
  140. low, or textures will appear grainy.
  141. Performance comparison
  142. ^^^^^^^^^^^^^^^^^^^^^^
  143. To give an idea of how much VRS can improve performance in theory, here's a
  144. performance comparison with the textured example scene shown at the top of this
  145. page. The VRS density map example present on this page is used.
  146. Results were captured on a GeForce RTX 4090 with the NVIDIA 525.60.11 driver.
  147. +---------------------+--------------+-------------+-------------------------+
  148. | Resolution | VRS disabled | VRS enabled | Performance improvement |
  149. +=====================+==============+=============+=========================+
  150. | 1920×1080 (Full HD) | 2832 FPS | 3136 FPS | +10.7% |
  151. +---------------------+--------------+-------------+-------------------------+
  152. | 2560×1440 (QHD) | 2008 FPS | 2256 FPS | +12.3% |
  153. +---------------------+--------------+-------------+-------------------------+
  154. | 3840×2160 (4K) | 1236 FPS | 1436 FPS | +16.2% |
  155. +---------------------+--------------+-------------+-------------------------+
  156. | 7680×4320 (8K) | 384 FPS | 473 FPS | +23.1% |
  157. +---------------------+--------------+-------------+-------------------------+
  158. In terms of performance improvements, variable rate shading is more beneficial
  159. at higher target resolutions. The reduction in visual quality is also less
  160. noticeable at high resolutions.
  161. .. note::
  162. For non-VR games, you will probably have to use a less aggressive VRS texture
  163. than what was used in this example. As a result, the effective performance
  164. gains will be lower.