I am working on an implementation of a custom graphics pipeline in URP that draws the game in several steps. The first step draws the scene using a black-and-white lit material, the second using a textured colored lit material, and the last combines the two dynamically according to some gameplay data that I pass to the GPU every frame.
I have set up the rendering with three cameras, two of which draw the scene into a render texture using their own universal render data object, and the last one samples the two render textures in a shader graph and produces the final color. The first two render data objects have a Render Objects render feature to override the materials on the objects in the scene to get the black-and-white and colored textures respectively.
Although I haven’t done extensive testing, this approach seems like it could cause some significant performance costs, and while testing on a weaker machine, I have noticed that the cameras can get desynchronized and the render textures used in the final combination shaders can be off by several pixels. On a higher end machine this approach seems to work well.
My question is: can I use render features to render the scene into textures with overridden materials instead of this multi-camera setup? The closest thing I’ve found is the Render Objects render feature, but I see no option to retarget it into a render texture. Is there example code somewhere that shows a render feature that does something similar? I’ve tried copying the code of the Render Objects into my project to try and tweak it, but it seems to use some internal code that is inaccessible.
I mean sure you can render to a separate texture using renderer features but it sounds a lot like you would do well really implementing this completely as from scratch as another pipeline in the core render loop, because it is so far off from the default URP setup.
When you use render objects features you draw anything you draw a second time (if you not remove those layers from the main / camera layermask. You might have circumvented that with your three camera setup but it’s easy to do mistakes there. Plus the render objects feature is in many ways incomplete when it comes to additional render pass (depth pre pass, depthNormal pass (rendering layers)).
3 cameras is a bad idea. Ideally you want only one camera. As you said desync issues, although I don’t see why, etc… and Unity will calculate culling for all 3 cameras. With a lot of objects that might be become noticable.
This page will probably help you a lot:
For getting a handle for the render target you use RenderingUtils.ReAllocateIfNeeded(ref colorTarget, colorDesc, name:settings.colorDestinationID);
Thanks for your reply. Yeah, the three camera setup did feel like a weird workaround.
That page you’ve linked looks really promising, I’ll look into it more.
I will also look into creating a custom render pipeline, although it look like quite an undertaking.