#HDRP onCustomRender, attempting to render the UI into a render target

1 messages · Page 1 of 1 (latest)

naive tartan
#

I'm trying to render the UI into a custom render target on HDRP (between versions 7 - 17). I am aware of this https://github.com/alelievr/HDRP-UI-Camera-Stacking but I am trying to support version 7.x also. I'm trying to use onCustomRender and override a camera with a custom RenderTarget that I create internally.

private void OnCustomRender(ScriptableRenderContext ctx, HDCamera camera)
{
    var cmd = CommandBufferPool.Get("Render UI");
    int depthID = Shader.PropertyToID("_CustomDepth");
    cmd.GetTemporaryRT(depthID, internalRenderTexture.width, internalRenderTexture.height, 24, FilterMode.Point, RenderTextureFormat.Depth);
    var depthRT = new RenderTargetIdentifier(depthID);
    cmd.SetRenderTarget(new RenderTargetIdentifier(internalRenderTexture), depthRT, 0);
    cmd.ClearRenderTarget(true, true, Color.clear);

    ctx.ExecuteCommandBuffer(cmd);
    cmd.Clear();

    // Render the UI
    if (camera.camera.TryGetCullingParameters(out var cullingParameters))
    {
        cullingParameters.cullingMask = (uint)uiLayerMask.value;
        cullingParameters.cullingOptions = CullingOptions.None;

        var cullingResults = ctx.Cull(ref cullingParameters);

        var drawingSettings = new DrawingSettings
        {
            sortingSettings = new SortingSettings(hdCamera.camera)
            {
                criteria = SortingCriteria.CommonTransparent | SortingCriteria.CanvasOrder | SortingCriteria.RendererPriority
            },
            perObjectData = PerObjectData.None,
        };

        for (var i = 0; i < hdTransparentPassNames.Length; i++)
        {
            drawingSettings.SetShaderPassName(i, hdTransparentPassNames[i]);
        }

        var filteringSettings = new FilteringSettings(RenderQueueRange.transparent, uiLayerMask);
        ctx.DrawRenderers(cullingResults, ref drawingSettings, ref filteringSettings);
    }

    cmd.ReleaseTemporaryRT(depthID);
    ctx.ExecuteCommandBuffer(cmd);
    CommandBufferPool.Release(cmd);
}
#

While I can see the draw call exist in the event list, the render target shows a blank screen.

Right now my Canvas is set to using the UI Camera as its target camera (Screen Space - Camera) and I am overriding the onCustomRender with this custom function I wrote.

#

The reason I figured I'd want to use onCustomRender is because I don't want any kind of post processing happening to the UI and internal render texture