Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How to build or where to get the "overdraw" shader used in the Scene view

Discussion in 'Shaders' started by Jean-Fabre, Jan 18, 2011.

  1. Jean-Fabre

    Jean-Fabre

    Joined:
    Sep 6, 2007
    Posts:
    429
    Hi,

    Posted a question in unity answers with no reply, so I am trying now on the appropriate forum:)


    Is the shader used for the overdraw effect available somewhere? You can view it in the authoring scene tab , the second drop down is normally set to rgb but you have other options, including overdraw.

    I really like this shader, so hopefully, someone can put me in the right direction to build it, as I am not yet very knowledgeable with shaders unfortunately.

    Bye,

    Jean
     
  2. Kuba

    Kuba

    Moderator

    Joined:
    Jan 13, 2009
    Posts:
    416
  3. Jean-Fabre

    Jean-Fabre

    Joined:
    Sep 6, 2007
    Posts:
    429
    Yep, thank you very much for that! works very well.

    I have added the possibility to pick the color for convenience:

    Code (csharp):
    1. Shader "Overdraw" {
    2. Properties {
    3.     _MainTex ("Base", 2D) = "white" {}
    4.     _Color ("Main Color", Color) = (0.15,0.0,0.0,0.0)
    5. }
    6.  
    7. SubShader {
    8.     Fog { Mode Off }
    9.     ZWrite Off
    10.     ZTest Always
    11.     Blend One One // additive blending
    12.  
    13.     Pass {
    14.         SetTexture[_MainTex] {
    15.             constantColor [_Color]
    16.             combine constant, texture
    17.         }
    18.     }
    19. }
    20. }
     
    Last edited: Jan 18, 2011
    Paul-Swanson and JBehreandt like this.
  4. cupsster

    cupsster

    Joined:
    Apr 14, 2009
    Posts:
    363
    Can this be extended to support bump map?
     
  5. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    This shader does not model any lighting. What would you expect a bump map to do?
     
  6. Kovenant

    Kovenant

    Joined:
    Sep 18, 2013
    Posts:
    254
    Can this be made into an Image Effect? If so, how? I would want this shader to affect everything visible by the camera instead of switching materials of objects at runtime..
     
  7. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    No. Quite explicitly this would be impossible as just an image effect. An image effect can only work on the image(s) that has been rendered, and since (presumably) the entire scene wasn't rendered in flat translucent colors to begin with there's no way for an image effect to show things that were hidden behind other things in the original image.

    However it would be possible using a replacement shader.
    https://docs.unity3d.com/Manual/SL-ShaderReplacement.html
     
    Kovenant likes this.
  8. Kovenant

    Kovenant

    Joined:
    Sep 18, 2013
    Posts:
    254
    Thanks.. I've achieved what I wanted with a ReplacementShader :) This will work great for a Stealth game I'm working on. However.. Is it possible to make a ReplacementShader only affect certain objects in the scene, or rather ignore certain objects in the scene on a certain Layer or with a certain tag?

    Making a whole level using this overdraw effect looks good, but with a lot of models in the scene it kinda makes no sense.. :)
     
  9. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    If you don't want an object to render at all, just make sure it has a tag that isn't listed in the replacement shader. For example, you could have your replacement shader use a tag name of "Stealth", then walls would use the value "Stealth"="Wall', enemies "Stealth"="Enemy", etc. Objects you don't care about don't get the tag at all, or use a tag value like "Hidden". This does mean you have to either use custom materials, or assign the tags via script:
    https://docs.unity3d.com/ScriptReference/Material.SetOverrideTag.html

    If you want to render the scene with the replacement shader, but have some objects render normally, that you can't do. For that people generally just render the entire scene as is and either manually swap the materials on objects, or they just render everything and then use a replacement shader pass to render on top like this:
     
  10. Kovenant

    Kovenant

    Joined:
    Sep 18, 2013
    Posts:
    254
    I found that video yesterday and it was great. However he forgot to include the modified Standard Shader and the shader he included doesn't work like it does in the video; i.e the outline is always drawn no matter if the character / object is behind a wall or not so I will try to fix that..
     
  11. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,521
  12. GearKlik

    GearKlik

    Joined:
    Sep 21, 2015
    Posts:
    58
    Is it possible to replace/edit the actual shader used by Unity to display scene overdraw? I find a color ramp from green through yellow to red is more intuitive for artists.