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.

Problems with URP custom post-processing

Discussion in 'Image Effects' started by D3SYNK, Nov 20, 2021.

  1. D3SYNK

    D3SYNK

    Joined:
    Nov 20, 2021
    Posts:
    2
    Foreword: I do not have that much experience with rendering, this is my first time exploring the topic.

    So I created a Scriptable render feature using this tutorial.
    I got graphics working perfectly fine, except when the new renderer feature is enabled, it just displays a black screen. I don't really know exactly what I'm doing so I don't really know what's going wrong.

    A few screen shots and some code:

    My ScriptableRendererFeature -
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Rendering;
    3. using UnityEngine.Rendering.Universal;
    4.  
    5. public class BlitMaterial : ScriptableRendererFeature
    6. {
    7.     class CustomRenderPass : ScriptableRenderPass
    8.     {
    9.         public RenderTargetIdentifier source;
    10.         public Material toApply;
    11.         RenderTargetHandle temp;
    12.  
    13.         public override void Configure(CommandBuffer cmd, RenderTextureDescriptor cameraTextureDescriptor)
    14.         {
    15.             temp.Init("_temp");
    16.         }
    17.  
    18.         public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
    19.         {
    20.             CommandBuffer cb = CommandBufferPool.Get();
    21.  
    22.             cb.GetTemporaryRT(temp.id, renderingData.cameraData.cameraTargetDescriptor);
    23.             Blit(cb, source, temp.Identifier(), toApply);
    24.             Blit(cb, temp.Identifier(), source);
    25.  
    26.             context.ExecuteCommandBuffer(cb);
    27.             cb.Release();
    28.         }
    29.     }
    30.  
    31.     public Material ApplicableMaterial;
    32.     CustomRenderPass m_ScriptablePass;
    33.  
    34.     public override void Create()
    35.     {
    36.         m_ScriptablePass = new CustomRenderPass();
    37.         m_ScriptablePass.renderPassEvent = RenderPassEvent.BeforeRenderingPostProcessing;
    38.     }
    39.  
    40.     public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
    41.     {
    42.         m_ScriptablePass.toApply = ApplicableMaterial;
    43.         m_ScriptablePass.source = renderer.cameraColorTarget;
    44.         renderer.EnqueuePass(m_ScriptablePass);
    45.     }
    46. }
    47.  
    The 2D Lit shader graph I'm using for my material -
    upload_2021-11-20_5-12-52.png

    The two frame debugger draws for each Blit -
    upload_2021-11-20_5-14-23.png
    In this one, you can see the camera color texture has some white text inside of it
    upload_2021-11-20_5-15-11.png
    In this one, the _MainTex property is completely black. ???
    Blit in the documentation says it copies to the material's _MainTex, but here it looks like it isn't doing much of anything. I'm just more confused than anything.

    Thanks in advance.
     
  2. GoGoGadget

    GoGoGadget

    Joined:
    Sep 23, 2013
    Posts:
    836
    Try blitting to renderer.cameraColorTarget instead of source in your second blit there.
     
  3. D3SYNK

    D3SYNK

    Joined:
    Nov 20, 2021
    Posts:
    2
    m_ScriptablePass.source is set to renderer.cameraColorTarget before the render is queued. It should be directly referencing renderer.cameraColorTarget through the source variable. In any case, I tried passing in a ScriptableRenderer instead of a RenderTargetIdentifier but it didn't help.
    m_ScriptablePass.source = renderer;

    instead of
    m_ScriptablePass.source = renderer.cameraColorTarget;
     
unityunity