Search Unity

Question Custom Multi-Pass Post Process Effect HDRP

Discussion in 'High Definition Render Pipeline' started by Frostbite23, Aug 23, 2020.

  1. Frostbite23

    Frostbite23

    Joined:
    Mar 8, 2013
    Posts:
    458
    Hello, long time user here (of unity, not HDRP), and I'm stuck on what seems like a rather simple issue.

    I've been porting an effect I made in the regular standard pipeline, and I'm close to completion though it's just been an absolute nightmare at this point. I should note I'm relatively new to scripting with this specific pipeline and I've been searching around on how I can do this in HDRP for a post process effect. Yet seemingly for some reason no one has asked this question anywhere and it drives me nuts trying to figure out how to work with this behemoth of a pipeline. But anyways on to my question.

    In the standard pipeline, when it comes to doing multi-pass effects and you wanted to get the render target of the pass you would simply do something like this.

    Code (CSharp):
    1. var compColor = RenderTexture.GetTemporary(context.width, context.height, 0, RenderTextureFormat.ARGBHalf);
    2. var blurFilter1 = RenderTexture.GetTemporary(context.width, context.height, 0, RenderTextureFormat.ARGBHalf);
    3. var blurFilter2 = RenderTexture.GetTemporary(context.width, context.height, 0, RenderTextureFormat.ARGBHalf);
    4. var sceneColor = RenderTexture.GetTemporary(context.width, context.height, 0, RenderTextureFormat.ARGBHalf);
    5.  
    6. command.BlitFullscreenTriangle(sceneColor, context.destination, sheet, 0);
    7. command.BlitFullscreenTriangle(context.source, compColor, sheet, 1);
    8. command.BlitFullscreenTriangle(compColor, blurFilter1, sheet, 2);
    9. command.BlitFullscreenTriangle(blurFilter1, blurFilter2, sheet, 3);
    10. sheet.properties.SetTexture("_SceneColor", sceneColor);
    11. context.command.BlitFullscreenTriangle(blurFilter2, context.destination, sheet, 5);
    12.  
    13. RenderTexture.ReleaseTemporary(compColor);
    14. RenderTexture.ReleaseTemporary(blurFilter1);
    15. RenderTexture.ReleaseTemporary(blurFilter2);
    16. RenderTexture.ReleaseTemporary(sceneColor);
    You would simply get a temporary render texture and use that as your 'destination' and if you had multiple passes you would simply get more render textures and just chain it down as needed.

    This works perfectly and it's simple and I haven't had a problem with it. So how the heck do I do this in HDRP I've been struggling to figure out.

    The reason being that in the template the blit function is replaced with
    Code (CSharp):
    1. HDUtils.DrawFullScreen(command, m_Material, compColor, null, 0);
    Not a big deal, except that where 'compColor' is, needs to be an RTHandle instead of a render texture. I tried to convert the render texture to an RTHandle however that doesn't work. So what do I do? I've been scratching my head on this for days, and I've been digging through the mess that is the HDRP code trying to figure out how Unity does multi-pass post process effects.

    Can someone help me out please? This is coming from someone who is used to making post process effects in the standard pipeline, but this HDRP pipeline currently has just been proving to be a nightmare. Now I understand though that this is a new pipeline and it's not going to be as simple as doing it the way I'm used to doing it in the standard pipeline, but it'd be mighty helpful for me (and for others who come across this thread) if someone can explain how to do something like that in this new pipeline (or at the very least, point me in the right direction).
     
    Last edited: Aug 23, 2020
  2. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    2,361
  3. antoinel_unity

    antoinel_unity

    Unity Technologies

    Joined:
    Jan 7, 2019
    Posts:
    265
    Yes, the Blur effect from custom passes above should work in a post-process as well.

    Note that we plan to have an API for render target pooling in post processes for multi-pass effects, it will hopefully make things easier to write.