Search Unity

Depth Shader/Depth Pass/Z-Depth

Discussion in 'Shaders' started by URAwesome, Apr 2, 2015.

  1. URAwesome

    URAwesome

    Joined:
    Sep 28, 2013
    Posts:
    23
    Hi all,

    I'm trying to locate a shader that would create an depth render effect used in animation and compositing software. Ideally the effect's range can be independant of camera distance. Needs to run on iOS. I'm not a coder myself. Any pointers much appreciated.

    Thank you.
     
  2. joelv

    joelv

    Unity Technologies

    Joined:
    Mar 20, 2015
    Posts:
    203
    Unity has the rendering of such a texture built in. You can set a flag on you camera to have the texture generated. http://docs.unity3d.com/ScriptReference/DepthTextureMode.html

    Code (CSharp):
    1. GetComponent<Camera>().depthTextureMode |= DepthTextureMode.Depth;
    You can then use _CameraDepthTexture in your shader to transform the depth rendered in whatever way you want.
     
  3. URAwesome

    URAwesome

    Joined:
    Sep 28, 2013
    Posts:
    23
    Hi there, thank you for the quick response. Unfortunately I'm not a coder, so don't know how to make the awesomeness of the above one line integrate with camera and shaders. Is there a tutorial you could point me towards? It's a very popular effect in visual fx - is there a possibility of getting this to an 'example' or tutorial page of Unity5. Thank you.
     
    Last edited: Apr 3, 2015