A Command Buffer holds a list of rendering commands. You can instruct Unity to schedule and execute those commands.
This page contains information on using Command Buffers in the Built-in Render Pipeline. For information on using Command Buffers in the Scriptable Rendering Pipeline, see Scheduling and executing rendering commands in the Scriptable Rendering Pipeline.
For a full list of the commands that you can execute using Command Buffers, see the CommandBuffer API documentation. Note that some commands are supported only on certain hardware; for example, the commands relating to ray tracing are supported only in DX12.
You can execute Command Buffers immediately using the Graphics.ExecuteCommandBuffer API.
In the Built-in Render Pipeline, you can execute Command Buffers at specific times in the render loop; to do this, use the Camera.AddCommandBuffer API with the CameraEvent enum, and the Light.AddCommandBuffer API with the LightEvent enum.
For example, you can use a Command Buffer with the AfterGBuffer CameraEvent to render additional GameObjects into the Deferred pipeline, after the pipeline processes all opaque GameObjects.
The order of execution depends on the rendering path that your Project uses.
Deferred rendering path | |
---|---|
BeforeGBuffer | |
Unity renders opaque geometry. | |
AfterGBuffer | |
Unity resolves depth. | |
BeforeReflections | |
Unity renders default reflections. | |
Unity renders Reflection Probe reflections. | |
AfterReflections | |
Unity copies reflections to the Emissive channel of the G-buffer. | |
BeforeLighting | |
Unity renders shadows. See LightEvent order of execution. | |
AfterLighting | |
BeforeFinalPass | |
Unity processes the final pass. | |
AfterFinalPass | |
BeforeForwardOpaque (only called if there is opaque geometry that cannot be rendered using deferred) | |
Unity renders opaque geometry that cannot be rendered with deferred rendering. | |
AfterForwardOpaque (only called if there is opaque geometry that cannot be rendered using deferred) | |
BeforeSkybox | |
Unity renders the skybox. | |
AfterSkybox | |
Unity renders halos. | |
BeforeImageEffectsOpaque | |
If you are using the Post-processing Stack V2 package, Unity applies opaque-only post-processing effects. | |
AfterImageEffectsOpaque | |
BeforeForwardAlpha | |
Unity renders transparent geometry, and UI Canvases with a Rendering Mode of Screen Space - Camera. | |
AfterForwardAlpha | |
BeforeHaloAndLensFlares | |
Unity renders lens flares. | |
AfterHaloAndLensFlares | |
BeforeImageEffects | |
If you are using the Post-processing Stack V2 package, Unity applies post-processing effects. | |
AfterImageEffects | |
AfterEverything | |
Unity renders UI Canvases with a Rendering Mode that is not Screen Space - Camera. |
Forward rendering path |
---|
BeforeDepthTexture |
Unity renders depth for opaque geometry. |
AfterDepthTexture |
BeforeDepthNormalsTexture |
Unity renders depth normals for opaque geometry. |
AfterDepthNormalsTexture |
Unity renders shadows. See LightEvent order of execution. |
BeforeForwardOpaque |
Unity renders opaque geometry. |
AfterForwardOpaque |
BeforeSkybox |
Unity renders the skybox. |
AfterSkybox |
Unity renders halos. |
BeforeImageEffectsOpaque |
If you are using the Post-processing Stack V2 package, Unity applies opaque-only post-processing effects. |
AfterImageEffectsOpaque |
BeforeForwardAlpha |
Unity renders transparent geometry, and UI Canvases with a Rendering Mode of Screen Space - Camera. |
AfterForwardAlpha |
BeforeHaloAndLensFlares |
Unity renders lens flares. |
AfterHaloAndLensFlares |
BeforeImageEffects |
If you are using the Post-processing Stack V2 package, Unity applies post-processing effects. |
AfterImageEffects |
AfterEverything |
Unity renders UI Canvases with a Rendering Mode of Screen Space - Camera. |
During the “render shadows” stage above, for each shadow-casting Light, Unity performs these steps:
BeforeShadowMap | |
BeforeShadowMapPass Unity renders all shadow casters for the current pass AfterShadowMapPass |
Repeat for each pass |
AfterShadowMap | |
BeforeScreenSpaceMask | |
Unity gathers the shadow map into a screen space buffer and performs filtering | |
AfterScreenSpaceMask |