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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Rendering Depth in Vert/Frag Shader

Discussion in 'Shaders' started by Flailer, Dec 7, 2015.

  1. Flailer

    Flailer

    Joined:
    Apr 1, 2014
    Posts:
    66
    After looking through the following posts and attempting the examples.

    http://forum.unity3d.com/threads/writing-depth-value-in-fragment-program.66153/
    http://forum.unity3d.com/threads/render-depth-distance.272979/
    http://docs.unity3d.com/Manual/SL-DepthTextures.html

    All that actually seems to write to the depth texture in Unity is setting Tags { "LightMode" = "ShadowCaster" }

    I'm confused. Does anyone around have some knowledge as to how this works now?

    The first post seems to imply that I can pretty much write whatever I want to the depth buffer (Woohoo!) but the posts are so old it hurts, wondering if this feature is now deprecated in favour of the UNITY_OUTPUT_DEPTH. This would be ok, however it doesn't appear to output anything.

    When checking through the UnityCG.cgnic, I can see where it is defined, but presumably this then gets picked up somewhere else as all I see if a define and no real output to the Depth, which judging by the first posts it must have to do at some point.

    EDIT: Was totally reading the cginc incorrectly. Think my mind got a little lost with the whole SV_Depth semantic and I was expecting something similar.

    So back to my question, how do I write my own depth stuff quickly and efficiently via shaders these days without some kind of Tags { "LightMode" = "ShadowCaster" } hack. This doesn't feel right. I presume if Output depth had broken / was bugged we'd have more of an uproar, so what am I missing?

    Thank you in advance.
     
    Last edited: Dec 7, 2015
  2. Flailer

    Flailer

    Joined:
    Apr 1, 2014
    Posts:
    66
  3. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,248
    See my reply to that post, he's asking about depth for post processing specifically though, which might be slightly different than what you need.
     
    Flailer likes this.
  4. Flailer

    Flailer

    Joined:
    Apr 1, 2014
    Posts:
    66
    I see, it is a little different, especially as it's appears to be more for a deferred render pipeline. But still very useful and clears up quite a few of my questions, which means I might be able to do a little more digging and work some things out myself.
     
  5. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,248
    Actually all of that is for the forward rendering pipeline. For deferred you just don't need to update the Camera-DepthNormalTexture.shader file to add an additional pass.
     
  6. Flailer

    Flailer

    Joined:
    Apr 1, 2014
    Posts:
    66