Non-uniform outline shader

Hey folks,
I’m looking for a fresnel based outline (unlit diffuse) shader with adjustable outline, to be used in an iOS project. I found this posted by noradninja (made with Strumpy Shader Editor), which does exactly what I’m looking for, but one thing; I need to be able to change the color of the outline: http://forum.unity3d.com/attachment.php?attachmentid=21739&d=1308794717

If I understand correctly, this can’t be done with the shader noradninja came up with, and I’m a non-technical artist, so if anyone have a such shader lying around or if anyone can point me in the right direction of how to make this, it would be much appreciated.
Thanks
-Casper

I came up with a similar shader for my project. Here’s my shader code, modified to have an adjustable width and support colour outlines.

Shader "Custom/Fresnel Outline" {

	Properties {
		_MainTex ("Diffuse (RGB)", 2D) = "white" {}
		_OutlineColor ("Outline Colour", Color) = ( 0.0, 0.0, 0.0, 0.0)
		_OutlineAdjust ("Outline Adjust", Range(0.0, 1.0)) = 0.25
	}

	SubShader {
		Tags { "RenderType"="Opaque" "IgnoreProjector"="True" "Queue"="Geometry" }
		Lighting Off
		LOD 200
		
		Pass {
			Tags { "LightMode" = "Always" }
			CGPROGRAM
				#pragma vertex vert
				#pragma fragment frag
				#pragma multi_compile_builtin
				#pragma fragmentoption ARB_precision_hint_fastest
				
				#include "UnityCG.cginc"
				
				struct v2f {
					float4	pos : SV_POSITION;
					fixed2	uv : TEXCOORD0;
					fixed		outline : TEXCOORD1;
				};
				
				v2f vert (appdata_base v) {
					v2f o;
					o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
					o.uv = v.texcoord.xy; // UVs.
					o.outline = dot(ObjSpaceViewDir(v.vertex), v.normal) / o.pos.w/ unity_Scale.w; // Ramp UV coord.
					return o;
				}
				
				sampler2D _MainTex;
				fixed4 _OutlineColor;
				fixed _OutlineAdjust;
				
				fixed4 frag(v2f i) : COLOR {
					fixed4 c = tex2D ( _MainTex, i.uv ); // Diffuse.
					fixed o = step ( _OutlineAdjust, i.outline ); //Outline.
					c *= o; // Apply outline to diffuse.
					c += _OutlineColor * (1 - o); // Apply colour to outline, add to diffuse.
					return c;
				}
			ENDCG
		}
	}
	FallBack Off
}

Exactly what I was looking for. Thank you so much!!

One question:
The outline seems to almost disappear (even at max setting) when you are far away, and cover the whole object when you are up close. Is it possible to have it remain a bit more constant? And again, thanks alot :slight_smile:

Yeah, it’s a result of the fresnel effect.

I’ll have a fiddle and see what I can do.

I’ve updated the code in my original post to fix that issue.

Perfect! :slight_smile: