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. Dismiss Notice

Enabling Depth-Textures in SceneView

Discussion in 'Scripting' started by a436t4ataf, Sep 22, 2019.

  1. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,873
    In 2019, I can't find how to enable Depth textures on SceneView in any of the docs. Searching the docs fails, searching google shows hacks (none of which work any more).

    All I could find was a post from @ArasP from 9 years ago promising that he was going to add this feature "soon": https://answers.unity.com/questions/10124/depth-buffer-materials-in-scene-view.html

    I'm guessing that the post-processing stack has made the hacks stop working? The obvious thing you'd expect to work ... does nothing:

    SceneView.currentDrawingSceneView.camera.depthTextureMode = DepthTextureMode.Depth;
     
  2. Samhayne

    Samhayne

    Joined:
    Jun 15, 2009
    Posts:
    44
    Also stumbling over this half a year later.

    This is really... untidy that the only way to enable depth textures in the SceneView is to have a (not necessarily needed) main tagged camera floating around somewhere with in the scene depth texture rendering enabled by script.

    Somehow the SceneView camera will only listen to this.

    D'oh! Unity! Please!
     
  3. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,873
    It seems that actually this has all been made "automatic" and that if you configure things appropriately it "just works, magic, hahahah good luck".

    A few things I discovered by trial and error (and with help from some Unity tech people who were at Unity last year):

    1. Orthographic cameras seem to mess up the depth buffer (actually they just redefine the values - but it makes some shaders appear to have no depth buffer, or others to have corurpt ones) - there are shader macros to handle this automatically for you, but you need to know they exist in order to use them :). *be especially careful you don't do what I did which is in one case had a camera temporarily set to orthogrpahic to debug one thing, and forgot to set it back, and didn't realise it would mess up so much stuff* :)

    2. the left-side Gizmos drop-down (has no name, its an icon of a picture-frame) has/had some weird bugs where if you disabled some things it would still enable depth-buffers when it wasn't supposed to - but only intermittently. I reported this, and I believe it's now been fixed (it was only some edge cases, IIRC)

    3. left-side Gizmos drop-down SHOULD BE what defines whether auto depth-buffer is being generated for Scene view. Off the top of my head ... if you turn on/off "Animated materials" I think that forces depth/no-depth ... although it might be one of the other options on there.

    TL;DR: current official design is that depth-buffer should always be on unless you specifically did somethign to turn it off (IIRC: it *might* depend on the shader compiler noticing that you are accessing the depth-buffer, but I think in practice they just have it always-on anyway now, because: why not?)

    ...and if that's not working for you, log a bug (is what Unity engineers told me at Unite :))
     
  4. CGDever

    CGDever

    Joined:
    Dec 17, 2014
    Posts:
    154
    Decades later I landed on this forum page.
    Sorry for bothering, bud has unity introduced the solution for this?
     
    Gawainying likes this.