adding an outline to Unity 5 standard shader

Sweet! Thank You!

do you find a solution for WebGL?

Is it possible to make this shader work with Deffered camera settings and Opaque-rendering mode on the material?

2 Likes

+1 for the shader & script. Saved countless hours on understanding how to extend standard shader itself. Thank you very much!

thank you very much!!! it’s very useful to me!!!

Hey!
I’ve been working with a shader based on this one, it’s important to me that this works. With Unity 5.4 the outline stopped working except if I replace this:

 Pass {
            Name "OUTLINE"
            Tags { "LightMode" = "Always" }
            Cull Front
            ZWrite On
            ColorMask RGB
            Blend SrcAlpha OneMinusSrcAlpha
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #pragma multi_compile_fog
            fixed4 frag(v2f i) : SV_Target
            {
                UNITY_APPLY_FOG(i.fogCoord, i.color);
                return i.color;
            }
            ENDCG
        }

For this:

 Pass {
            Name "OUTLINE"
            Tags { "LightMode" = "Deferred" } //Here I replacement
            Cull Front
            ZWrite On
            ColorMask RGB
            Blend SrcAlpha OneMinusSrcAlpha
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #pragma multi_compile_fog
            fixed4 frag(v2f i) : SV_Target
            {
                UNITY_APPLY_FOG(i.fogCoord, i.color);
                return i.color;
            }
            ENDCG
        }

And it didn’t work as it should, the outline works really weird. It’s important that this works on Deferred. It works in Forward but it’s not what I’m looking. Can someone give me any solution?
I know I should not update unity during a project, that was my wrong.
(I’m sorry, Englis is not my native language)

This is the result I had with v5.3:

And this now:

Hello!!
Anyone has any idea how to add Smoothness to what MingJ has done?!
Standard shader has it,… but not his script.

Everything else works great so far.

Thank you.

Help me please! I spent a lot of time, but there is no result. Used shader and script MingZ (thanks), but no outline on top surface of object (black color on down surface of object - maybe this is outline). Screenshot attached.
What I doing wrong?


Wow fantastic! This is exactly what I was looking for.

However… is anyone else having trouble with it not working? If I setup a material and adjust the outline properties it appears to look correct in the material preview window, but when this material is applied to an object the outline just does not render at all. Both in the editor and when compiled and run in the player.

Never mind. Turns out it was because I was using Deferred shading. Did not realize this only worked in ForwardBase

Adding smoothness can be achieved by replacing the TexturePropertySingleLine method on the last else statement of void DoSpecularMetallicArea with TexturePropertyTwoLines. (Assuming metallic workflow)

void DoSpecularMetallicArea() {
            if(m_WorkflowMode == WorkflowMode.Specular) {
                if(specularMap.textureValue == null)
                    m_MaterialEditor.TexturePropertyTwoLines(Styles.specularMapText, specularMap, specularColor, Styles.smoothnessText, smoothness);
                else
                    m_MaterialEditor.TexturePropertySingleLine(Styles.specularMapText, specularMap);

            } else if(m_WorkflowMode == WorkflowMode.Metallic) {
                if(metallicMap.textureValue == null)
                    m_MaterialEditor.TexturePropertyTwoLines(Styles.metallicMapText, metallicMap, metallic, Styles.smoothnessText, smoothness);
                else
                    m_MaterialEditor.TexturePropertyTwoLines(Styles.metallicMapText, metallicMap, metallic, Styles.smoothnessText, smoothness);
                    //m_MaterialEditor.TexturePropertySingleLine(Styles.metallicMapText, metallicMap);
            }
        }

For those who want to make it work on Andriod and IOs:

there is two sub shader inside the standard shader, just impeliment this part inside both of them

  • // Outline addition starts here
  • Cull Off
  • ZWrite Off
  • //ZTest Always // Uncomment for ā€œsee throughā€
    • CGPROGRAM
  • #pragma surface surf Solid vertex:vert
  • struct Input {
  • float4 color : COLOR;
  • };
    • fixed4 _OutColor;
  • float _Outline;
    • fixed4 LightingSolid (SurfaceOutput s, half3 lightDir, half atten) {
  • return _OutColor;
  • }
    • void vert (inout appdata_full v) {
  • v.vertex.xyz += v.normal * _Outline;
  • }
    • void surf (Input IN, inout SurfaceOutput o) {
  • o.Albedo = _OutColor.rgb;
  • }
  • ENDCG
    • Cull Back
  • ZWrite On
  • ZTest LEqual
  • // Outline addition ends here

Would anyone mind posting a complete and working version?