使用高清渲染管线创建沉浸式,逼真的VR体验

We’re officially bringing virtual reality to the High Definition Render Pipeline (HDRP). In 2019.3.6f1 and after with package version 7.3.1, HDRP is now verified and can be used in VR.

我们正式将虚拟现实技术引入 高清渲染管线 (HDRP)。 在2019.3.6f1及更高版本的软件包7.3.1中,HDRP已通过验证并可以在VR中使用。

This blog post takes a technical dive into using HDRP in your VR project. To learn more about all the possibilities that HDRP offers, take a look at this blog post.

这篇博客文章深入探讨了在VR项目中使用HDRP的技术。 要了解有关HDRP提供的所有可能性的更多信息,请参阅此 博客文章

VR in HDRP is designed so that:

HDRP中的VR设计为:

  1. All HDRP features are compatible with VR.

    所有HDRP功能均与VR兼容。

  2. HDRP is fully supported with the new Unity XR Plugin Framework.

    新的 Unity XR插件框架 完全支持HDRP 。

  3. Single-pass (instancing) is the default and recommended rendering solution for VR.

    单次通过(实例化)是VR的默认和推荐的渲染解决方案。

功能亮点 (Feature highlights)

Using HDRP for a VR project, you can take advantage of all the render pipeline’s features to create experiences bound only by your imagination. With its state-of-the-art rendering techniques, HDRP can deliver stunning, photorealistic visuals at a quality rarely seen before in virtual reality environments.

将HDRP用于VR项目,您可以利用所有渲染管道的功能来创建仅受您的想象力约束的体验。 凭借其最新的渲染技术,HDRP可以以虚拟现实环境中前所未有的质量提供令人惊叹的逼真的视觉效果。

Here’s a very quick overview of the features available for your VR projects:

这是您的VR项目可用功能的快速概述:

  • Deferred and Forward rendering

    递延渲染

  • All light types, shadows, decals, and volumetrics

    所有光源类型,阴影,贴花和体积

  • Screen space effects

    屏幕空间效果

    • Ambient Occlusion (AO)

      环境光遮挡(AO)

    • Screen Space Reflection (SSR)

      屏幕空间反射(SSR)

    • Subsurface Scattering (SSS)

      地下散射(SSS)

    • Distortion and Refraction

      变形和折射

    Screen space effects

    屏幕空间效果

  • Post-processing

    后期处理

    • Color Grading, Anti-aliasing, Depth of Field, etc.

      颜色分级,抗锯齿,景深等

    Post-processing

    后期处理

  • All VFXs from Visual Effect Graph

    视觉效果图中的所有VFX

支持平台 (Supported platforms)

VR for HDRP is currently available for the following platforms and devices: 

HDRP的VR当前可用于以下平台和设备:

  • Oculus Rift & Rift S (Oculus XR Plugin, Windows 10, DirectX 11)

    Oculus Rift和Rift S(Oculus XR插件,Windows 10,DirectX 11)

  • Windows Mixed Reality (Windows XR Plugin, Windows 10, DirectX 11)

    Windows Mixed Reality(Windows XR插件,Windows 10,DirectX 11)

  • PlayStationVR 

    PlayStationVR

OpenVR: Valve is currently developing their OpenVR Unity XR Plugin for 2019.3 and beyond, and this will be available soon.

OpenVR:Valve目前正在为2019.3及更高版本开发其OpenVR Unity XR插件,并将很快推出。

Stereo rendering techniques

立体渲染技术

A native VR implementation will process everything twice – once for each eye. We call this solution multipass rendering. HDRP supports multipass rendering, however, we do not recommend this method because your application will use twice as much CPU power for rendering, essentially doubling your number of draw calls. On top of that, shadows will be rendered twice and could consume a significant portion of your GPU budget.

原生VR实施将处理所有内容两次-每只眼睛一次。 我们将此解决方案称为 多遍渲染 。 HDRP支持多通道渲染,但是,我们不建议您使用此方法,因为您的应用程序将使用两倍的CPU能力进行渲染,从而使绘图调用次数实质上增加了一倍。 最重要的是,阴影将被渲染两次,并可能消耗GPU预算的很大一部分。

That said, there are some cases where using multipass is appropriate:

也就是说,在某些情况下,使用多次通过是合适的:

  • If your system has a small amount of GPU memory, multipass uses less memory for render targets than single pass.

    如果您的系统具有少量GPU内存,那么多遍使用的渲染目标内存将少于单遍。

  • If for some reason you need to render vastly different viewpoints for each eye.

    如果出于某种原因,您需要为每只眼睛渲染截然不同的视点。

A faster solution is to use single pass (instanced) rendering. In this mode, every draw call is simultaneously rendered for both eyes. This is accomplished by using a texture array for the render targets and instanced draw calls. Furthermore, culling and shadows are processed only once per frame.

更快的解决方案是使用单遍(实例化)渲染。 在此模式下,每个绘图调用都同时为两只眼睛渲染。 这可以通过将纹理数组用于渲染目标和实例绘制调用来完成。 此外,每帧仅处理一次剔除和阴影。

HDRP has been designed so that all features are compatible with VR and optimized for single pass rendering.

HDRP的设计使所有功能都与VR兼容,并针对单遍渲染进行了优化。

The key design decision was to use texture array for all render targets (even when you’re not creating for VR). This decision, coupled with shader macros, has allowed us to author shaders that are automatically compatible with VR,  apart from a few special cases (e.g., light list generation, indirect tile deferred shading, volumetric lighting, and camera-relative rendering).

关键的设计决策是对所有渲染目标都使用纹理数组(即使您不是为VR创建的)。 除了一些特殊情况(例如,光源列表生成,间接平铺延迟着色,体积照明和相对于相机的渲染)外,这一决定以及着色器宏使我们能够创作与VR自动兼容的着色器。

Note that single pass rendering for double-wide textures is not supported by HDRP because of the additional complexity and overhead required for all full-screen passes and effects.

请注意,HDRP不支持双倍宽纹理的单遍渲染,因为所有全屏遍历和效果都需要额外的复杂性和开销。

从HDRP VR开始 (Start with HDRP VR)

To get started with HDRP VR, check out the VR Overview section in Unity’s documentation. To help you to set up HDRP with VR, we also provide an HDRP Wizard, which validates your settings and can help you to fix any settings the Wizard identifies as being incorrect.

要开始使用HDRP VR,请查看 Unity文档中 的“ VR概述” 部分。 为了帮助您通过VR设置HDRP,我们还提供了 HDRP向导 ,该 向导 可以验证您的设置,并可以帮助您修复向导标识为不正确的任何设置。

使用高清渲染管线创建沉浸式,逼真的VR体验

The HDRP VR Wizard

HDRP VR向导

To configure your project for VR manually using the new XR plugin framework, please refer to the documentation. To set up single pass rendering, you must have both Project Settings set to Single-Pass Stereo Rendering mode and the HDRP asset settings set to Single Pass. HDRP will default to multipass if either one of those two options isn’t enabled for single pass.

要使用新的XR插件框架手动为VR配置项目,请参阅 文档 。 要设置单次渲染,你必须有 两个 项目设置设置为单通道立体渲染模式 ,并 设置为单程HDRP资产设置。 如果未为单程通过启用这两个选项之一,则HDRP将默认为多通。

使用高清渲染管线创建沉浸式,逼真的VR体验

Enable Single Pass rendering with the Oculus plugin in Project Settings and in HDRP asset settings.

在项目设置和HDRP资产设置中使用Oculus插件启用Single Pass渲染。

Anti-aliasing

抗锯齿

Reducing aliasing is extremely important in VR in order to create a great user experience and avoid breaking the virtual environment’s immersiveness. HDRP provides several solutions to help with anti-aliasing.

减少混叠在VR中非常重要,这样才能创建出色的用户体验并避免破坏虚拟环境的沉浸感。 HDRP提供了多种解决方案来帮助抗锯齿。

The camera anti-aliasing modes are described in-detail in Unity’s documentation. These options include: 

相机的抗锯齿模式在Unity 文档中 详细介绍 。 这些选项包括:

  • Multisampling Anti-Aliasing (MSAA) is supported with forward rendering. You can balance quality versus performance by choosing the number of samples (2x, 4x, 8x). This technique can achieve great results, but it can also be expensive.

    前向渲染支持多重采样抗锯齿(MSAA)。 您可以通过选择样本数量(2x,4x,8x)来平衡质量与性能。 这项技术可以取得很好的效果,但是也很昂贵。

  • Temporal Anti-Aliasing is likely the best solution for most applications. It’s very effective at reducing aliasing, but it can blur out some details. You can counterbalance this blur with the included sharpen filter control.

    对于大多数应用,时间抗锯齿可能是最好的解决方案。 它在减少混叠方面非常有效,但可以模糊一些细节。 您可以使用随附的锐化滤镜控件来抵消这种模糊。

  • Somewhat cheaper solutions include Fast Approximate Anti-Aliasing (FXAA) or Subpixel Morphological Anti-Aliasing (SMAA).

    较便宜的解决方案包括快速近似抗锯齿(FXAA)或亚像素形态抗锯齿(SMAA)。

  • It’s also possible to combine MSAA with TAA, FXAA, or SMAA. This technique improves visual quality, but the cost is cumulative.

    也可以将MSAA与TAA,FXAA或SMAA结合使用。 这种技术可以提高视觉质量,但是成本是累积的。

  • There is also additional shading anti-aliasing available per material with Geometric Specular Anti-Aliasing, which you can tweak directly on materials. Its use is recommended for smooth and dense surfaces. 

    几何镜面 抗锯齿还为每种材质提供了附加的阴影 抗锯齿功能 ,您可以直接在材质上进行调整。 建议将其用于光滑密实的表面。

Performance

性能

VR rendering is extremely demanding due to the higher refresh rate and resolution required to display to both eyes. Make sure to disable any features you don’t need in the HDRP asset settings. Features like Volumetric aren’t suited for VR applications since their performance doesn’t meet the required 90 fps despite being supported. Frequently monitoring and profiling performance will help you to identify any bottlenecks in your project.

由于呈现给双眼的刷新率和分辨率更高,因此VR渲染的要求非常严格。 确保禁用 HDRP资产设置中 不需要的所有功能 。 诸如Volumetric之类的功能不适用于VR应用程序,因为尽管受支持,但其性能仍无法满足要求的90 fps。 经常监视和分析性能将帮助您确定项目中的任何瓶颈。

Note that by default, the precision of volumetric effects (z slices) in VR will be halved to keep GPU performance more acceptable. In addition to volumetric lighting, it’s highly recommended to disable HDRP Area Light support when doing a VR project. Unlike other features, Area Light must be disabled via the shader configuration files.

请注意,默认情况下,VR中的体积效果(z切片)的精度将减半,以使GPU性能更可接受。 除了 体积照明外 ,强烈建议 在执行VR项目时 禁用HDRP Area Light支持 。 与其他功能不同,必须通过 着色器配置文件 禁用Area Light 。

There are two rendering methods available in HDRP, which also impact performance: Lit Shader Mode Forward and Deferred. To learn about the differences between those two modes, please see the documentation. Choosing the right mode for VR depends on the project’s requirements. Forward rendering lets you enable MSAA and reduce memory usage, while Deferred rendering is more efficient for projects with a large number of lights, but it also consumes more memory.

HDRP中有两种渲染方法,它们也会影响性能:“ Lit Shader Mode Forward”和“ Deferred”。 要了解这两种模式之间的区别,请参阅 文档 。 为VR选择正确的模式取决于项目的要求。 使用正向渲染,您可以启用MSAA并减少内存使用,而对于具有大量灯光的项目,延迟渲染更有效,但它也会占用更多内存。

Another factor that influences GPU performance is the resolution of the rendering buffer. This resolution is initially set by the XR display plugin and depends on the headset you’re using. You can then adjust the resolution in your application or use the dynamic resolution feature to drive resolution depending on the current scene’s context. For example, resolution could be adapted based on the current GPU frame time.

影响GPU性能的另一个因素是渲染缓冲区的分辨率。 此分辨率最初由XR显示插件设置,并取决于您使用的耳机。 然后,您可以在应用程序中调整分辨率,或使用 动态分辨率 功能根据当前场景的上下文来驱动分辨率。 例如,可以基于当前的GPU帧时间调整分辨率。

For more tips, check out this HDRP VR talk from Unite 2019 Copenhagen.

有关更多技巧,请查看 Unite 2019 Copenhagen的HDRP VR演讲 。

深入了解HDRP VR (Technical dive into HDRP VR)

To support VR in HDRP, we’ve added a set of shader macros to help handle the view instancing and texture array usage for the render target. For example, you can declare a texture in a shader with the following code:

为了在HDRP中支持VR,我们添加了一组着色器宏来帮助处理渲染目标的视图实例化和纹理阵列使用。 例如,您可以使用以下代码在着色器中声明纹理:

TEXTURE2D_X(MyTexture);

TEXTURE2D_X(MyTexture);

On platforms that support texture array, this macro will expand to TEXTURE2D_ARRAY. If the platform does not support texture array or if the setting in ShaderConfig.cs is disabled, the macro will expand to regular TEXTURE2D. Similar features are available for texture sampling.

在支持纹理数组的平台上,此宏将扩展为TEXTURE2D_ARRAY。 如果平台不支持纹理数组,或者如果ShaderConfig.cs中的设置被禁用,则宏将扩展为常规TEXTURE2D。 类似的功能可用于纹理采样。

On the shader side, the proper view constants (view matrix, projection matrix, etc.) are stored in the array and indexed based on the eye index, which is derived from the instanceID of the primitives. In the case of compute shaders, the z dispatch dimension is used to identify each eye. The macro UNITY_XR_ASSIGN_VIEW_INDEX is usually used to assign the proper eye index.

在着色器端,适当的视图常量(视图矩阵,投影矩阵等)存储在数组中,并基于从原始图元的instanceID导出的眼睛索引进行索引。 在计算着色器的情况下,z调度维度用于标识每只眼睛。 宏UNITY_XR_ASSIGN_VIEW_INDEX通常用于分配适当的眼睛索引。

HDRP VR的未来 (The future of HDRP VR)

Future versions of HDRP VR will focus on:

HDRP VR的未来版本将重点关注:

  • Improving performance with new hardware options like Variable Rate Shading 

    通过可变速率着色等新硬件选项提高性能

  • Improving platform support with Vulkan and DX12

    使用Vulkan和DX12改善平台支持

  • Improving devices support

    改善设备支持

  • Extending single pass to support more than two views

    扩展单次通过以支持两个以上的视图

让我们知道您的想法 (Let us know what you think)

You can start taking advantage of HDRP VR today. We’d love to hear your feedback in the HDRP forum as we continue to make improvements.

您可以立即开始使用HDRP VR。 我们很乐意在 继续改进的同时 ,在 HDRP论坛 上听到您的反馈 。

翻译自: https://blogs.unity3d.com/2020/03/12/creating-immersive-photorealistic-vr-experiences-with-the-high-definition-render-pipeline/