Search Unity

Showcase Custom Pass tool for Multi Passes

Discussion in 'High Definition Render Pipeline' started by VladvSydorenko, Jan 20, 2023.

  1. VladvSydorenko

    VladvSydorenko

    Joined:
    Mar 15, 2017
    Posts:
    4
    Hello.

    I've created a small library for myself for Custom Passes in HDRP.

    I wanted something better then
    Code (CSharp):
    1. if (injectionPoint === CustomPassInjectionPoint.AfterOpaqueDepthAndNormal)
    2. {
    3.   // write depth
    4. }
    5. else
    6. {
    7.   // write color
    8. }
    9.  
    So, I've made an attribute to simplify it in a way
    `[FakePass(injectionPoint, stage)]`

    For Setup stage:
    Code (CSharp):
    1.        
    2. // Inject in Setup
    3. [FakePass(CustomPassInjectionPoint.AfterOpaqueDepthAndNormal, FakePassStage.Setup)]
    4. private void Setup_AfterDepth(ScriptableRenderContext renderContext, CommandBuffer cmd)
    5. {
    6.     // like in CustomPass.Setup
    7. }
    8.  
    Or for Execute stage:
    Code (CSharp):
    1.  
    2. // Inject in Execute
    3. [FakePass(CustomPassInjectionPoint.AfterOpaqueDepthAndNormal, FakePassStage.Execute)]
    4. private void Execute_AfterDepth(CustomPassContext ctx)
    5. {
    6.     // like in CustomPass.Execute
    7. }
    8.  
    And cleanup:
    Code (CSharp):
    1.  
    2. // Inject in Cleanup
    3. [FakePass(CustomPassInjectionPoint.AfterOpaqueDepthAndNormal, FakePassStage.Cleanup)]
    4. private void Cleanup_AfterDepth()
    5. {
    6.     // like in CustomPass.Cleanup
    7. }
    8.  
    Then add your instance to injection
    Code (CSharp):
    1. // add to injection
    2. InjectionSetttings.Injector.Add(this);
    3.  
    4. // remove from injection
    5. InjectionSetttings.Injector.Remove(this);
    The injector should have all CustomPasses for all injection points (included in packages's samples).
    Screenshot 2023-01-20 141433.png

    BaseClass helper
    You can extend FakePassBase (MonobeBaviour).
    In this case you shouldn't worry about injection.
    Example:
    Code (CSharp):
    1.  
    2. [ExecuteInEditMode]
    3. public class ExampleFakePass : FakePassBase
    4. {
    5.     protected override object Source => this;
    6.  
    7.     // Inject in Setup
    8.     [FakePass(CustomPassInjectionPoint.AfterOpaqueDepthAndNormal, FakePassStage.Setup)]
    9.     private void Setup_AfterDepth(ScriptableRenderContext renderContext, CommandBuffer cmd)
    10.     {
    11.         Debug.Log("Setup");
    12.     }
    13.  
    14.     // Inject in Execute
    15.     [FakePass(CustomPassInjectionPoint.AfterOpaqueDepthAndNormal, FakePassStage.Execute)]
    16.     private void Execute_AfterDepth(CustomPassContext ctx)
    17.     {
    18.         //Debug.Log("Execute");
    19.     }
    20.  
    21.     // Inject in Cleanup
    22.     [FakePass(CustomPassInjectionPoint.AfterOpaqueDepthAndNormal, FakePassStage.Cleanup)]
    23.     private void Cleanup_AfterDepth()
    24.     {
    25.         Debug.Log("Cleanup");
    26.     }
    27. }
    28.  
    From the base class, you have few options:
    Auto Inject - inject OnEnable
    Audo Find Injector - Trying find the injector on the scene
    Screenshot 2023-01-20 140656.png


    Summary
    I've created this small package for easier HDRP custom passes investigation.
    Don't use it in production. It's very alpha and unstable.
    But maybe someone would be interested.

    Github repo: https://github.com/vasdxyz/fakepass
     
    PutridEx, ignarmezh and merpheus like this.