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…
You can find more info about extending the Universal Render Pipeline (the renamed LDRP) in this presentation and check out these custom rendering examples.
@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)
@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)
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.
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 ?