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

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

I answered on Unity Answers. :slight_smile:

Yep, thank you very much for that! works very well.

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

Shader "Overdraw" {
Properties {
    _MainTex ("Base", 2D) = "white" {}
    _Color ("Main Color", Color) = (0.15,0.0,0.0,0.0)
}

SubShader {
    Fog { Mode Off }
    ZWrite Off
    ZTest Always
    Blend One One // additive blending

    Pass {
        SetTexture[_MainTex] {
            constantColor [_Color]
            combine constant, texture
        }
    }
}
}
2 Likes

Can this be extended to support bump map?

This shader does not model any lighting. What would you expect a bump map to do?

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…

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.

1 Like

Thanks… I’ve achieved what I wanted with a ReplacementShader :slight_smile: 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… :slight_smile:

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:

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:

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…

Hi, I believe that the ZTest Always should be ZTest LEqual.
You can see more on this here Overdraw of opaque and transparent geometry - Unity Engine - Unity Discussions

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.