I have my old code for URP that will render meshes with a selected material using other camera matrices (the second camera is disabled, I use it to get the matrices). And now I need to do the same thing in HDRP, but looks like you can’t use this simple approach here. The result is all wrong, in URP I used a Shader Graph Material to render custom Depth, it just displays the distance to a Camera plane. HDRP version of this Shader Graph was used, of course.
For some reason when I render these meshes only one time, it somehow renders them with weird material that has color set to white. And it does not render the backfaces, even though I set the material to be double-sided. If I move the rendering code into Update, the result is black.
Something is wrong here, but there is no info about how I need to change the command buffer rendering approach when using HDRP.
Just tested the CustomPassUtils.RenderFromCamera but for some reason, it requires Camera to be enabled. Is there a way to render from the Camera view without enabling the Camera, only sending the essential matrices?
Note that the culling results of the main camera will be used, so if your disabled camera is completely in a different place looking in a different direction or whatever, it will render only stuff in its view that is also visible in the main camera.
You can use the disabled camera’s TryGetCullingParameters(out var cullingParams) and call ctx.renderContext.Cull(ref cullingParams).
My memory is slightly vague because I experimented with this a few months ago.
Here is some code where I do some prep work to render from a disabled camera with its own culling results.
I don’t know how correct it is, because I was also experimenting and struggling to get it to work at first.
BTW big gotcha, if you pass CustomPassContext around, do it by ref since it is a struct.
Thank you, I will try this method. And yes, my second cameras are in other places, I used them to get local Depth data for some custom effects. In URP I can spawn these effects with cameras in large numbers, because Cameras were disabled, of course. So, just staying to do the same thing in HDRP.
I was surprised that there are no methods to just render a mesh with given matrices to a render texture, I mean working ones because the standard approach with Command Buffer is not working.