Version: 5.6
API
HDR 拾色器

高动态范围渲染

在标准渲染中,像素的红色、绿色和蓝色值均由 0 到 1 范围内的分数表示,其中 0 表示零强度,1 表示显示设备的最大强度。虽然这很容易使用,但它并不能准确反映在现实生活场景中光照的运作方式。人眼倾向于适应局部光照条件,因此在光线昏暗的房间中看起来是白色的物体实际上可能还不如在强烈日光下看起来是灰色的物体明亮。此外,眼睛对昏暗范围的亮度差异比对明朗范围的亮度差异更敏感。

如果能调整渲染使像素值的范围来更准确地反映其在真实场景中的光照情况,则可以实现更真实的视觉效果。虽然这些值最终需要映射回显示设备上的可用范围,但任何中间计算(例如 Unity 的图像效果)都将提供更真实的结果。高动态范围 (HDR) 渲染的精髓是允许图形的内部表示使用 0 到 1 范围之外的值。

使用 HDR

应使用摄像机组件上的设置为每个摄像机单独启用 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.

在 HDR 中渲染的异常明亮的场景。如果不执行色调映射,大部分像素会看起来超出范围。
在 HDR 中渲染的异常明亮的场景。如果不执行色调映射,大部分像素会看起来超出范围。
The same scene as above. But this time, the tonemapping effect is bringing most intensities into a more plausible range. Note that adaptive tonemapping can even blend between above and this image thus simulating the adaptive nature of capturing media (e.g. eyes, cameras).
The same scene as above. But this time, the tonemapping effect is bringing most intensities into a more plausible range. Note that adaptive tonemapping can even blend between above and this image thus simulating the adaptive nature of capturing media (e.g. eyes, cameras).

HDR Bloom and Glow

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.

The car window sun reflections in this scene have intensity values far bigger than 1.0. Bloom can only pick up and glow these parts if the camera is HDR enabled thus capturing these intensities.
The car window sun reflections in this scene have intensity values far bigger than 1.0. Bloom can only pick up and glow these parts if the camera is HDR enabled thus capturing these intensities.
The car window will remain without glow if the camera is not HDR enabled. Only way to add glow is to lower the intensity threshold but then unwanted parts of the image will start glowing as well.
The car window will remain without glow if the camera is not HDR enabled. Only way to add glow is to lower the intensity threshold but then unwanted parts of the image will start glowing as well.

HDR 的优点

  • 在高强度区域不会丢失颜色
  • 更好地支持泛光和发光效果
  • 减少低频光照区域的条带

HDR 的缺点

  • 使用浮点渲染纹理(渲染速度较慢,需要更多 VRAM)
  • No hardware anti-aliasing support (but you can use Anti-Aliasing image effect to smooth out the edges)
  • 并非所有硬件都支持

使用注意事项

前向渲染

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.

另请参阅

HDR 拾色器

API
HDR 拾色器