Custom renderer feature won't work for me

Hi there,

I’m trying to create a URP custom renderer feature, but I’m having some difficulties… I’m not sure if I’m doing something wrong, or the sample I used as a starting point is wrong, or if there is a bug in Unity. My starting point was the sample here: Unity - Manual: Example of a complete Scriptable Renderer Feature in URP. In fact, I’m not much further than the starting point - I just wanted to get that working before changing anything. But when I apply the renderer feature, I get a black screen as a result. I’ve looked at what is happening in the frame debugger, and it seems to me that the vertical pass is sampling from the wrong texture:

It is writing to the texture I would expect though (the same one it’s reading from, for reasons I don’t understand):

image

To give some context without having to go through the whole page above, the pass is set up like this:

...
        TextureHandle srcCamColor = resourceData.activeColorTexture;
        TextureHandle dst = UniversalRenderer.CreateRenderGraphTexture(renderGraph,
            blurTextureDescriptor, k_BlurTextureName, false);

        // Update the blur settings in the material
        UpdateBlurSettings();

        // This check is to avoid an error from the material preview in the scene
        if (!srcCamColor.IsValid() || !dst.IsValid())
            return;
        
        // The AddBlitPass method adds a vertical blur render graph pass that blits from the source texture (camera color in this case) to the destination texture using the first shader pass (the shader pass is defined in the last parameter).
        RenderGraphUtils.BlitMaterialParameters paraVertical = new(srcCamColor, dst, material, 0);
        renderGraph.AddBlitPass(paraVertical, k_VerticalPassName);

So ‘srcCamColor’ is passed as the source, and that comes from resourceData.activeColorTexture (which I think should be the camera target texture). It certainly looks like the source and destination should be different textures. Trying to figure out what is going wrong, I changed it to to blit to and from ‘srcCamColor’ texture like this:

...
        RenderGraphUtils.BlitMaterialParameters paraVertical = new(srcCamColor, srcCamColor, material, 0);
        renderGraph.AddBlitPass(paraVertical, k_VerticalPassName);

As might be expected the RenderTarget now becomes ‘_CameraTargetAttachmentA’. The _BlitTexture remains ‘_BlurTexture…’ as before though. (For reference, I actually only made this change because the following change on it’s own made both passes redundant, I think, as they no longer show up in the Frame Debugger).

What really surprised me though is if I comment out the horizontal pass that follows the vertical pass:

        // RenderGraphUtils.BlitMaterialParameters paraHorizontal = new(dst, srcCamColor, material, 1);
        // renderGraph.AddBlitPass(paraHorizontal, k_HorizontalPassName);

Now, the _BlitTexture passed to the vertical pass is good!

So can anyone help advise what is going on here? Is the sample incorrect? Am I doing something wrong (I’ve not much expertise on the rendering side of things, really)? Or is this a bug? I’m using 6000.0.20f1 for reference. Any help greatly appreciated!

Also, if anyone has a working implementation of a renderer feature - especially one that requires an intermediate buffer like this one - that would be very helpful, as I couldn’t find much by googling.

Kind regards,

  Andy

The sample from the doc page works correctly.
You can find a range of samples in the RenderGraph package sample that you can install through the package manager (see here).

Hi again,

Thanks for your reply, @AljoshaD. I don’t see a sample provided that does two ‘AddBitPass’ calls in order to render first to a temporary texture and then back to the main buffer, but thanks for the reference anyway - I had missed this resource, and maybe I can find some other useful stuff in there. Perhaps the ‘blur’ from the doc page could be added there?

That said… I still can’t get it to work. I tried in a completely fresh project, using the URP 3d template as a starting point in 6000.0.20f1 (have also tried on 6000.0.14f1 for the record). I then:

  • added a red cube to my scene (which shows up in my game view along with the skybox)
  • added the three full scripts + shader from the page (BlurRendererFeature, BlurRenderPass, CustomVolumeComponent, BlurShader) copy-pasted directly with no changes into.
  • I checked that MSAA was disabled as described on the page.
  • I went to Settings/PC_Renderer and added the BlurRendererFeature there, and configured it to use the BlurShader.

I then see exactly the same behaviour I saw in my own project - the game view then goes black whenever the added renderer feature is enabled, and the frame debugger suggests that the vertical pass is being passed its temporary texture (_BlurTexture) both as its _BlitTexture and as its RenderTarget.

Am I missing something crucial here? I have a sneaking suspicion (well, ChatGPT does if I’m honest) it might be related to textures being reused in the pipeline, or possibly to the “Intermediate texture” setting somehow (though I’ve tried both settings for that without luck). Or maybe there’s some other setting I need to pay attention to? When you say the sample from the doc page works, do you mean you have tested it successfully in a recent version of Unity? Or is it that it used to work and you assume it still does / should?

If you have tested successfully ina recent version, could you share which version, and if possible share the set up steps you use? Or better yet, maybe share a project where you have it working?

I will investigate if I can adapt one of the other samples (e.g., the ‘BlitAndSwapColor’ feature) to work with a 2nd pass using a separate intermediate texture (as I can at least get that sample to work).

Thanks in any case for your reply. Any further help will be much appreciated.

Kind regards,

 Andy

PS I’ve attached my broken repro project, in it is of any use figuring out what is going on.

RenderGraphSample.zip (437.9 KB)

BlurRendererFeature.cs (5.4 KB)
BlurShader.shader (2.6 KB)
This is the exact doc sample code, but made the shader field public. Set the shader on the render feature.
and turn on the blur on the custom volume property, add it on your global volume.

I tested with our master branch, so 23f1, which is not available yet.

there might actually be a bug that is solved in 21f1 with using the blit pass twice Fixed Render Graph Blit utils error when using multiple times in succ… · Unity-Technologies/Graphics@93c3d34 · GitHub

Ah, yes indeed, that seems to have been it! I updated to .21f, and now it works fine. Thanks very much for your help! Kind regards,

Andy

Well it doesn’t work anymore:

1 Like