包含此页的版本:
不含此页的版本:
此页面包含有关如何获取、设置和配置渲染管线 获取场景内容并将其显示在屏幕上的一系列作。Unity 允许您从预构建的渲染管道中进行选择,或编写自己的渲染管道。更多信息
请参阅术语表Unity 当前正在使用的。Unity 当前使用的渲染管线称为活动渲染管线。
要渲染内容,Unity 可以使用内置渲染管线或基于可编写脚本渲染管线 (SRP) 的渲染管线,其中包括通用渲染管线 (URP) 和高清渲染管线 (HDRP)。
要指定Unity使用的可编写脚本的渲染管线,请使用渲染管线资产。渲染管线资产告诉 Unity 使用哪个 SRP 以及如何配置它。如果未指定渲染管线资产,Unity 将使用内置渲染管线。
你可以创建多个渲染管线资产,这些资产使用相同的渲染管线,但配置不同;例如,你可以为不同的硬件质量级别使用不同的渲染管线资产。有关渲染管线资产的一般介绍,请参阅可编写脚本的渲染管线简介。有关 URP 的渲染管线资产的信息,请参阅通用渲染管线资产,有关 HDRP 的渲染管线资产,请参阅高清渲染管线资产。
一旦您在 Unity 编辑器中或运行时更改活动渲染管线资产,Unity 就会使用新的活动渲染管线来渲染内容。如果您在 Unity 编辑器中,这包括 Game 视图、场景场景包含游戏的环境和菜单。将每个唯一的场景文件视为一个独特的关卡。在每个场景中,你放置你的环境、障碍物和装饰品,基本上是将你的游戏设计和构建成碎片。更多信息
请参阅术语表在“项目”面板和检查器一个 Unity 窗口,显示有关当前选定游戏对象、资产或项目设置的信息,允许您检查和编辑值。更多信息
请参阅术语表.
更改活动渲染管线时,必须确保项目中的资产和代码与新的渲染管线兼容;否则,您可能会遇到错误或意外的视觉效果。
对于 Quality settings 窗口中的每个质量级别,Unity 使用分配给 Render Pipeline Asset 的 Render Pipeline Asset。如果未分配该属性,Unity 会改用分配给 Graphics settings 窗口中 Default Render Pipeline Asset 的 Render Pipeline Asset。
如果未同时设置 Render Pipeline Asset 和 Default Render Pipeline,则 Unity 会使用内置渲染管线。
要将活动渲染管线设置为 内置渲染管线(Built-in Render Pipeline),请从图形设置和质量设置中删除所有渲染管线资产。
为此,请执行以下作:
要将活动渲染管线设置为基于 SRP 的渲染管线,请告诉 Unity 要将哪个渲染管线资产用作默认活动渲染管线,以及可选地为每个质量级别使用哪个渲染管线资产。
为此,请执行以下作:
在 C# 中脚本一段代码,允许您创建自己的组件、触发游戏事件、随时间修改组件属性以及以您喜欢的任何方式响应用户输入。更多信息
请参阅术语表,您可以获取和设置活动渲染管线,并在活动渲染管线发生变化时接收回调。您可以在 Unity 编辑器的编辑模式或播放模式下执行此作,也可以在应用程序的运行时执行此作。
为此,请使用以下 API:
以下示例代码演示如何使用这些 API:
using UnityEngine;
using UnityEngine.Rendering;
public class ActiveRenderPipelineExample : MonoBehaviour
{
// In the Inspector, assign a Render Pipeline Asset to each of these fields
public RenderPipelineAsset defaultRenderPipelineAsset;
public RenderPipelineAsset overrideRenderPipelineAsset;
void Start()
{
GraphicsSettings.defaultRenderPipeline = defaultRenderPipelineAsset;
QualitySettings.renderPipeline = overrideRenderPipelineAsset;
DisplayCurrentRenderPipeline();
}
void Update()
{
// When the user presses the left shift key, switch the default render pipeline
if (Input.GetKeyDown(KeyCode.LeftShift)) {
SwitchDefaultRenderPipeline();
DisplayCurrentRenderPipeline();
}
// When the user presses the right shift key, switch the override render pipeline
else if (Input.GetKeyDown(KeyCode.RightShift)) {
SwitchOverrideRenderPipeline();
DisplayCurrentRenderPipeline();
}
}
// Switch the default render pipeline between null,
// and the render pipeline defined in defaultRenderPipelineAsset
void SwitchDefaultRenderPipeline()
{
if (GraphicsSettings.defaultRenderPipeline == defaultRenderPipelineAsset)
{
GraphicsSettings.defaultRenderPipeline = null;
}
else
{
GraphicsSettings.defaultRenderPipeline = defaultRenderPipelineAsset;
}
}
// Switch the override render pipeline between null,
// and the render pipeline defined in overrideRenderPipelineAsset
void SwitchOverrideRenderPipeline()
{
if (QualitySettings.renderPipeline == overrideRenderPipelineAsset)
{
QualitySettings.renderPipeline = null;
}
else
{
QualitySettings.renderPipeline = overrideRenderPipelineAsset;
}
}
// Print the current render pipeline information to the console
void DisplayCurrentRenderPipeline()
{
// GraphicsSettings.defaultRenderPipeline determines the default render pipeline
// If it is null, the default is the Built-in Render Pipeline
if (GraphicsSettings.defaultRenderPipeline != null)
{
Debug.Log("The default render pipeline is defined by " + GraphicsSettings.defaultRenderPipeline.name);
}
else
{
Debug.Log("The default render pipeline is the Built-in Render Pipeline");
}
// QualitySettings.renderPipeline determines the override render pipeline for the current quality level
// If it is null, no override exists for the current quality level
if (QualitySettings.renderPipeline != null)
{
Debug.Log("The override render pipeline for the current quality level is defined by " + QualitySettings.renderPipeline.name);
}
else
{
Debug.Log("No override render pipeline exists for the current quality level");
}
// If an override render pipeline is defined, Unity uses that
// Otherwise, it falls back to the default value
if (QualitySettings.renderPipeline != null)
{
Debug.Log("The active render pipeline is the override render pipeline");
}
else
{
Debug.Log("The active render pipeline is the default render pipeline");
}
// To get a reference to the Render Pipeline Asset that defines the active render pipeline,
// without knowing if it is the default or an override, use GraphicsSettings.currentRenderPipeline
if (GraphicsSettings.currentRenderPipeline != null)
{
Debug.Log("The active render pipeline is defined by " +GraphicsSettings.currentRenderPipeline.name);
}
else
{
Debug.Log("The active render pipeline is the Built-in Render Pipeline");
}
}
}