Search Unity

Rendering a Depth Texture by creating a RenderTexture of type DEPTH - supported?

Discussion in 'General Graphics' started by sebj, Aug 16, 2017.

  1. sebj

    sebj

    Joined:
    Dec 4, 2013
    Posts:
    70
    Hi,

    I want to create a set of depth textures that can be passed to a shader (so using, _CameraDepthTexture is not possible). I have found that if I pass DEPTH as a RenderTexture type, and set it as a render target, that Unity will render a depth pass using the inbuilt functionality, and that I can bind the resulting texture(s) to other shaders.

    I have used RenderDoc to verify that 1. Unity is only creating the depth buffer (because that's the only one bound in the call that does the depth pass), and 2. It's the inbuilt functionality that runs, because encoding of the depth in the buffer is *not* what my replacement shader uses.

    This is good! I like this functionality very much!

    My question is, is this behaviour by design? Is it part of the API? And can we rely on it in future versions?

    I am concerned because there is no mention of this behaviour in the documentation of the format itself, or the cameras depth texture. Further this thread is quite recent and contains no mention of this approach, despite the posters clearly wanting one like it.

    This is in a project using Unity 5.5.3.

    Sj