Search Unity

Depth texture - Exclude other shaders? Performance thoughts?

Discussion in 'Shaders' started by Samhayne, May 26, 2020.

  1. Samhayne

    Samhayne

    Joined:
    Jun 15, 2009
    Posts:
    45
    Hello :),

    I'm battling around with depth textures for the first time.
    The well known approach to draw foam on water as it seems.

    But: What is not so well described and where google failed on me is the following:

    1) How worried should I be about mobile performance rendering that texture?
    If I should be worried - would it make more sense to use a replacement shader, only rendering the ground and every object touching the water to the depth texture?

    2) Using my main camera: How can I exclude an opaque shader from writing to the depthNormal texture?
    I got a cutout shader here (pretty basic, no fallback) and it (i.e also its transparent border) is writing to the depthNormal texture.
    This only seems to happens though for a depthNormal texture. For a pure depth texture it seems to be fine.
    I'm puzzled.
     
  2. Samhayne

    Samhayne

    Joined:
    Jun 15, 2009
    Posts:
    45
    Okay. One day later I can answer question 2) myself:

    This feedback posting provided the solution: https://shaderforge.userecho.com/communities/1/topics/896-proper-depth-depth-normal-rendering

    Internally Unity uses a replacement shader to create the depthNormal texture.
    As of today it's "Internal-DepthNormalsTexture.shader" from the builtin-shaders archive [Downloads->Builtin shaders].

    To make the cutout shader work with this it must
    a) have the following parameters:
    • _Maintex
    • _Cutoff
    • _Color
    b) Use the RenderType "TransparentCutout"


    My problem was that I didn't use that RenderType and our cutoff parameter had a different name.
    After adapting these two things our cutout sprites now render correctly to the depth texture (without the cutout border) and therefore don't need to be excluded.


    By the way:
    The pure depth texture seems to be created differently... the replacement depth shader mentioned in the linked posting doesn't exist in the archive any more.

    That's probably why I only ran into this problem with the depthNormals texture.