high_dynamic_range.rst 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. .. _doc_high_dynamic_range:
  2. High dynamic range
  3. ==================
  4. Introduction
  5. ------------
  6. Normally, an artist does all the 3D modelling, then all the texturing,
  7. looks at their awesome looking model in the 3D DCC and says "looks
  8. fantastic, ready for integration!" then goes into the game, lighting is
  9. setup and the game runs.
  10. So where does all this HDR stuff thing come from? The idea is that
  11. instead of dealing with colors that go from black to white (0 to 1), we
  12. use colors whiter than white (for example, 0 to 8 times white).
  13. To be more practical, imagine that in a regular scene, the intensity
  14. of a light (generally 1.0) is set to 5.0. The whole scene will turn
  15. very bright (towards white) and look horrible.
  16. After this the luminance of the scene is computed by averaging the
  17. luminance of every pixel of it, and this value is used to bring the
  18. scene back to normal ranges. This last operation is called
  19. tone-mapping. Finally, we are at a similar place from where we
  20. started:
  21. .. image:: img/hdr_tonemap.png
  22. Except the scene is more contrasted because there is a higher light
  23. range at play. What is this all useful for? The idea is that the scene
  24. luminance will change while you move through the world, allowing
  25. situations like this to happen:
  26. .. image:: img/hdr_cave.png
  27. Additionally, it is possible to set a threshold value to send to the
  28. glow buffer depending on the pixel luminance. This allows for more
  29. realistic light bleeding effects in the scene.
  30. Linear color space
  31. ------------------
  32. The problem with this technique is that computer monitors apply a
  33. gamma curve to adapt better to the way the human eye sees. Artists
  34. create their art on the screen too, so their art has an implicit gamma
  35. curve applied to it.
  36. The color space where images created in computer monitors exist is
  37. called "sRGB". All visual content that people have on their computers
  38. or download from the internet (such as pictures, movies, etc.)
  39. is in this colorspace.
  40. .. image:: img/hdr_gamma.png
  41. The mathematics of HDR require that we multiply the scene by different
  42. values to adjust the luminance and exposure to different light ranges,
  43. and this curve gets in the way as we need colors in linear space for
  44. this.
  45. Linear color space & asset pipeline
  46. -----------------------------------
  47. Working in HDR is not just pressing a switch. First, imported image
  48. assets must be converted to linear space on import. There are two ways
  49. to do this:
  50. SRGB -> linear conversion on image import
  51. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  52. This is the most compatible way of using linear-space assets, and it will
  53. work everywhere including all mobile devices. The main issue with this
  54. is loss of quality, as sRGB exists to avoid this same problem. Using 8
  55. bits per channel to represent linear colors is inefficient from the
  56. point of view of the human eye. These textures might be later compressed
  57. too which makes the problem worse.
  58. In any case though, this is the easy solution that works everywhere.
  59. Hardware sRGB -> linear conversion.
  60. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  61. This is the most correct way to use assets in linear-space, as the
  62. texture sampler on the GPU will do the conversion after reading the
  63. texel using floating point. This works fine on PC and consoles, but most
  64. mobile devices do no support it, or do not support it on compressed
  65. texture format (iOS for example).
  66. Linear -> sRGB at the end.
  67. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  68. After all the rendering is done, the linear-space rendered image must be
  69. converted back to sRGB. To do this, simply enable sRGB conversion in the
  70. current :ref:`Environment <class_Environment>` (more on that below).
  71. Keep in mind that sRGB -> Linear and Linear -> sRGB conversions
  72. must always be **both** enabled. Failing to enable one of them will
  73. result in horrible visuals suitable only for avant-garde experimental
  74. indie games.
  75. Parameters of HDR
  76. -----------------
  77. HDR is found in the :ref:`Environment <class_Environment>`
  78. resource. These are found most of the time inside a
  79. :ref:`WorldEnvironment <class_WorldEnvironment>`
  80. node or set in a camera. There are many parameters for HDR:
  81. .. image:: img/hdr_parameters.png
  82. ToneMapper
  83. ~~~~~~~~~~
  84. The ToneMapper is the heart of the algorithm. Many options for
  85. tonemappers are provided:
  86. - **Linear:** Simplest tonemapper. It does its job for adjusting scene
  87. brightness, but if the differences in light are too big, it will
  88. cause colors to be too saturated.
  89. - **Log:** Similar to linear but not as extreme.
  90. - **Reinhardt:** Classical tonemapper (modified so it will not desaturate
  91. as much)
  92. - **ReinhardtAutoWhite:** Same as above but uses the max scene luminance
  93. to adjust the white value.
  94. Exposure
  95. ~~~~~~~~
  96. The same exposure parameter as in real cameras. Controls how much light
  97. enters the camera. Higher values will result in a brighter scene, and
  98. lower values will result in a darker scene.
  99. White
  100. ~~~~~
  101. Maximum value of white.
  102. Glow threshold
  103. ~~~~~~~~~~~~~~
  104. Determine above which value (from 0 to 1 after the scene is tonemapped),
  105. light will start bleeding.
  106. Glow scale
  107. ~~~~~~~~~~
  108. Determine how much light will bleed.
  109. Min luminance
  110. ~~~~~~~~~~~~~
  111. Lower bound value of light for the scene at which the tonemapper stops
  112. working. This allows dark scenes to remain dark.
  113. Max luminance
  114. ~~~~~~~~~~~~~
  115. Upper bound value of light for the scene at which the tonemapper stops
  116. working. This allows bright scenes to remain saturated.
  117. Exposure adjustment speed
  118. ~~~~~~~~~~~~~~~~~~~~~~~~~
  119. Auto-exposure will change slowly and will take a while to adjust (like
  120. in real cameras). Bigger values means faster adjustment.