轻量级渲染管线
Update: LWRP is now out of preview and production-ready. Get more info in our 2019.1 release post.
更新:LWRP现在已经过预览,无法投入生产。 在我们的2019.1版本发布中获取更多信息。
In a recent blog post we introduced the concept of Scriptable Render Pipelines. In short, SRP allow developers to control how Unity renders a frame in C#. We will release two built-in render pipelines with Unity 2018.1: the Lightweight Pipeline and HD Pipeline. In this article we’re going to focus on the Lightweight Pipeline or LWRP.
在最近的博客文章中,我们介绍了可脚本渲染管道的概念。 简而言之,SRP允许开发人员控制Unity如何在C#中渲染框架。 我们将使用Unity 2018.1发布两个内置渲染管道:轻量级管道和HD管道。 在本文中,我们将重点介绍轻量级管道或LWRP。
By exposing the rendering pipelines to C# our goal is to make Unity less of a black box and enable developers to explicitly control what is happening during rendering. Developers can use the built-in pipelines we’re providing, develop their own pipeline from scratch or start by modifying one of the provided pipelines to meet their specific requirements.
通过将渲染管线暴露给C#,我们的目标是使Unity不再是黑盒子,并使开发人员能够显式控制渲染过程中发生的事情。 开发人员可以使用我们提供的内置管道,从头开始开发自己的管道,也可以通过修改提供的管道之一来满足他们的特定要求。
We’ve released a video which provides a short overview of the Scriptable Render Pipeline concept including some footage of projects using the various pipelines:
我们发布了一个视频,其中简要介绍了可脚本渲染管道概念,其中包括一些使用各种管道的项目的素材:
The goal of the LWRP is to provide optimized real time performance on performance constrained platforms by making some tradeoffs with regard to lighting and shading.
LWRP的目标是通过在照明和阴影方面做出一些折衷,在性能受限的平台上提供优化的实时性能。
The target audience for LWRP is developers targeting a broad range of mobile platforms, VR and those that develop games with limited realtime lighting needs. The LWRP performs single-pass forward rendering with one real time shadow light and light culling per-object with the advantage that all lights are shaded in a single pass. Compared to the legacy pipeline forward rendering, which performs an additional pass per pixel light within range, using the LW pipeline will result in less draw calls. This is at the expense of some additional shader complexity due to more lights per pass. The LWRP is also supported by our Shader Graph tool, which will provide some additional benefits with regard to shader authoring workflow.
LWRP的目标受众是面向各种移动平台,VR以及那些开发实时照明需求有限的游戏的开发商。 LWRP使用一个实时阴影光和每个对象进行光剔除来执行单遍正向渲染,其优点是所有光都在单遍中被着色。 与传统流水线正向渲染相比,传统流水线正向渲染对范围内的每个像素光执行额外的传递,使用LW流水线将减少绘制调用。 由于每次通过更多的光,这以一些额外的着色器复杂性为代价。 我们的Shader Graph工具也支持LWRP,这将在着色器创作工作流程方面提供一些其他好处。
轻量级着色器 (Lightweight Shaders)
The LWRP has its own process for rendering and therefore requires shaders which are written with it in mind. We have developed a new set of Standard Shaders that are located under the Lightweight Pipeline group in the material’s shader selection dropdown. These include a Standard PBR shader, a Non PBR Standard shader with a simplified lighting model, a Standard Terrain shader and a Standard Unlit shader. It’s worth noting that all Unity’s unlit stock shaders work already with LWRP. This includes legacy particles, UI, skybox, and sprite shader.
LWRP具有自己的渲染过程,因此需要考虑到着色器。 我们已经开发了一套新的标准着色器,它们位于材质的着色器选择下拉列表的“轻量级管道”组下。 其中包括标准PBR着色器,具有简化照明模型的非PBR标准着色器,标准地形着色器和标准非照明着色器。 值得注意的是,Unity的所有未照明的股票着色器都已与LWRP一起使用。 这包括旧粒子,UI,天空盒和精灵着色器。
The Lightweight Pipeline also provides material upgraders to upgrade Unity’s stock lit shaders to shaders compatible with the pipeline. In order to upgrade materials go to Edit -> Render Pipeline -> Upgrade -> Lightweight. You can choose to either upgrade all material in a project, or selected materials.
轻量级管道还提供了材质升级程序,以将Unity的库存照明着色器升级到与管道兼容的着色器。 为了升级材料,请转到编辑->渲染管道->升级->轻量化 。 您可以选择升级项目中的所有材料或选定的材料。
渲染管道资产 (The Render Pipeline Asset)
The currently selected render pipeline is selected by assigning a pipeline asset in the Scriptable Render Pipeline Settings of the Graphics Settings window. It can also be assigned from script via the GraphicsSettings.renderPipelineAsset property.
通过在“图形设置”窗口的“可脚本绘制的渲染管线设置”中分配管线资产,可以选择当前选定的渲染管线。 也可以通过GraphicsSettings.renderPipelineAsset属性从脚本中分配它。
In addition to selecting a pipeline to define the overall rendering approach of your project at the outset, it’s possible to store multiple quality settings within different instances of the same type of render pipeline. The pipeline asset controls the global rendering quality settings and is responsible for creating the pipeline instance. The pipeline instance contains intermediate resources and the render loop implementation.
除了从一开始就选择管道定义项目的整体渲染方法外,还可以在同一类型的渲染管道的不同实例中存储多个质量设置。 管道资产控制全局渲染质量设置,并负责创建管道实例。 管道实例包含中间资源和渲染循环实现。
轻量级渲染 (Lightweight Rendering)
The rendering features of LWRP are mainly a subset of the built-in renderer. In order to improve performance on performance limited platforms, certain functionality has been deliberately excluded. Unity provides developers with a wide array of tools and techniques to apply to their games. The risk in this is that sometimes the wrong technique is applied to a game which doesn’t have the performance resources to support it. The goal of providing specialized rendering pipelines as templates is to mitigate the possibility for users to make certain potentially costly mistakes in terms of performance. Deploying inappropriate post processing effects for a target platform for example may make the game slow on a device, even though those effects are supported in Unity and might perform appropriately on the appropriate target platform.
LWRP的渲染功能主要是内置渲染器的子集。 为了提高性能受限平台上的性能,已故意排除某些功能。 Unity为开发人员提供了适用于其游戏的多种工具和技术。 这样做的风险是,有时将错误的技术应用于没有性能资源来支持该游戏的游戏。 提供专门的渲染管道作为模板的目的是减轻用户在性能方面犯某些潜在的代价高昂的错误的可能性。 例如,为目标平台部署不合适的后处理效果可能会使游戏在设备上变慢,即使Unity支持这些效果并可能在适当的目标平台上正常执行。
Realtime global illumination is another example of a feature which is rarely used on the LW RP target platforms and has therefore been removed. The single supported rendering path is single-pass forward, which is another decision which privileges performance over rendering complexity. The table below provides further detail about which techniques are supported in the Built-In Pipeline, and which are supported in Lightweight.
实时全局照明是该功能的另一个示例,该功能很少在LW RP目标平台上使用,因此已被删除。 支持的单一渲染路径是单向前进,这是另一个决定性能而不是渲染复杂性的决定。 下表提供了有关内置管道支持哪些技术以及轻量级支持哪些技术的更多详细信息。
Unity Built-In Pipeline | Lightweight Pipeline | |
Platform Coverage | All | All |
Rendering Paths | Multi-pass Forward Multi-pass Deferred | Single-pass Forward |
Lighting Attenuation | Separate precomputed attenuation textures for Point and Spot Vertex light attenuation does not reach 0 intensity at range boundary. | Attenuation computed in the shader smoothly fading to light range. Inner and outer angle for spot lights. |
Color Space | Linear with sRGB light intensity sRGB | Linear preferred, Gamma supported Linear light intensities |
Realtime Lights | Directional, Spot and Point Amount of pixel lights controlled by Quality Settings Forward path limited to 8 pixel lights. Supports up to 4 vertex point lights. | Directional, Spot and Point Amount of pixel lights controlled by Pipeline Asset Limited to 8 pixel lights. Supports up to 4 vertex point lights. |
Light Modes | Baked Mixed Baked Indirect Shadow Mask Distance Shadowmask Subtractive Realtime | Baked Mixed Baked Indirect Realtime |
Global Illumination | Directional, Spot, Point and Rectangular Area Lights Baked Lightmap (Non-Directional and Directional) Light Probes Realtime Dynamic Lightmap Realtime Lightprobes | Directional, Spot, Point and Rectangular Area Lights Baked Lightmap (Non-Directional and Directional) Light Probes Realtime GI Not Supported. |
Light Culling | Per-Object. No Compute. | Per-Object. No Compute. |
Shader Library | Dozens of non physically based shaders specializations Unified Standard PBS Shaders: Metallic workflow Specular workflow Roughness workflow | Unified Standard non physically based Shader (covers most legacy and mobile lit shaders) Unified Standard Shader (Metallic or Specular workflow) |
Physically Based Shading | Disney Diffuse + Cook Torrance (GGX, Smith, Schlick) Specular Lambertian Diffuse + Simplified Cook Torrance (GGX, Simplified KSK and Schlick) Specular Lambertian Diffuse + Non-Microfaceted LUT Specular | Lambertian Diffuse + Simplified Cook Torrance (GGX, Simplified KSK and Schlick) Specular |
Light Cookies | Monochrome | Not supported in V1 |
Light Probes Modes | One interpolated probe LPPV | One interpolated probe |
Reflection Probes | Sorted per-object, blend between at most 2 probes | Sorted per-object, no blending |
Shadows Features | PSSM Stable and Close Fit Filtering: PCF No depth clip. Pancaking done in vertex. | PSSM Stable Fit Filtering: PCF No depth clip. Pancaking done in vertex. |
Shadow Modes | Light Space Screen Space | Screen Space |
Shadow Casting Lights | Directional, Spot, Point Multiple shadow light casters, one per-pass. | Directional and Spot Single shadow light caster supported as main light. |
General | ||
Camera | Sorts camera by depth value Stack Management Groups by common camera state Handles depth state between cameras | Sorts camera by depth value No stack management RenderTarget scale supported Game renders at scaled resolution UI renders at native resolution |
Anti-Aliasing | MSAA, TAA | MSAA |
Pipeline Additional Data | Motion Vectors | None |
Post-Processing | Legacy Post-Processing stack new Post-Processing Stack | Subset of the new Post-Processing Stack FX No support for: TAA, Motion Blur, SSR |
Debug option | Display GBuffer Display various bake lighting view mode | |
Sky lighting | Procedural Sky Cubemap/LatLong Sky Ambient Lighting | Procedural Sky Cubemap Ambient Lighting |
Unity内置管道 | 轻量级管道 | |
平台覆盖 | 所有 | 所有 |
渲染路径 | 多遍转发 多次递延 | 单遍转发 |
照明衰减 | 针对点和点的单独的预先计算的衰减纹理 顶点光衰减在范围边界处未达到0强度。 | 在着色器中计算出的衰减会平滑地衰减到光照范围。 聚光灯的内角和外角。 |
色彩空间 | 线性与sRGB光强度 RGB | 首选线性,支持伽玛 线性光强度 |
实时灯 | 定向,点和点 由“质量设置”控制的像素光量 前向路径限制为8个像素灯。 支持多达4个顶点照明。 | 定向,点和点 受管线资产控制的像素光量 仅限8像素灯。 支持多达4个顶点照明。 |
灯光模式 | 烤 混合的 间接烤制 阴影面具 距离荫罩 减法 即时的 | 烤 混合的 间接烤制 即时的 |
全球照明 | 定向,聚光,点和矩形区域灯 烤 光照贴图(非定向和定向) 光探头 即时的 动态光照贴图 实时光探头 | 定向,聚光,点和矩形区域灯 烤 光照贴图(非定向和定向) 光探头 不支持实时GI。 |
轻选 | 每个对象。 没有计算。 | 每个对象。 没有计算。 |
着色器库 | 数十种非基于物理的着色器专业知识 统一标准PBS着色器: 金属工作流程 镜面工作流程 粗糙度工作流程 | 非基于物理的统一标准着色器(涵盖大多数旧式和移动式照明着色器) 统一标准明暗器(金属或镜面工作流程) |
基于物理的阴影 | 迪士尼Diffuse + Cook Torrance(GGX,Smith,Schlick)镜面 Lambertian漫反射+简化的Cook Torrance(GGX,简化的KSK和Schlick)高光 朗伯扩散+非微面LUT镜面反射 | Lambertian漫反射+简化的Cook Torrance(GGX,简化的KSK和Schlick)高光 |
轻饼干 | 单色 | V1不支持 |
光探头模式 | 一个内插探针 低压PV | 一个内插探针 |
反射探头 | 按对象排序,最多2个探针之间混合 | 按对象排序,不融合 |
阴影功能 | PSSM稳定贴身 过滤:PCF 没有深度剪辑。 Pancaking在顶点完成。 | PSSM稳定贴合 过滤:PCF 没有深度剪辑。 Pancaking在顶点完成。 |
阴影模式 | 光空间 屏幕空间 | 屏幕空间 |
影子投光灯 | 定向,点,点 多个阴影光脚轮,每个通道一次。 | 定向和现货 支持单阴影光脚轮作为主光源。 |
一般 | ||
相机 | 按深度值对摄像机排序 堆栈管理 按常见相机状态分组 处理相机之间的深度状态 | 按深度值对摄像机排序 没有堆栈管理 支持RenderTarget比例 游戏以缩放的分辨率渲染 UI以本机分辨率呈现 |
抗锯齿 | MSAA,TAA | MSAA |
管道附加数据 | 运动向量 | 没有 |
后期处理 | 旧版后处理堆栈 新的后处理堆栈 | 新的后处理堆栈FX的子集 不支持:TAA,运动模糊,SSR |
调试选项 | 显示缓冲区 显示各种烘烤照明查看模式 | |
天空照明 | 程序天空 Cubemap / LatLong天空 环境照明 | 程序天空 立方体贴图 环境照明 |
自定义轻量级管道 (Customizing The Lightweight Pipeline)
The incredible potential of the Scriptable Render Pipeline architecture is that it’s more open and customizable than rendering in Unity ever has been. If you want to have access to Lightweight Pipeline source, take a look at the Scriptable Render Pipeline github page. There you can grab the C# source for the LW RP and begin making modifications to create a pipeline which is uniquely suited to your project. If you run into any issues, we’d love to hear about them via our github page. We’re also looking forward to hearing from you on the beta forum.
可脚本化渲染管道架构的惊人潜力是,它比Unity中的渲染更加开放和可定制。 如果您想访问轻量级管道源,请查看Scriptable Render Pipeline github页面 。 在那里,您可以获取LW RP的C#源代码,并开始进行修改以创建特别适合您的项目的管道。 如果您遇到任何问题,我们很乐意通过github页面来了解有关它们的信息。 我们也期待在Beta论坛上收到您的来信 。
轻量级渲染管线