命令缓冲区可保存一组渲染命令。您可以指示 Unity 调度和执行这些命令。
本页包含有关在内置渲染管线中使用命令缓冲区的信息。有关在可编程渲染管线中使用命令缓冲区的信息,请参阅在可编程渲染管线中调度和执行渲染命令。
有关可以使用命令缓冲区执行的命令的完整列表,请参阅 CommandBuffer API 文档。请注意,一些命令仅在某些硬件上受支持。例如,与射线追踪有关的命令仅在 DX12 中受支持。
可以使用 Graphics.ExecuteCommandBuffer API 立即执行命令缓冲区。
在内置渲染管线中,可以在渲染循环中的特定时间执行命令缓冲区。为此,请将 Camera.AddCommandBuffer API 与 CameraEvent 枚举一起使用,并将 Light.AddCommandBuffer API 与 LightEvent 枚举一起使用。
例如,可以将命令缓冲区与 AfterGBuffer CameraEvent 结合使用,从而将其他游戏对象渲染到延迟管线中(在管线处理所有不透明的游戏对象之后)。
执行顺序取决于项目使用的渲染路径。
延迟渲染路径 | |
---|---|
BeforeGBuffer | |
Unity 渲染不透明几何体。 | |
AfterGBuffer | |
Unity 解析深度。 | |
BeforeReflections | |
Unity 渲染默认反射。 | |
Unity 渲染反射探针反射。 | |
AfterReflections | |
Unity 将反射复制到 G 缓冲区的 Emissive 通道。 | |
BeforeLighting | |
Unity 渲染阴影。请参阅 LightEvent 执行顺序。 | |
AfterLighting | |
BeforeFinalPass | |
Unity 对最终通道进行处理。 | |
AfterFinalPass | |
BeforeForwardOpaque(仅当存在无法以延迟方式渲染的不透明几何体时调用) | |
Unity 渲染无法以延迟方式渲染的不透明几何体。 | |
AfterForwardOpaque(仅当存在无法以延迟方式渲染的不透明几何体时调用) | |
BeforeSkybox | |
Unity 渲染天空盒。 | |
AfterSkybox | |
Unity 渲染光环。 | |
BeforeImageEffectsOpaque | |
如果使用 Post-processing Stack V2 包,则 Unity 会应用仅限不透明的后期处理效果。 | |
AfterImageEffectsOpaque | |
BeforeForwardAlpha | |
Unity 会渲染透明几何体以及具有 Screen Space - Camera 渲染模式的 UI 画布。 | |
AfterForwardAlpha | |
BeforeHaloAndLensFlares | |
Unity 渲染镜头光晕。 | |
AfterHaloAndLensFlares | |
BeforeImageEffects | |
如果使用 Post-processing Stack V2 包,则 Unity 会应用后期处理效果。 | |
AfterImageEffects | |
AfterEverything | |
Unity 对渲染模式不是 Screen Space - Camera 的 UI 画布进行渲染。 |
前向渲染路径 |
---|
BeforeDepthTexture |
Unity 渲染不透明几何体的深度。 |
AfterDepthTexture |
BeforeDepthNormalsTexture |
Unity 渲染不透明几何体的深度法线。 |
AfterDepthNormalsTexture |
Unity 渲染阴影。请参阅 LightEvent 执行顺序。 |
BeforeForwardOpaque |
Unity 渲染不透明几何体。 |
AfterForwardOpaque |
BeforeSkybox |
Unity 渲染天空盒。 |
AfterSkybox |
Unity 渲染光环。 |
BeforeImageEffectsOpaque |
如果使用 Post-processing Stack V2 包,则 Unity 会应用仅限不透明的后期处理效果。 |
AfterImageEffectsOpaque |
BeforeForwardAlpha |
Unity 会渲染透明几何体以及具有 Screen Space - Camera 渲染模式的 UI 画布。 |
AfterForwardAlpha |
BeforeHaloAndLensFlares |
Unity 渲染镜头光晕。 |
AfterHaloAndLensFlares |
BeforeImageEffects |
如果使用 Post-processing Stack V2 包,则 Unity 会应用后期处理效果。 |
AfterImageEffects |
AfterEverything |
Unity 对渲染模式为 Screen Space - Camera 的 UI 画布进行渲染。 |
在上面的“渲染阴影”阶段,对于每个投射阴影的光源,Unity 执行以下步骤:
BeforeShadowMap | |
BeforeShadowMapPass Unity 渲染当前通道的所有阴影投射物 AfterShadowMapPass |
对每个通道进行重复 |
AfterShadowMap | |
BeforeScreenSpaceMask | |
Unity 将阴影贴图收集到屏幕空间缓冲区中并执行过滤 | |
AfterScreenSpaceMask |
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.