Search Unity

Custom Post processing in 2019.3 HDRP/URP

Discussion in 'High Definition Render Pipeline' started by mutp, Aug 29, 2019.

  1. mutp

    mutp

    Joined:
    Oct 1, 2018
    Posts:
    79
    Is custom post processing available in either HDRP or URP post processing stacks? Based on my experiment, it doesn't seem to be the case. Is there a timeline on when we can expect this?
     
  2. rz_0lento

    rz_0lento

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

    jister

    Joined:
    Oct 9, 2009
    Posts:
    1,749
    Since 2019.3 is out, any updates on this? do we still have to pull the SRP from git to get access to custom post processing?
     
  4. Bordeaux_Fox

    Bordeaux_Fox

    Joined:
    Nov 14, 2018
    Posts:
    589
    HDRP 7.2.0 comes out this week.
     
  5. jister

    jister

    Joined:
    Oct 9, 2009
    Posts:
    1,749
    Last edited: Feb 3, 2020
  6. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    2,361
    Custom post processing and custom passes have been for a while on 7.1 already. Been using both myself.

    In addition to @jister's link, here's one for custom passes:
    https://docs.unity3d.com/Packages/c...s.high-definition@7.1/manual/Custom-Pass.html
    and here's a demo repo on how custom passes:
    https://github.com/alelievr/HDRP-Custom-Passes

    Both custom passes and custom pp passes have their own use cases. Custom passes can be handy if you need to inject passes for specific meshes at some point in the frame graph, I've used this for example to tag objects from specific layers with simple stencil write shader so I can tag HDRP's built-in stencil bits like ExcludeFromTAA bit (which you can't set other than manually via shader right now).
     
    jister likes this.
  7. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    2,361
    Here's a quickly ported color blindness emulation on HDRP PP using custom PP pass:


    source code: HDRP_ColorBlindnessPP.zip

    And here's a stencil write example for custom pass: CustomStencilPass.unitypackage (just drag the prefab to scene, then just change the stencil write bit from the included material).

    HDRP's stencilbitmask values for 7.1.x here.
    and for 7.2.0 and onwards, you can find the bits here.

    Do note that these were just quick experiments, and are not a fully polished examples and can therefore still contain some errors.
     
    BATTLEKOT and jister like this.
  8. jister

    jister

    Joined:
    Oct 9, 2009
    Posts:
    1,749
    @rizu thanks for the examples
    any idea how to get World Space Positions to work?
    I use to do this in an Image Effect shader to get a world space reference frame:
    Code (CSharp):
    1. struct appdata
    2.             {
    3.                 float4 vertex : POSITION;
    4.                 float2 uv : TEXCOORD0;
    5.                 float4 ray : TEXCOORD1;
    6.             };
    7.  
    8. ...
    9.  
    10. v2f vert(appdata v)
    11.             {
    12.                 v2f o;
    13.                 o.vertex = UnityObjectToClipPos(v.vertex);
    14.                 o.uv = v.uv.xy;
    15.                 o.interpolatedRay = v.ray;
    16.                 UNITY_TRANSFER_FOG(o,o.vertex);
    17.                 return o;
    18.             }
    19.  
    20. ...
    21.  
    22. half rawDepth = DecodeFloatRG(tex2D(_CameraDepthTexture, i.uv.xy));
    23.                 half linearDepth = Linear01Depth(rawDepth);
    24.                 half4 wsDir = linearDepth * i.interpolatedRay;
    25.                 half3 wsPos = _WorldSpaceCameraPos + wsDir;
    If I Debugged wsPos, I got this:
    wsPos.PNG
    with the Interpolated ray being the magic that gave this at the camera's position:
    interpolatedray.PNG

    I tried almost everything i could find, but am not able to reproduce this in the PP Shader.
    Could someone show how to get this result in HD Postprocessing shader?
     
  9. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    2,361
    Do note that HDRP is rendering camera relative, so some things don't work quite like they used to. If I know some PP effect needs similar thing, I can just peek into built-in PP shaders and see how they solved it there.

    And I often also check how HDRP shader graphs do things to get an example snippet. For example wire a simple shader graph, put there some property name that I can easily search for and right click the master node on graph to get the generated shader code for it.
     
  10. jister

    jister

    Joined:
    Oct 9, 2009
    Posts:
    1,749
    @rizu thanks for the tip, found my answer here.

    to get the same result as in the first screen, I use this now:
    Code (CSharp):
    1. float depth = LoadCameraDepth(input.positionCS.xy);
    2.         half linearDepth = Linear01Depth(depth, _ZBufferParams);
    3.        
    4.         PositionInputs posInput = GetPositionInput(input.positionCS.xy, _ScreenSize.zw, depth, UNITY_MATRIX_I_VP, UNITY_MATRIX_V);
    5.        
    6.         float4 worldPos = float4(posInput.positionWS, 1.0);
    7.         float4 curClipPos = mul(UNITY_MATRIX_UNJITTERED_VP, worldPos);
    8.         float2 positionCS = curClipPos.xy / curClipPos.w;
    9. half3 wsPos = _WorldSpaceCameraPos + worldPos;
    10. return float4(wsPos, 1);
    Possibilities are endless again! ;p
     
    rz_0lento likes this.