Simplest way to get the pixel depth from Render Texture (CPU)?

485 views Asked by At

In my project I capture the scene to a RenderTexture and I want to be able to loop over those pixels to get the depth of each pixel.

I have so far tried to convert RenderTexture to Texture2D and loop over pixels that way, but as far as I know you can only get rgba pixel values, not depth.

I'm thinking that I would just have create a shader to show and then sample its color values the way I was doing before. But is there a simpler way? Thanks.

1

There are 1 answers

0
Kevin Spaghetti On

You can only get the RGBA values from the render result because the depth buffer is stored separately from the render target in which the result is drawn (because the depth buffer does not need to be stored after the render operation).
If you can't find a way to get the depth buffer into a RenderTexture then using a shader to copy the depth values into a texture might be the best solution.