Camera.RenderWithShader in URP

For performance, I want to be able to replace the shader on all materials in use with Default/Unlit, as a runtime toggle.

This was previously easy using Camera.RenderWithShader.

With URP I can’t figure out any way to do something similar. ScriptableRenderPass seems to for add passes to add more things to the screen, or update what was already rendered, such as adding lens flare (How to create a custom Renderer Feature | Universal RP | 12.1.12).

After reading a bit about Camera.RenderWithShader, it sounds like it was also intended to be use as more of a modification to the main camera’s visuals. They mention “Heat Vision” and it being applied to another camera which you can enable. This essentially what URP’s render features allow you to do, except you can apply 1 material to the final render. It doesn’t sound much less efficient, shouldn’t it just be one extra pass?

Reading URP’s render feature examples it doesn’t feel like this is something you can do, care to point me in the right direction?

Lack of easy replacement shaders is one of the main reasons I’m not considering moving to URP.

I haven’t used this myself, but was curious to see if there was a defined way of rendering a pass for a single camera only. Looks like the official method is to use the API mentioned in this thread to execute a RenderPass on your target camera:
Is there any way to do a single Camera.Render() with URP? - Unity Forum

In your custom RenderPass, you should then be able to use DrawRenderers with an override material defined in the DrawSettings param to replace the rendering of specific shader types / filtered objects etc.

Thanks, while it’s good that it’s maybe doable, that sounds like too much work to replace 3 lines of code and for no real benefit in my case at least.

AFAIK you use render layers which are new to URP. Each Mesh Renderer now has a Render Layer tag for it to control if it’s a part of the render feature pass. So you can apply the feature to your entire screen, then opt certain things in or out.

https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal@16.0/manual/features/rendering-layers.html

While that seems cool (thanks for the link), I don’t see it as quite equivalent? Render feature pass seems like a post processing thing, while what I really want is to renderer everything with a custom shader.

what’s the difference in the end if all the objects you want to do the replacement on get the treatment?

Do they? If I want to do a bunch of stuff based on world position, can I just calculate it in the vertex shader, or is it something that I need to reconstruct from depth and normals in a render pass?

A Render Feature can be used to draw with a replacement shader. You can configure your Renderer with this RF and use an asset based workflow to set up your rendering.

These are great learning resources