在标准渲染中,像素的红色、绿色和蓝色值均由 0 到 1 范围内的分数表示,其中 0 表示零强度,1 表示显示设备的最大强度。虽然这很容易使用,但它并不能准确反映在现实生活场景中光照的运作方式。人眼倾向于适应局部光照条件,因此在光线昏暗的房间中看起来是白色的物体实际上可能还不如在强烈日光下看起来是灰色的物体明亮。此外,眼睛对昏暗范围的亮度差异比对明朗范围的亮度差异更敏感。
如果能调整渲染使像素值的范围来更准确地反映其在真实场景中的光照情况,则可以实现更真实的视觉效果。虽然这些值最终需要映射回显示设备上的可用范围,但任何中间计算(例如 Unity 的图像效果)都将提供更真实的结果。高动态范围 (HDR) 渲染的精髓是允许图形的内部表示使用 0 到 1 范围之外的值。
应使用摄像机组件上的设置为每个摄像机单独启用 HDR:
When HDR is active, the scene is rendered into an HDR image buffer which can accommodate pixel values outside the 0..1 range. This buffer is then postprocessed using image effects such as HDR bloom. The tonemapping image effect is what converts the HDR image into the standard low dynamic range (LDR) image to be sent for display. The conversion to LDR must be applied at some point in the image effect pipeline but it need not be the final step if LDR-only image effects are to be applied afterwards. For convenience, some image effects can automatically convert to LDR after applying an HDR effect (see Scripting below).
Tonemapping is the process of mapping HDR values back into the LDR range. There are many different techniques, and what is good for one project may not be the best for another. A variety of tonemapping image effects have been included in Unity. To use them select Assets > Import Package > Effects select the camera in the scene then select Component > Image Effects >ToneMapping a detailed description of the tonemapping types can be found in the image effects documentation.
Using HDR allows for much more control in post processing. LDR bloom has an unfortunate side effect of blurring many areas of a scene even if their pixel intensity is less than 1.0. By using HDR it is possible to only bloom areas where the intensity is greater than one. This leads to a much more desiarable outcome with only super bright elements of a scene bleeding into neighboring pixels. The built in ‘Bloom and Lens Flares’ image effect now also supports HDR. To attach it to a camera select Assets > Import Package > Effects select the camera in the scene then select Component > Image Effects > Bloom a detailed description of the ‘Bloom’ effect can be found in the image effects documentation.
In forward rendering mode HDR is only supported if you have an image effect present. This is due to performance considerations. If you have no image effect present then no tone mapping will exist and intensity truncation will occur. In this situation the scene will be rendered directly to the backbuffer where HDR is not supported.
In HDR mode the lighting buffer is also allocated as a floating point buffer. This reduces banding in the lighting buffer. HDR is supported in deferred rendering even if no image effects are present.
The ImageEffectTransformsToLDR attribute can be added to an image effect script to indicate that the target buffer should be in LDR instead of HDR. Essentially, this means that a script can automatically convert to LDR after applying its HDR image effect. See Writing Image Effects for more details.