Search Unity

Access RenderTexture DepthBuffer

Discussion in 'Image Effects' started by Deleted User, Jul 7, 2017.

  1. Deleted User

    Deleted User

    Guest

    I've seen this question asked a lot, but have never found an answer that didn't say something like "Use _CameraDepthTexture in the shader" or have no answer at all.

    I'm trying to produce an effect like the occlusion culling in Fallout 2. If you look at the video, you'll see things that can block the player's view around the main character are culled in a spherical radius around the character.

    Now the question is, given a RenderTexture how do I access its depth buffer in a shader? _CameraDepthTexture will not work because I'm using a multi pass render technique.

    One of the renders is the "occluders" and therefor anything that can be masked out. The second one is the "masks" texture which is a sphere that fades out over a radius. Last, but not least the third one is the "default" layer which includes the characters and anything that cannot be masked out.

    I know I can pass RenderTextures via Material.SetTexture, but I have no clue how to read the depth information from that RenderTexture. tex2D will only give me the color information, which I need, but I also need the depth information.

    I'm really hoping I don't have to do something ridiculous like render the scene two times per layer. As that would be quite a lot of VRAM to use on a technique like this.

    Thanks in advance, Zac.
     
    Last edited by a moderator: Jul 11, 2017
  2. Deleted User

    Deleted User

    Guest

    Its been several days now, so I thought I'd do a bump. I still haven't found the answer as I've been busy with things, haha.