Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

DepthTexture isn't perfect for Andriod

Discussion in 'Shaders' started by liuyu, Jan 6, 2015.

  1. liuyu

    liuyu

    Joined:
    Oct 14, 2014
    Posts:
    28
    Hi, I write an postprocess:
    Code (CSharp):
    1. void OnEnable ()
    2. {
    3.         camera.depthTextureMode |= DepthTextureMode.Depth;
    4. }
    And in shader:

    Code (CSharp):
    1. float kDepth = UNITY_SAMPLE_DEPTH(tex2D(_CameraDepthTexture, kuv));//kViewDiruv));
    2.                 kDepth = Linear01Depth (kDepth);
    3.                 return float4(kDepth,kDepth,kDepth,1);
    And, the result is:


    Why there are so many striation? And how to resolve it?
    Thank you?
     
  2. jvo3dc

    jvo3dc

    Joined:
    Oct 11, 2013
    Posts:
    1,520
    I assume this is not the actual result on an Android device. The Unity preview can be quite pessimistic when it comes to the bit depth of depth buffers on mobile platforms.

    On the other side, you must realize that many mobile platforms use a TBDR (Tile Based Deferred Renderer). This means there is no full screen depth buffer available at all. I'm not sure whether this influences your current solution, but it might.

    So my advice would be to test on an actual device.

    (As far as I know, Unity can't simulate a TBDR right now, but it would be nice if it could.)
     
  3. liuyu

    liuyu

    Joined:
    Oct 14, 2014
    Posts:
    28
    The test phone is samsung note2. The picture is screen shot form the samsung note2. (Look the rightdown of the picture: Development Build.)
    Are there some settings for unity building?

    I'm only to show the depth, it's look like:
    The code is:
    Code (CSharp):
    1. //VS
    2. PX_T_outvs Vert_T(PX_T_invs i)
    3. {
    4.     PX_T_outvs o;
    5.  
    6.     o.pos = mul (UNITY_MATRIX_MVP, i.vertex);
    7.     o.texcoord = i.texcoord;
    8.  
    9.     return o;
    10. }
    11. fixed4 Frag_Tex( PX_T_outvs i ) : COLOR
    12. {
    13.     float depth = UNITY_SAMPLE_DEPTH(tex2D(_CameraDepthTexture, i.texcoord));
    14.     depth = Linear01Depth (depth);
    15.     return fixed4(depth,depth,depth,1);
    16. }
    But I use another phone(nexus 5), the depth texture is good. Is the graphic device of samsung note2 very poor to make the depth texture bad?
     
    Last edited: Jan 7, 2015
  4. jvo3dc

    jvo3dc

    Joined:
    Oct 11, 2013
    Posts:
    1,520
    Well, there are so many devices out there. I usually check gfxbench.com to find out relative performance and the chipsets used. That's the first step. So, I come to:

    Note 3: Adreno 305
    Nexus 5: Adreno 330

    The note 2 is not on there, but after some googling I found it has the Mali-400MP in there. I'd say there is a bit of a generation difference there. The Adreno 3xx series probably supports 24 bit depth, while the Mali-4xx series only goes to 16 bit depth. It'll take a bit more digging to make sure, but it's not uncommon for mobile GPU's to have less bits in the depth buffer. Only the latest generation seems to generally be on par with desktop GPU's in that area.

    There are publish settings for this, but I don't think that will help with the note 2. First thing to try would be to place the near and far clip plane more tightly around your scene to make more use out of the available depth buffer range.
     
  5. liuyu

    liuyu

    Joined:
    Oct 14, 2014
    Posts:
    28
    Thank you, jvo3dc, you let me know why the striation appear at samsung note2.
    So I think there need some codes to prohibit depth texture at Mali-400MP.

    Thank you very much.