1
\$\begingroup\$

Using Unity's URP I've been trying to setup a scriptable render feature which will add a pass which draws objects on a certain layer to multiple render targets. Unfortunately, I am not able to get it to draw to the camera's depth buffer no matter what I do. According to the docs there is a way to specify a depth attachment along with color attachments. Looking at the source code, it seems that Unity will default to using BuiltinRenderTextureType.CameraTarget if no depth attachment is specified. Unfortunately, I think the actual usage is closed source so I don't know how Unity handles it.

One thing I noticed is that it seems it will only draw to the proper depth buffer if I set the render target to cameraColorTarget:

var rt = new RenderTargetIdentifier(renderingData.cameraData.renderer.cameraColorTarget, 0, CubemapFace.Unknown, -1);

ConfigureTarget(rt, m_CameraDepthTarget);
// Or also works:
ConfigureTarget(rt);

and setting it to anything else doesn't work. I'm drawing in the Exceute method using context.DrawRenderers.

What I'm wondering is if there is some way I can draw color to a different render target than camera's framebuffer, but still draw/test depth using default depth buffer? Without much resources and documentation on URP side of things I'm a bit lost on if/how it can be done at the point. Is it something that can be done in general? Or are depth buffers somehow tied to a render texture under the hood or something so it is not possible? But if that is the case, then it should still be possible using multiple render targets (MRT) since I can render to cameraColorTarget as well as my custom render target in a single pass (but unfortunately I've tried and doesn't seem to work for whatever reason).

\$\endgroup\$
1
  • \$\begingroup\$ Annoyingly I'm beginning to suspect that it's some issue regarding Unity's lack of documentation and stuff. I just noticed that it will actually work using MRT but only if all the color attachments are cameraColorTarget. I have two color targets, if I set the first but not the second or vice versa it doesn't work. Setting both of them and then it works. Unfortunately that is essentially useless. \$\endgroup\$
    – Buretto
    Oct 14, 2022 at 4:11

1 Answer 1

0
\$\begingroup\$

For some reason it works if you enable depth texture in the scriptable renderer asset.

I could not find an explanation for why it behaves like that though.

I don't intend to use the depth texture, and so it seems a bit wasteful and not the perfect solution as it adds a CopyDepth pass; but it is the only solution I know of at the moment.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .