high_dynamic_range.rst 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. :article_outdated: True
  2. .. _doc_high_dynamic_range:
  3. High dynamic range lighting
  4. ===========================
  5. Introduction
  6. ------------
  7. Normally, an artist does all the 3D modeling, then all the texturing, looks at
  8. their awesome looking model in the 3D modeling software and says "looks
  9. fantastic, ready for integration!" then goes into the game, lighting is setup
  10. and the game runs.
  11. So at what point does all this "HDR" business come into play? To understand
  12. the answer, we need to look at how displays behave.
  13. Your display outputs linear light ratios from some maximum to some minimum
  14. intensity. Modern game engines perform complex math on linear light values in
  15. their respective scenes. So what's the problem?
  16. The display has a limited range of intensity, depending on the display type.
  17. The game engine renders to an unlimited range of intensity values, however.
  18. While "maximum intensity" means something to an sRGB display, it has no bearing
  19. in the game engine; there is only a potentially infinitely wide range
  20. of intensity values generated per frame of rendering.
  21. This means that some transformation of the scene light intensity, also known
  22. as *scene-referred* light ratios, need to be transformed and mapped to fit
  23. within the particular output range of the chosen display. This can be most
  24. easily understood if we consider virtually photographing our game engine scene
  25. through a virtual camera. Here, our virtual camera would apply a particular
  26. camera rendering transform to the scene data, and the output would be ready
  27. for display on a particular display type.
  28. .. note::
  29. Godot does not support high dynamic range *output* yet. It can only perform
  30. lighting in HDR and tonemap the result to a low dynamic range image.
  31. For advanced users, it is still possible to get a non-tonemapped image
  32. of the viewport with full HDR data, which can then be saved to an OpenEXR file.
  33. Computer displays
  34. -----------------
  35. Almost all displays require a nonlinear encoding for the code values sent
  36. to them. The display in turn, using its unique transfer characteristic,
  37. "decodes" the code value into linear light ratios of output, and projects
  38. the ratios out of the uniquely colored lights at each reddish, greenish,
  39. and blueish emission site.
  40. For a majority of computer displays, the specifications of the display are
  41. outlined in accordance with IEC 61966-2-1, also known as the
  42. 1996 sRGB specification. This specification outlines how an sRGB display
  43. is to behave, including the color of the lights in the LED pixels as well as
  44. the transfer characteristics of the input (OETF) and output (EOTF).
  45. Not all displays use the same OETF and EOTF as a computer display.
  46. For example, television broadcast displays use the BT.1886 EOTF.
  47. However, Godot currently only supports sRGB displays.
  48. The sRGB standard is based around the nonlinear relationship between the current
  49. to light output of common desktop computing CRT displays.
  50. .. image:: img/hdr_gamma.png
  51. The mathematics of a scene-referred model require that we multiply the scene by
  52. different values to adjust the intensities and exposure to different
  53. light ranges. The transfer function of the display can't appropriately render
  54. the wider dynamic range of the game engine's scene output using the simple
  55. transfer function of the display. A more complex approach to encoding
  56. is required.
  57. Scene linear & asset pipelines
  58. ------------------------------
  59. Working in scene-linear sRGB is more complex than pressing a single switch. First,
  60. imported image assets must be converted to linear light ratios on import. Even
  61. when linearized, those assets may not be perfectly well-suited for use
  62. as textures, depending on how they were generated.
  63. There are two ways to do this:
  64. sRGB transfer function to display linear ratios on image import
  65. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  66. This is the easiest method of using sRGB assets, but it's not the most ideal.
  67. One issue with this is loss of quality. Using 8 bits per channel to represent
  68. linear light ratios is not sufficient to quantize the values correctly.
  69. These textures may also be compressed later, which can exacerbate the problem.
  70. Hardware sRGB transfer function to display linear conversion
  71. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  72. The GPU will do the conversion after reading the texel using floating-point.
  73. This works fine on PC and consoles, but most mobile devices don't support it,
  74. or they don't support it on compressed texture formats (iOS for example).
  75. Scene linear to display-referred nonlinear
  76. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  77. After all the rendering is done, the scene linear render requires transforming
  78. to a suitable output such as an sRGB display. To do this, enable sRGB conversion
  79. in the current :ref:`Environment <class_Environment>` (more on that below).
  80. Keep in mind that the **sRGB -> Display Linear** and **Display Linear -> sRGB**
  81. conversions must always be **both** enabled. Failing to enable one of them will
  82. result in horrible visuals suitable only for avant-garde experimental
  83. indie games.
  84. Parameters of HDR
  85. -----------------
  86. HDR settings can be found in the :ref:`Environment <class_Environment>`
  87. resource. Most of the time, these are found inside a
  88. :ref:`WorldEnvironment <class_WorldEnvironment>`
  89. node or set in a Camera node. For more information, see
  90. :ref:`doc_environment_and_post_processing`.