Search Unity

Question Understanding Custom Post Process Orders

Discussion in 'High Definition Render Pipeline' started by TOES, Apr 29, 2023.

  1. TOES

    TOES

    Joined:
    Jun 23, 2017
    Posts:
    134
    How does the custom post process orders under project settings / graphics / hdrp global settings actually work?

    I added my own post process in the "Before Post Process", where I extract the current render buffer. However, when looking at the content of this, I can see Post Processing effects such as Exposure is already added to it.

    But, how come? I thought "Before Post Process" means whatever Post Processing code would be executed before Exposure and others?

    This is my code, for reference, all I want to do with it is to store the image in the renderbuffer so I can access a pure non post processed image (ignore the exposure effects, they are not important).

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Rendering;
    3. using UnityEngine.Rendering.HighDefinition;
    4. using System;
    5.  
    6. [Serializable, VolumeComponentMenu("Post-processing/Custom/PostProcessHelper")]
    7. public sealed class PostProcessHelper : CustomPostProcessVolumeComponent, IPostProcessComponent
    8. {
    9.     [Tooltip("Fixed Exposure")]
    10.     public ClampedFloatParameter fixedExposure = new ClampedFloatParameter(0f, 1f, 15);
    11.  
    12.     [Tooltip("Compensation")]
    13.     public ClampedFloatParameter compensation = new ClampedFloatParameter(0f, -10f, 10);
    14.  
    15.     Material m_Material;
    16.  
    17.     public static RenderTexture renderBuffer;
    18.  
    19.     public bool IsActive() => fixedExposure.value>0;
    20.  
    21.     public override CustomPostProcessInjectionPoint injectionPoint => CustomPostProcessInjectionPoint.BeforePostProcess;
    22.  
    23.     public override void Setup()
    24.     {
    25.         Shader shader = Shader.Find("Custom/PostProcessHelper");
    26.         if ( shader!= null)
    27.             m_Material = new Material(shader);
    28.     }
    29.  
    30.     public override void Render(CommandBuffer cmd, HDCamera camera, RTHandle source, RTHandle destination)
    31.     {
    32.         if (m_Material == null)
    33.             return;
    34.  
    35.         if (renderBuffer == null || renderBuffer.width != source.rt.width || renderBuffer.height != source.rt.height)
    36.         {
    37.             if (renderBuffer != null) DestroyImmediate(renderBuffer);
    38.             renderBuffer = new RenderTexture(source.rt.width, source.rt.height, 0, RenderTextureFormat.ARGBFloat, 0);
    39.         }
    40.         Graphics.Blit(source, renderBuffer);
    41.  
    42.         m_Material.SetFloat("_fixedExposure", fixedExposure.value);
    43.         m_Material.SetFloat("_compensation", compensation.value);
    44.         cmd.Blit(source, destination, m_Material, 0);
    45.     }
    46.  
    47.     public override void Cleanup() => CoreUtils.Destroy(m_Material);
    48.  
    49. }