Search Unity

Question URP 13.1.8 is adding Clear() after my custom RenderPass if start BeforeRenderingOpaque?

Discussion in 'Universal Render Pipeline' started by Babiole, Jun 2, 2022.

  1. Babiole

    Babiole

    Joined:
    May 7, 2016
    Posts:
    17
    Hi, I updated my project from URP 12 to URP 13, and since then my render pass is followed automagically by a "Clear" color, which is the opposite of what I want.
    If I'm writing inside the RenderTarget in the BeforeRenderingOpaques this for a good reason why this "Clear" appear from nowhere?

    upload_2022-6-2_10-37-53.png

    Also, if I call the BlitToStack pass on the AfterRenderingOpaques, no clear appear automagically between my pass and the next pass. Where this clear come from? And why urp assume we need a clear here? It was working perfectly on URP 12 without this clear.


    Code (CSharp):
    1. private RTHandle _target;
    2.         private RTHandle _rtd;
    3.        
    4.         void Dispose()
    5.         {
    6.             _rtd?.Release();
    7.         }
    8.        
    9.         public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderingData)
    10.         {
    11.             _target = renderingData.cameraData.renderer.cameraColorTargetHandle;
    12.             var desc = renderingData.cameraData.cameraTargetDescriptor;
    13.             desc.depthBufferBits = 0; // Color and depth cannot be combined in RTHandles
    14.             RenderingUtils.ReAllocateIfNeeded(ref _rtd, desc, FilterMode.Point, TextureWrapMode.Clamp, name: "_MergeBufferHandle");
    15.         }
    16.  
    17.         public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
    18.         {
    19.             var cb = CommandBufferPool.Get("BlitToStack");
    20.             CreateCommandBuffer(cb);
    21.             context.ExecuteCommandBuffer(cb);
    22.             CommandBufferPool.Release(cb);
    23.         }
    24.  
    25.         private void CreateCommandBuffer(CommandBuffer cb)
    26.         {
    27.             if (StackTexture.Count > 1)
    28.             {
    29.                 for (var i = 0; i < StackTexture.Count; i++)
    30.                 {
    31.                     cb.SetGlobalTexture("_MainTex", StackTexture[i]);
    32.                     cb.Blit(StackTexture[i], _rtd, Mat, 0);//, new Vector2(1f, -1f), new Vector2(0, 1f));
    33.                 }
    34.                 cb.Blit(_rtd, _target);
    35.             }
    36.             else
    37.             {
    38.                 cb.Blit(StackTexture[0], _target);
    39.             }
    40.         }
     
  2. kankane

    kankane

    Joined:
    Feb 22, 2013
    Posts:
    23
    Did you ever figure this out? I am running into the same issue.
     
  3. AurochChris

    AurochChris

    Joined:
    Jan 7, 2014
    Posts:
    24
    @kankane I've not encountered the issue before, but in OnCameraSetup() have you tried calling ConfigureClear(ClearTarget.none, Color.clear) by any chance?
     
    kankane likes this.
  4. kankane

    kankane

    Joined:
    Feb 22, 2013
    Posts:
    23
    Hey @AurochChris, thanks for the idea. I just tried that but no change unfortunately.
     
  5. kankane

    kankane

    Joined:
    Feb 22, 2013
    Posts:
    23
    Actually, I spoke too soon. It does seem to work on the mobile device but not in the editor. I can work with that for now. Thanks!