本页面包含有关设置 Unity 当前使用的活动渲染管线的信息。此信息可让您切换到内置渲染管线、通用渲染管线 (URP)、高清渲染管线 (HDRP) 或自定义渲染管线。
请注意,如果要切换到另一个渲染管线,必须确保项目中的资源和代码兼容新的渲染管线实例,否则,可能会遇到错误或意外的视觉效果。
一旦您在 Unity 编辑器中设置了活动渲染管线,Unity 就会开始使用它进行渲染。这包括 Game 视图、Scene 视图,以及 Project 面板和 Inspector 中显示的材质预览。
要将活动渲染管线设置为内置渲染管线,您必须告知 Unity 您未使用任何基于可编程渲染管线的渲染管线。当您从项目设置中删除所有这些引用后,Unity 默认使用内置渲染管线。
为此需要执行以下操作:
要将活动渲染管线设置为基于 SRP 的渲染管线,您必须告诉 Unity 要使用哪个渲染管线资源。渲染管线资源是一种资源,其中包含有关要使用的渲染管线以及如何配置该渲染管线的数据。
您可以拥有多个渲染管线资源,让 Unity 以不同配置使用同一渲染管线;例如,您可能有一个适合高端硬件的设置,一个适合低端硬件的设置。
有关渲染管线资源的一般介绍,请参阅可编程渲染管线简介。有关 URP 中渲染管线资源的信息,请参阅通用渲染管线资源。有关 HDRP 中渲染管线资源的信息,请参阅高清渲染管线资源。
您可以使用 C#代码设置渲染管线资源。您可以在 Unity 编辑器中以编辑模式或运行模式运行此代码,或者在构建的播放器中在运行时运行此代码。
由于 SRP 是高度可配置的,因此更改活动的渲染管线资源可能会导致更改差异很大(例如从 URP 切换到 HDRP)。在运行时更改渲染管线资源的性能成本相应地有所不同。
请注意,切换到新的渲染管线资源会使 Unity 销毁当前的渲染管线实例,并调用新渲染管线资源的 CreatePipeline()
方法。根据 SRP 中的代码,此操作可能在计算上是资源密集型操作。
以下示例代码显示了如何设置存储在 GraphicsSettings.renderPipelineAsset 中的默认渲染管线资源。
请注意,如果您已在项目的 Quality Settings 为渲染管线资源指定了质量级别,则当前质量级别的渲染管线资源将覆盖默认渲染管线资源。您可以如以下代码所示的方式在 C# 代码中使用 QualitySettings-renderPipeline API 进行更新。
using UnityEngine;
using UnityEngine.Rendering;
public class SwitchRenderPipelineAsset : MonoBehaviour
{
public RenderPipelineAsset exampleAssetA;
public RenderPipelineAsset exampleAssetB;
void Update()
{
if (Input.GetKeyDown(KeyCode.A)) {
GraphicsSettings.renderPipelineAsset = exampleAssetA;
Debug.Log("Default render pipeline asset is: " + GraphicsSettings.renderPipelineAsset.name);
}
else if (Input.GetKeyDown(KeyCode.B)) {
GraphicsSettings.renderPipelineAsset = exampleAssetB;
Debug.Log("Default render pipeline asset is: " + GraphicsSettings.renderPipelineAsset.name);
}
}
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.