Search Unity

Mobile Forward Depth Pass Question, IOS.

Discussion in 'Image Effects' started by FranFndz, Oct 31, 2018.

  1. FranFndz

    FranFndz

    Joined:
    Sep 20, 2018
    Posts:
    178
    Hi,

    Im writing a DoF for Mobile, I got it to work 80 fps using Snapdragon 820.
    My question is,
    If I enable the camera DepthPass as;
    Camera.main.depthTextureMode = DepthTextureMode.Depth;

    What unity do is render all my mesh one more time in the Depth Pass.
    If I use shadow unity render all my mesh again for the shadow Pass.
    Finally Unity render all again using the RGB color.

    3 Pass. Not good for mobile at all.

    Can some one confirm this ? In forward render using Depth Pass means render all mesh agains and duplicate all the draw calls?

    My solution is write in the alpha channel the Depth using the camera and vertex position. So now I have only One Pass for the DoF.

    The issue is:
    When I look Snapdragon Profiler my app have 3 Texture, The main BLIT RGBA (A using the Depth), Stencil Texture and Depth Texture (Empty).
    Why Unity still create a Depth Texture if I setup my camera as
    Camera.main.depthTextureMode = DepthTextureMode.None;
    ??

    And this is the big question, when I look inside the XCODE, Unity is creating the Depth Texture and I can see the pass, but at the en the Depth Texture get Clean (Black). Xcode also show me that the Depth Texture is being create only in one Pass (Not rendering the mesh again).

    So is strange, Unity Frame Debugger show one Depth Texture completely Black, SnapDragon show the same, one texture Black.

    Xcode show one Depth Texture correctly but at the last call it get Clean.

    Whats is de deal? IOS make a free Depth Texture for me? And why it get clean?
     
  2. FranFndz

    FranFndz

    Joined:
    Sep 20, 2018
    Posts:
    178
    Wait,

    I just check Snapdragon and Android also create Depth Texture for free.
    Camera is set to;
    Camera.main.depthTextureMode = DepthTextureMode.None;

    And only One Draw per mesh, but again it get clean at the end.

     
  3. FranFndz

    FranFndz

    Joined:
    Sep 20, 2018
    Posts:
    178
    Finally I did it!


    Camera set to depth render = None;
    No strange second Depth Pass in unity Frame debugger.
    Using simple unlit shader with no Fallback or Shadow.
    Not saving the Depth in the Alpha Buffer of the RGBA (calculating the vertex as before).

    Taking the depth texture created by default as I see inside Xcode and Snapdragon.

    More faster than before! And I also have a Alpha buffer for other effect :D

     
  4. FranFndz

    FranFndz

    Joined:
    Sep 20, 2018
    Posts:
    178
    Tried mobile and all look good, faster than before.

    I just don't get why Unity make one more DepthPass in Forward if you have any shader that fall on shadow?
    And why Unity create a Depth Texture even if you do not turn it on ?
    Why GPU Profiler always show Depth Texture even if in Unity you have all turned off?

    Anyway, good I can use that texture the GPU is making, save me one pass and memory.
     
  5. FranFndz

    FranFndz

    Joined:
    Sep 20, 2018
    Posts:
    178
    Last Post,

    Turn OFF depth texture in Script/
    Turn ON unity Setting Disable Depth/

    Check Xcode and Snapdragon, Depth Texture still there.
    I will test it now in multiple devices to see if all GPU make this @Free@ depth texture in forward mobile.
    :D
     
    JoeStrout likes this.
  6. GoGoGadget

    GoGoGadget

    Joined:
    Sep 23, 2013
    Posts:
    864
    Would be very surprised if this was reliable on all mobile GPUs - how are you reading from the native depth texture in your Unity shader?
     
  7. resetme

    resetme

    Joined:
    Jun 27, 2012
    Posts:
    204
    this is my home account.

    It work from nexus 5, opengl 2 and beyound. we have around 20 QA tester with many android devices. Not an issue until now.

    As i have free alpha buffer im doing fake HDR bloom with DoF. around 90 fps in SO-04 Performance (that cellphone have awful CPU but good GPU , snapdragon 820).

    I dont have the code here but was something like;
    not using RenderImage or CommandBuffer (AWAYS slower when profiling in Snapdragon, Mali, Xcode). CommandBuffer is fast but OnPostRender is a littler faster.

    Cameradepth NONE;

    OnPostRender()
    rendertexture color = color.buffer:
    rendertexture depth = depth.buffer;

    camera.targetbuffer = color, depth;

    SetTexture(shaderID, color);
    SetTexture(shaderID, depth)
    SetTexure(shaderID, DOF) <- Using Dual Filtering as ARM guide recommend, faster and nice soft blurry
    blit 2 time down 2 times up;
    final blit.

    inside shader Get the Depth NOT using the unity manual code, that one dont work or it will activate the second pass with fallback.

    instead use;
    SAMPLE_DEPTH_TEXTURE(depth, UV);
    then
    Linear01Depth()
     
    GoGoGadget likes this.
  8. FranFndz

    FranFndz

    Joined:
    Sep 20, 2018
    Posts:
    178
    Up to date, this Native Depth Buffer does not work on Nexus 6 in OpenGl 3.0.
    OpenGl 2.0 is OK!

    We are using it on old devices like snapdragon 801, also we delete unity Fog, and using the Native Depth as Fog (remove the sky box write mask to work better).
    Also doing an invert depth pass for some Bloom effect.
    Fast 60fps in most android devices we tested.
     
  9. joshuacwilde

    joshuacwilde

    Joined:
    Feb 4, 2018
    Posts:
    731
    @FranFndz, I was looking at Xcode the other day and noticed this as well. But how did you end up getting the depth texture readable as a texture in Unity? Any help would be much appreciated!!