2
\$\begingroup\$

I can access the same with duplicating the cameras AND the rendertextures, but that seems like a lot of overkill of just getting the depth buffer.

I don't need a very precise depth buffer, so it can easily be put in the alpha channel.

\$\endgroup\$
6
  • \$\begingroup\$ It sounds like you answered your own question: "put depth in the alpha channel". What happens when you try this? \$\endgroup\$
    – DMGregory
    Commented Jun 7, 2023 at 23:05
  • \$\begingroup\$ Hi @DMGregory, I only see one "depth" setting with ColorFormat on the RenderTexture - and that is called Auto Depth and puts it in the color channels. So then it doesn't write any colors anymore. \$\endgroup\$
    – Dirk Boer
    Commented Jun 8, 2023 at 12:03
  • \$\begingroup\$ So write a shader that puts depth where you want it while rendering the colour components, or use a post process to copy the depth texture into the alpha channel? What step do you need help with? \$\endgroup\$
    – DMGregory
    Commented Jun 8, 2023 at 12:23
  • \$\begingroup\$ if I need both the depth and the color channels then I need to have two cameras (camera can only write to one rendertexture) and two render passes. I will take a look at postprocesses (but I am still using the legacy pipeline) \$\endgroup\$
    – Dirk Boer
    Commented Jun 8, 2023 at 12:56
  • 2
    \$\begingroup\$ No, Unity also writes a specially-named depth texture that you can read from while the camera is rendering (and I think in OnRenderImage just after it's finished). Here's an older presentation about it that describes how to use it in the legacy pipeline. \$\endgroup\$
    – DMGregory
    Commented Jun 8, 2023 at 13:04

0

You must log in to answer this question.

Browse other questions tagged .