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

Grayscale Depth Surface Shader

Discussion in 'Shaders' started by Boris1998, Nov 28, 2015.

  1. Boris1998

    Boris1998

    Joined:
    Jul 5, 2013
    Posts:
    82
    I need a surface shader that displays depth as grayscale. I think zbuffer is needed here.
    What I want to achieve is similar to this:

    Except, it is done using Vizualize option on new Depth Of Field image effect, and is, later on, not compatibile with other Image Effects because it just shows Depth Texture over Camera's rendering.

    I need 3 shaders:
    1. Just plain grayscale depth surface shader. Example: http://answers.unity3d.com/questions/847344/increasing-the-level-of-detail-with-a-depth-render.html
    Except the shader there is not working in UNITY 5.
    2. Standard shader combined with depth grayscale shader over it which transparency can be altered through slider. I think I could combine Standard and 1st shader myself.

    I want to make something similar to the game "WHICH". Screenshot:


    Thank you all for your time, and help. Cheers!
     

    Attached Files:

  2. StevenGerrard

    StevenGerrard

    Joined:
    Jun 1, 2015
    Posts:
    97
    First normalize your depth buffer.
    Then convert it to gray scale color output, for example " return float4(normalizedDepth.xxx, 1); "
    Maybe in your case you need some other curve to achieve effect you need.
     
  3. Boris1998

    Boris1998

    Joined:
    Jul 5, 2013
    Posts:
    82
    Care explaining a little bit more? I am not really good with shaders.
    What do you mean exactly by "normalizing depth buffer", and how could it be done?
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,248
    Couldn't you just use fog?