How to render everything with a replacement shader... with HDRP?

I have a complicated scene with lots of different objects in it. Each object can consist of a hierarchy of multiple sub-objects. Each sub-object can have a mesh with multiple and varied materials on it. Each material could use one of many different shaders. etc.

What I need to be able to do is:-

Render my main camera as normal, but also have an additional camera through which I render all the objects again, however instead of their usual Lit/PBR shaders I simply want to render (for example) all cars blue, all buildings red, all people yellow, all badgers magenta, etc. (completely unlit - I need the final RGB values to be accurate and consistent).

With no support for Camera.SetReplacementShader in HDRP/LWRP, I must admit I’m stumped as to how I would achieve this. Does anybody have any helpful suggestions? Bonus points if it also works with Shader Graph shaders as well…

Thanks.

I’d also like to know if that’s possible. Did you get any info on this in the meantime?

I too would love an answer to this…

1 Like

In URP/HDRP you can use scriptable render pass with one pass for each color.
And yeah, lack of ReplacementShader this is a very big limitation of SRP.

1 Like

You can find more info about extending the Universal Render Pipeline (the renamed LDRP) in this presentation and check out these custom rendering examples.

1 Like

The official demos in GitHub - Unity-Technologies/UniversalRenderingExamples: This project contains a collection of Custom Renderer examples. This will be updated as we refine the feature and add more options. demonstrates how this problem is solved by using OverrideMateril instead of ShaderReplacement

@Ggz91 I downloaded the examples but am having trouble seeing where the equivalent of ShaderReplacement is used. The ScriptableRenderPipelines have been hard for me to get into overall, so perhaps I’m missing something basic?

Or maybe an easier question: Where do I create an OverrideMaterial, is that doable in the editor, in C#, or both? And how do I use it?

Is it possible to do this every frame, as if I was doing camera’s RenderWithShader(…) method, without significant performance hit? (I just want to render a black and white mask of the scene, so the shaders would be super simple)

1 Like

@ModLunar
It can be done like so (tested with URP 7.3.1):

  • Create a new URP renderer asset (right-click somewhere in the Project view, then select Create → Rendering → Universal Render Pipeline → Forward Renderer), name it, lets say, CameraReplacementRenderer.
  • Click on the CameraReplacementRenderer asset to edit its properties
  • Change filtering: Opaque Layer Mask: None, Transparent Layer Mask: None. This is to disable normal camera rendering (we only want the render features to do work, without this we would render everything twice)
  • Add “Render Objects (Experimental)” Render Feature
  • On “Render Objects (Experimental)”
  • Set layers you want it to render
  • Set Overrides → Material to a material that’s using your replacement shader
  • Add CameraReplacementRenderer to your URP Render Pipeline Asset
  • Set your camera to use CameraReplacementRenderer

Hope this helps.

14 Likes

i could only get this to work when I set opaque layer mask and transparent layer mask to everything

If you want to override specific object materila. How do you do it?

I have this problem too, did you solve it?

This does not seem to grab the original object shader variables like color or emission properties though, just applies a shader but does not keep the original scene information.

Or i miss something ?

Thanks

ReplacementShader for SRP has landed in 2022.2 Replacement for Camera.Render/Camera.RenderWithShader - Unity Engine - Unity Discussions

2 Likes

Hi, thanks for the heads up, that is great news :slight_smile:

Will this system retain the original materials variables like in the Standard Pipeline, so can do operations based on the item color - emission etc values of the normal material ?

Also is this version available to install from the Hub ?

Thanks

Wow, just in time, this will be a game changer for my project!

1 Like

I can’t seem to find these setting for HDRP.

Same, is there anything for HDRP side ?