Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Depth Textures support for Mobile (iOS/Android) platform

Discussion in 'Wish List' started by I am da bawss, Nov 7, 2011.

  1. I am da bawss

    I am da bawss

    Joined:
    Jun 2, 2011
    Posts:
    2,574




    In one of my previous post, it was discovered Depth Texture is not currently supported for mobile platforms (iOS/Android). It seems many image effects (Depth of Field, Edge Detect Effect Normals, Global Fog, Color Correction Curves, Crease, Sun Shafts, Tilt Shift) depend on the Depth Texture support, which is currently disabled. Which means its support for mobile platform is critical.


    Depth of Field



    Edge Detect Normal


    Global Fog


    Crease


    Sun Shafts


    Tilt Shift





    dEngine iOS


    http://fabiensanglard.net/dEngine/index.php
    http://fabiensanglard.net/dEngineSourceCodeRelease/


    Maratis 3D iOS




    It should be noted that Apple supports GL_OES_depth_texture since iOS 4.1 - which has allow quite a few indie developers to take advantage of and made real-time shadows on iOS successfully. So Depth Texture support is critical for a whole hosts of image effects and dynamic shadow system on mobile platform.
     
    Last edited: Nov 11, 2011
  2. I am da bawss

    I am da bawss

    Joined:
    Jun 2, 2011
    Posts:
    2,574
    So nobody believe depth texture support is needed?
     
  3. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    has nothing to do with 'believe'
    UT knows its there and UT knows that for platform consistency it should be addad asap.
    If we are now meant to start requesting such things the concept of crossplatform is obviously no longer 'active'
     
  4. I am da bawss

    I am da bawss

    Joined:
    Jun 2, 2011
    Posts:
    2,574
    What are you saying? Are you saying that if UT is to enable Depth Texture feature it will break the cross platform consistency?! HUH?
    Isn't the whole point of having Depth Texture support means every platform now will finally have all the above effects supported??
     
  5. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Clearly that's the opposite of what he's saying. Read it again: "UT knows that for platform consistency it should be addad asap".

    --Eric
     
  6. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Right. What I'm saying is that we should not be needed to request features that are just meant to be there and offered by the hardware without 'black magic' if Unity is meant to be accepted as a crossplatform engine.
     
  7. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    I agree.
     
  8. I am da bawss

    I am da bawss

    Joined:
    Jun 2, 2011
    Posts:
    2,574
    Sorry, I have some difficulties understanding dreamora's English.
    I get the gist of what he meant in majority of his posts, but many times it just confused me.
    I know English is not your first language dreamora, but neither is mine. I guess what I am saying is it can cause misunderstanding when two non-native speakers are conversing in foreign language.



    But yeh I know, but it is NOT THERE. That's why I am requesting it. SO WHO'S WITH ME??!
     
    Last edited: Nov 23, 2011
  9. lovelost

    lovelost

    Joined:
    Nov 21, 2011
    Posts:
    6
    Is this a workaround?

    Taking DoF as an example, the error (trying to add it to a camera on an iOS Pro project) is:

    The image effect Main Camera (DepthOfField34)is not supported on this platform!
    UnityEngine.Debug:LogError(Object)
    PostEffectsBase:NotSupported() (at Assets/Standard Assets/Image Effects (Pro Only)/PostEffectsBase.js:85)
    PostEffectsBase:CheckSupport(Boolean) (at Assets/Standard Assets/Image Effects (Pro Only)/PostEffectsBase.js:65)
    DepthOfField34:Start() (at Assets/Standard Assets/Image Effects (Pro Only)/DepthOfField34.js:93)


    So I nixed the CheckSupport() function in PostEffectsBase.js to simply return true on being called. And, with a quick test, it looks like a test scene does indeed have DoF in it on my iPad 2. Actually I don't have a great depth scene to test so am going on the basis that the whole frame is blurred as it is in the game editor window.
     
  10. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Oh so they implemented it and didn't fix that stupid check? Not really ...??
     
  11. lovelost

    lovelost

    Joined:
    Nov 21, 2011
    Posts:
    6
    Don't take my word for it just yet. I only blocked the roadblock test itself, so it will be up to anyone who knows how to use some of these features to verify whether things like DoF will work...
     
  12. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    will see if I find time to test it tonight. Would surely be interesting to know.
     
  13. lovelost

    lovelost

    Joined:
    Nov 21, 2011
    Posts:
    6
    Just done a quick test and I may have kind-of got it to work. If you look at the attached sample scene image of three spheres on a plane, one central, one really close, one very far away and much bigger. Used the joystickThumb texture on them from the standard mobile assets(!). Now I switched to desktop build and got the focus how I wanted it -- on the middle sphere. Then switched back to iOS and immediately ran a build run. This image is directly off my iPad 2:



    Note that the game pane within Unity doesn't show the depth correctly when in iOS mode.

    This is only my first test but may be promising...
     
  14. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    hmm ... I would have to check if the check on mobile really returns false then ... who knows, perhaps its just unitys in-editor emulation thats totally out of date?
     
  15. aubergine

    aubergine

    Joined:
    Sep 12, 2009
    Posts:
    2,878
    I have no idea about iOS, but i know one thing for sure is you can compose your own depth texture with just a single replacement vertex shader. So, why dont you people write your own depth textures and own suitable shaders to use it?

    iOS supports rendertextures and replacement shaders right?
     
  16. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    render textures yes but render textures with depth modes report 'unsupported' (render texture without depth mode naturally with a suitable shader is still usable for some effects but some are just impossible if you have to use a prebaked one) but as we see above, if we just ignore that check it at least seems to work.
     
  17. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    So Unity, about that fast Mobile/DOF shader one of you guys over at the HQ is dying to write... let yourselves be better than UDK!
     
  18. aubergine

    aubergine

    Joined:
    Sep 12, 2009
    Posts:
    2,878
    I can do the unity builtin dof or such kind shaders without using depth format but with an argb32 or argbhalf, so virtually 99% of what is needed should be doable. Only needs custom image effects to use the format though.
     
  19. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Right.
    But it depends on what you want to achieve. If you wanted to do something that relied on the real depth (motion blur for example) then you can not fake around it, you have to replace the whole effect with something else that does not rely on the currently rendered scene state (or you have to 'estimate it' procedurally from the rendered backbuffer color data)
     
  20. Cameron_SM

    Cameron_SM

    Joined:
    Jun 1, 2009
    Posts:
    915
    What Aubergine is saying here is that you can use replacement shaders to draw your own depth texture into the RBGA channels of a color render texture. You don't need anything to specifically "support" depth, programmable vertex shaders allow you calculate it yourself. Simply render all opaque geometry and pass pos.zw to fragment so it's interpolated linearly then do the perspective divide pos.z/pos.w == standard unity 32bit non-linear depth float for that pixel. Encode for ARGB32 and you're done.

    From there modifying the built-in image effects to use your custom depth texture instead of the built in unity depth texture auto-generated by the camera ought to be fairly trivial. In fact, in forward rendering mode this is exactly what Unity does internally, it uses a replacement shader to re-render all RenderType=opaque geometry as described above and outputs the depth value calculated in that shader to the _CameraDepth rendertexture.
     
    Last edited: Dec 16, 2011
  21. Muckel

    Muckel

    Joined:
    Mar 26, 2009
    Posts:
    471
    ....any news on this ?
    thxxxx
    would love to use Dof on Mobile....
     
  22. kurylo3d

    kurylo3d

    Joined:
    Nov 7, 2009
    Posts:
    1,123
    Yea i truely would love to utilize the light shafts and depth of field on mobile.
     
  23. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Drawing your own depth texture when the camera provides it seems like stupidity to me though.
     
  24. Rob_Fireproof

    Rob_Fireproof

    Joined:
    Jan 16, 2012
    Posts:
    9
    Just to add to what's already been said, crippling CheckSupport in PostEffectsBase.js does make DoF work on iPad2, although I also had to comment out the lines where the component was disabled (search for "enabled = false" in the same file). Otherwise even though the iPad could do it, the Mac I was building from couldn't, and disabled the component when it opened the scene.

    Oh, and it (fairly predictable) destroys the framerate on iPad 2...

    Looks very pretty though :)
     
  25. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Got to be a fast approximation though. Windwaker on gamecube (hardware that isn't as good as ipad2) - does it very quickly. But it is strangely limited. I think probably, camera slicing or something.

    Any tips on how this could be done on mobile in a very quick way? I think many of us would love to try it out.
     
  26. Nikolai-Sander

    Nikolai-Sander

    Joined:
    Feb 2, 2011
    Posts:
    12
    You don't even have to write you own shader but you can just use the built-in one. If you attach this script to your camera you can make any post process effect work that uses the depth/normal texture:

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class CreateDepthNormals : MonoBehaviour
    6. {
    7.     RenderTexture depthNormalTexture;  
    8.     Camera theCam;
    9.     GameObject shaderCamera;
    10.    
    11.    
    12.     void OnDisable()
    13.     {                  
    14.         if(shaderCamera != null)
    15.             DestroyImmediate (shaderCamera);
    16.        
    17.         if (depthNormalTexture != null) {
    18.             RenderTexture.ReleaseTemporary (depthNormalTexture);
    19.             depthNormalTexture = null;
    20.         }
    21.        
    22.     }
    23.     void OnPreRender()
    24.     {
    25.         if (!enabled || !gameObject.active)
    26.             return;
    27.  
    28.         if(theCam == null)
    29.             theCam = this.GetComponent<Camera>();
    30.        
    31.         if(depthNormalTexture == null)         
    32.             depthNormalTexture = RenderTexture.GetTemporary((int)theCam.pixelWidth, (int)theCam.pixelHeight, 16);              
    33.                        
    34.         if (!shaderCamera) {           
    35.             shaderCamera = new GameObject("DepthNormalCamera", typeof(Camera));
    36.             shaderCamera.camera.enabled = false;
    37.             shaderCamera.hideFlags = HideFlags.HideAndDontSave;
    38.         }
    39.        
    40.         Camera cam = shaderCamera.camera;
    41.         cam.CopyFrom (theCam);
    42.         cam.backgroundColor = new Color(0,0,0,0);
    43.         cam.clearFlags = CameraClearFlags.SolidColor;
    44.         cam.targetTexture = depthNormalTexture;    
    45.         cam.depth = -2;
    46.         Shader s = Shader.Find("Hidden/Camera-DepthNormalTexture");    
    47.         cam.RenderWithShader (s, "");      
    48.         Shader.SetGlobalTexture("_CameraDepthNormalsTexture",depthNormalTexture);
    49.     }
    50.        
    51.     // Update is called once per frame
    52.     void Update () {
    53.    
    54.     }
    55. }
     
    Miguel-Ferreira likes this.
  27. jister

    jister

    Joined:
    Oct 9, 2009
    Posts:
    1,749
    arg unity Fix this allready will you!!!!
     
  28. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,521
  29. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    0. That game didn't have shadows as it did not even have 3D. Thats pure cpu rendering ;)
    Also casting shadows from this kind of objects is a thing you can easily do even with unity as projectors work fine here

    1. Older games and the first to have it on mobile relied on Stencil Buffer shadows. Stencils are a technology unity does not support in any form nor use to my knowledge and thats not gonna change as Stencils are a thing of the past and have been for a while. In addition they couldn't be exposed to shaderlab as you need low level access to use them, another reason why UT likely never approached it

    2. I would assume that Unity 4 will support them. ipad2+ , iphone 4S+ and the current generation of android high ends finally can make use of shadows.

    As for depth textures: There is a rumor (didn't verify it yet) that they actually work with unity on iOS at least yet that Unitys editor 'fake opengl es' renderer pretends that it isn't possible or more correctly: fails to return true on the 'is supported' function while it works otherwise.
     
    Last edited: Apr 29, 2012
  30. poolts

    poolts

    Joined:
    Aug 9, 2012
    Posts:
    113
    Does anyone have any more information on this? Are shaders that require depth information (i.e. sun shafts) actually supported, but this check just returns false regardless?

    When I commented out the check, the shader did work within the editor, but was flickering, weird. Anybody any information, if these shaders are now supported on devices 4S and above?
     
  31. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,364
    Unity support rendertextures since v3.0. Prior to v4.0 (which is the official version that support automatic depth textures generation for mobile) you had to construct your own depth buffer to generate depth textures (which was quite easy btw). The big problem is making something like this runs on today's mobile hardware. I still believe current mobile hardware isn't ready for heavy post process. You have to be very careful and approximate your desired effect at the cost of being sometimes weird or unnatural.
    Shadows are hugely needed yes but they are also hugely slow on mobile hardware. Your scene have to be drawn multiple times, there's a lot of heavy operations on pixels that must be done, your drawcall will double for each light casting shadows. If shadowgun had shadows with their current scenes setup the requirement to play such a game will be iPad3 and iPhone5 (and they will still look blocky cause even such devices can't afford high res shadowmaps). There's no magic trick here, shadows are heavy as simple as that. :D

    The fastest shadows technique that you can implement in your game is simply "no shadows at all". :rolleyes:
     
    Last edited: Dec 30, 2012