RTClearFlags
Flags that determine which render targets Unity clears when you use CommandBuffer.ClearRenderTarget.
Read time 2 minutesLast updated 3 hours ago
Definition
- Type: Enum
- Namespace: UnityEngine.Rendering
- Assembly: UnityEngine.CoreModule
[Flags]public enum RTClearFlags
Remarks
You can combine flags by using the bitwise OR operator.
The following example clears a render texture with the selected flags, and displays the render texture on the material of the GameObject. Because the example runs the command buffer outside camera rendering, it works the same way in every render pipeline. Attach the script to a GameObject that has a Renderer component, for example a quad. In the Inspector window, select a Clear Mode, then enter Play mode.
Examples
using UnityEngine;using UnityEngine.Rendering;[RequireComponent(typeof(Renderer))]public class MyClearScript : MonoBehaviour{ public enum ClearMode { All, ColorStencil } public ClearMode m_ClearMode; RenderTexture m_RenderTexture; void Start() { // Create a render texture with a color buffer and a 24-bit depth and stencil buffer. m_RenderTexture = new RenderTexture(256, 256, 24); // Display the render texture on the GameObject's material. GetComponent<Renderer>().material.mainTexture = m_RenderTexture; CommandBuffer buffer = new CommandBuffer(); buffer.SetRenderTarget(m_RenderTexture); switch (m_ClearMode) { case ClearMode.All: // Clear the color, depth, and stencil buffers. Clear the stencil buffer to 0xF0. buffer.ClearRenderTarget(RTClearFlags.All, Color.red, 1.0f, 0xF0); break; case ClearMode.ColorStencil: // Clear only the color and stencil buffers. Clear the stencil buffer to 0xF0. buffer.ClearRenderTarget(RTClearFlags.Color | RTClearFlags.Stencil, Color.green, 1.0f, 0xF0); break; } // Run the command buffer immediately, then release it. Graphics.ExecuteCommandBuffer(buffer); buffer.Release(); } void OnDestroy() { if (m_RenderTexture != null) Destroy(m_RenderTexture); }}
Fields
Value | Description |
|---|---|
| All | Clear all color render targets, the depth buffer, and the stencil buffer. This is equivalent to combining RTClearFlags.Color, RTClearFlags.Depth and RTClearFlags.Stencil. |
| Color | Clear all color render targets. |
| Color0 | Clear color target 0. |
| Color1 | Clear color target 1. |
| Color2 | Clear color target 2. |
| Color3 | Clear color target 3. |
| Color4 | Clear color target 4. |
| Color5 | Clear color target 5. |
| Color6 | Clear color target 6. |
| Color7 | Clear color target 7. |
| ColorDepth | Clear both the color and the depth buffer. This is equivalent to combining RTClearFlags.Color and RTClearFlags.Depth. |
| ColorStencil | Clear both the color and the stencil buffer. This is equivalent to combining RTClearFlags.Color and RTClearFlags.Stencil. |
| Depth | Clear the depth buffer. |
| DepthStencil | Clear both the depth and the stencil buffer. This is equivalent to combining RTClearFlags.Depth and RTClearFlags.Stencil. |
| None | Do not clear any render target. |
| Stencil | Clear the stencil buffer. |