Search Unity

How to make the camera render depth textures from scripts

Discussion in 'General Graphics' started by konsnos, Jan 26, 2015.

  1. konsnos

    konsnos

    Joined:
    Feb 13, 2012
    Posts:
    121
    Hey all,

    I was reading the manual about the Soft Particles and as the title sais I read that I can make the camera render depth textures from scripts. My question is how can I do that? I can't seem to find any help on the internet or I'm searching with the wrong keywords.

    Also I've tried the Deferred Lightning to make use of Soft particles, and although Lightning was better I noticed some problems with World Space Canvas which at random times comes on top of the particles or behind them, having a blink-like effect. I also know that this is heavier than Forward Lightning. Is it heavier than camera depth textures too or just the same?

    Bonus question: Which graphics cards started supporting Deferred Lighting?

    Thanks for reading. I hope someone can help.
     
  2. brianasu

    brianasu

    Joined:
    Mar 9, 2010
    Posts:
    369
    http://docs.unity3d.com/ScriptReference/Camera-depthTextureMode.html

    In the script you do something like yourcamera.depthTextureMode = DepthTextureMode.Depth

    Then in your shader add sampler2D _CameraDepthTexture

    then you have access to a depth texture.

    Deferred lighting automatically renders a depth + normals texture so you can access sampler2D _CameraDepthNormalsTexture. There is no extra cost in deferred mode to get that texture but in forward it has render an additional depth pass.

    Not sure about the UI problems it might be the shader. Deferred is heavier on gpu memory but performance wise it's better with more smaller lights. Deferred performance is based on fillrate.

    I think all cards that support dx9 and multi render targets should support deferred. I remember implementing it 6-7 years ago so most cards should support it.
     
    konsnos likes this.