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

Feature Request [URP] Lacking Render Pass Injection Points

Discussion in 'Graphics Dev Blitz Day 2023 - Q&A' started by wwWwwwW1, May 24, 2023.

  1. wwWwwwW1

    wwWwwwW1

    Joined:
    Oct 31, 2021
    Posts:
    609
    Hi, the current URP render pass events don't allow rendering before/after motion vectors and TAA.

    I remember that this is possible in HDRP, so is there any plan to add this important feature?
     
    goncalo-vasconcelos likes this.
  2. wwWwwwW1

    wwWwwwW1

    Joined:
    Oct 31, 2021
    Posts:
    609
    Bump.

    All motion related effects can only access correct motion vectors after rendering post-processing, which will break many things (distortion, TAA).

    If it's technically difficult to add new injection points (RenderPassEvent), I suggest moving the URP motion vectors pass to before rendering post-processing.
     
  3. ManueleB

    ManueleB

    Unity Technologies

    Joined:
    Jul 6, 2020
    Posts:
    86
    Hey!

    I double checked the code and the pass is already injected BeforeRenderingPostProcessing, have you tried injecting your pass at RenderPassEvent.BeforeRenderingPostProcessing + 1? In general injection points work like integers in a certain range for priority, so adding N after your RenderPassEvent should allow you to have your pass in between MotionVector and PostProcessing. Not sure if this helps?


    Code (CSharp):
    1.  internal MotionVectorRenderPass(Material cameraMaterial)
    2.         {
    3.             renderPassEvent = RenderPassEvent.BeforeRenderingPostProcessing;
    4.             m_CameraMaterial = cameraMaterial;
    5.             m_PassData = new PassData();
    6.             base.profilingSampler = ProfilingSampler.Get(URPProfileId.MotionVectors);
    7.  
    8.             ConfigureInput(ScriptableRenderPassInput.Depth);
    9.         }
    we are also discussing changing some passes RenderPassEvents in the frame so will considering moving motion vectors earlier
     
  4. wwWwwwW1

    wwWwwwW1

    Joined:
    Oct 31, 2021
    Posts:
    609
    Hi, thanks for the reply!

    I tried injecting the render pass at
    RenderPassEvent.BeforeRenderingPostProcessing + 1
    , but the Blitter complains that
    renderingData.cameraData.renderer.cameraColorTargetHandle
    is null.

    Code (CSharp):
    1. Assertion failed
    2. UnityEngine.Rendering.Blitter:BlitCameraTexture (UnityEngine.Rendering.CommandBuffer,UnityEngine.Rendering.RTHandle,UnityEngine.Rendering.RTHandle,UnityEngine.Material,int)
    3.  
    4. ...
    Should I make a bug report? I used to think that
    RenderPassEvent.BeforeRenderingPostProcessing + 1
    should not be used because of the error.
     
  5. wwWwwwW1

    wwWwwwW1

    Joined:
    Oct 31, 2021
    Posts:
    609
    I did another test and the custom render pass works after removing the use of (empty)
    renderingData.cameraData.renderer.cameraColorTargetHandle
    , but it seems that the actual injection point will be the same as
    RenderPassEvent.AfterRenderingPostProcessing
    .

    URP_BeforePostProcessing_PlusOne.jpg

    Perhaps moving the motion vectors pass earlier is the only solution to this. Is it possible to have this solved in 2023.2, because I believe temporal reprojection is a big usage of motion vectors.

    Thanks again!
     
  6. wwWwwwW1

    wwWwwwW1

    Joined:
    Oct 31, 2021
    Posts:
    609
    Bump
     
  7. ManueleB

    ManueleB

    Unity Technologies

    Joined:
    Jul 6, 2020
    Posts:
    86
    I had a look and looks like the postprocessing passes are being queued in BeforeRenderingPostProcessing, so any render feature injected in the same place wouldn't work as expected. I am making a quick fix moving the postProcessing pass in the correct place so your code should work as expected by using BeforeRenderingPostProcessing + 1
     
    wwWwwwW1 likes this.
  8. ManueleB

    ManueleB

    Unity Technologies

    Joined:
    Jul 6, 2020
    Posts:
    86
    (this will already work with the RenderGraph path once we enable it for everyone in 23 as we improved the injection point system for that, this specific fix should make it work as expected also on the old (current) one)

    while waiting for the fix you can modify the package locally as a temporary workaround:

    In PostProcessPasses.cs, replace the code at the end of the Recreate() function with this:


    Code (CSharp):
    1. if (data != null)
    2.             {
    3.                 m_ColorGradingLutPass = new ColorGradingLutPass(RenderPassEvent.BeforeRenderingPrePasses, data);
    4.                 m_PostProcessPass = new PostProcessPass(RenderPassEvent.AfterRenderingPostProcessing - 2, data, ref ppParams);
    5.                 m_FinalPostProcessPass = new PostProcessPass(RenderPassEvent.AfterRenderingPostProcessing - 1, data, ref ppParams);
    6.                 m_CurrentPostProcessData = data;
    7.             }
     
    wwWwwwW1 likes this.