Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Unable to clear a single RenderTexture inside RenderFeature

Discussion in 'Universal Render Pipeline' started by PelvisParsley, May 12, 2023.

  1. PelvisParsley

    PelvisParsley

    Joined:
    Aug 9, 2016
    Posts:
    89
    I have a render feature where Im interacting with multiple RTs but for this example Ill assume we have 2, the camera texture and a custom RTHandle.

    Currently its works fine with a single SetRenderTarget:
    Code (CSharp):
    1. buffer.SetRenderTarget(new RenderTargetIdentifier[]{BuiltinRenderTextureType.CurrentActive, _handle}, BuiltinRenderTextureType.CurrentActive);
    2.                 buffer.ClearRenderTarget(false, false, Color.clear);
    This renders properly on both textures. But I'd like to clear "_handle" and not the camera texture. When I try this:
    Code (CSharp):
    1.                 cmd.SetRenderTarget(_handle, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.DontCare);
    2.                 cmd.ClearRenderTarget(false, true, Color.red);
    3.                 cmd.SetRenderTarget(new RenderTargetIdentifier[]{BuiltinRenderTextureType.CurrentActive, _handle}, BuiltinRenderTextureType.CurrentActive);
    4.                 cmd.ClearRenderTarget(false, false, Color.clear);
    SetRenderTarget does not work a second time. If I move the first two calls to OnCameraSetup, or FrameCleanup, the texture always stays the color red, nothing is drawn into it. Which I dont understand because drawing is still occurring inside Execute(). What can I do to clear this RTHandle properly prior to draw?
     
  2. PelvisParsley

    PelvisParsley

    Joined:
    Aug 9, 2016
    Posts:
    89
    bumping this, as Im stuck with this. If anyone knows another way to clear multiple targets inside a render feature, do let me know