Search Unity

Question Custom pass AggregateCullingParameters not working

Discussion in 'High Definition Render Pipeline' started by PiotrekXR, Jan 16, 2022.

  1. PiotrekXR

    PiotrekXR

    Joined:
    Dec 6, 2021
    Posts:
    1
    I am using Unity 2021.2.4f1 and HDRP 12.1.1. I am trying to create custom pass for rendering metaballs.

    This is my custom pass code:
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Experimental.Rendering;
    3. using UnityEngine.Rendering;
    4. using UnityEngine.Rendering.HighDefinition;
    5.  
    6.  
    7. public class LiquidPass : CustomPass
    8. {
    9.     [SerializeField] private Material blitMaterial;
    10.     [SerializeField] private LayerMask layerMask = 0;
    11.     [SerializeField] private int blurSampleCount = 25;
    12.     [SerializeField] private int blurRadius = 40;
    13.  
    14.     private RTHandle blurBuffer;
    15.  
    16.     protected override void Setup(ScriptableRenderContext renderContext, CommandBuffer commandBuffer)
    17.     {
    18.         blurBuffer = RTHandles.Alloc(
    19.             scaleFactor: new Vector2(0.5f, 0.5f),
    20.             slices: TextureXR.slices,
    21.             dimension: TextureXR.dimension,
    22.             colorFormat: GraphicsFormat.R16G16B16A16_SNorm,
    23.             useDynamicScale: true,
    24.             name: "Blur Buffer"
    25.         );
    26.     }
    27.  
    28.     protected override void AggregateCullingParameters(ref ScriptableCullingParameters cullingParameters, HDCamera camera)
    29.     {
    30.         cullingParameters.cullingMask |= (uint)layerMask.value;
    31.     }
    32.  
    33.     protected override void Execute(CustomPassContext customPassContext)
    34.     {
    35.         // Draw renderers with selected layers
    36.         CustomPassUtils.DrawRenderers(customPassContext, layerMask);
    37.  
    38.         // Blur custom buffer
    39.         RTHandle target = customPassContext.customColorBuffer.Value;
    40.         float blurRadiusScale = customPassContext.cameraColorBuffer.rtHandleProperties.rtHandleScale.x;
    41.         CustomPassUtils.GaussianBlur(customPassContext, target, target, blurBuffer, blurSampleCount, blurRadius * blurRadiusScale, downSample: true);
    42.  
    43.         // Blit custom buffer to camera buffer
    44.         int passId = blitMaterial.FindPass("Forward");
    45.         if (passId == -1) passId = blitMaterial.FindPass("ForwardOnly");
    46.         CoreUtils.SetRenderTarget(customPassContext.cmd, customPassContext.cameraColorBuffer, customPassContext.cameraDepthBuffer);
    47.         CoreUtils.DrawFullScreen(customPassContext.cmd, blitMaterial, shaderPassId: passId);
    48.     }
    49.  
    50.     protected override void Cleanup()
    51.     {
    52.         blurBuffer.Release();
    53.     }
    54. }
    55.  
    It works as expected, but the original objects are still rendered by the camera:
    upload_2022-1-16_14-23-36.png

    When I disable Liquid layer in the camera Culling Mask, the objects completely disappear but
    CustomPassUtils.DrawRenderers does not render them either.

    If I remove AggregateCullingParameters override completely the camera renders them but DrawRenderers does not in any circumstances.

    These are my custom pass settings:
    upload_2022-1-16_14-26-16.png

    I have other issue too where when I change TargetDepthBuffer to Custom, the DrawRenderers again does not render the objects in any way (stops working) which is weird.

    What's more weird is that I am trying to achieve an effect similar to that in this example: https://github.com/alelievr/HDRP-Custom-Passes/tree/master/Assets/CustomPasses/Liquid , and in that example it works in the Visual Effect graph but does not work on the mesh renderers (left: scene view, right: game view):
    upload_2022-1-16_14-31-47.png
     

    Attached Files: