本页包含有关在内置渲染管线中使用 CommandBuffer 的信息。有关在渲染管线中基于可编程渲染管线使用 CommandBuffer 的信息,请参阅在可编程渲染管线中调度和执行渲染命令。
CommandBuffer 保存渲染命令列表(例如设置渲染目标或绘制给定网格)。您可以指示 Unity 在内置渲染管线中的各个点安排和执行这些命令,因此,您可以自定义和扩展 Unity 的渲染功能。
可以使用 Graphics.ExecuteCommandBuffer API 立即执行 CommandBuffer,也可以进行安排,让它们在渲染管线中的给定点执行。要安排它们,请使用 Camera.AddCommandBuffer API 与CameraEvent 枚举,以及 Light.AddCommandBuffer API 与 LightEvent 枚举。要查看 Unity 何时执行以这种方式安排的 CommandBuffer,请参阅 CameraEvent 和 LightEvent 的执行顺序。
有关可以使用 CommandBuffer 执行的命令的完整列表,请参阅 CommandBuffer API 文档。请注意,一些命令仅在某些硬件上受支持。例如,与光线追踪有关的命令仅在 DX12 中受支持。
Unity 博客文章扩展 Unity 5 渲染管线:CommandBuffer 介绍了内置渲染管线中的 CommandBuffer,并包含示例项目和示例代码。它介绍如何使用 CommandBuffer 来实现几种不同的效果,并包含一个示例项目和示例代码。项目是为 Unity 的旧版本创建的,但原理相同。
CameraEvents 执行顺序取决于项目使用的渲染路径。
延迟渲染路径
前向渲染路径
在上面的“渲染阴影”阶段,对于每个投射阴影的光源,Unity 执行以下步骤:
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.