I’m trying to add an outline to an arrow 3d model to make its edges stick out more. Any advice?
This simple outlining shader requires your mesh has all the joints welded otherwise the joints will create gaps for the outline (as can be seen when applied to built-in cube, cylinder or capsule).
// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt)
Shader "Legacy Shaders/Diffuse outlined" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_OutlineColor ("Outline Color", Color) = (1,1,1,1)
_thickness ("Outline thickness", Range(-1,1)) = .2
_MainTex ("Base (RGB)", 2D) = "white" {}
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
Pass {
Name "Outliner"
Cull Front
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
fixed4 _OutlineColor;
half _thickness;
struct appdata {
float4 pos : POSITION;
fixed4 normal : NORMAL0;
};
struct v2f {
fixed4 pos : SV_POSITION;
};
v2f vert (appdata v) {
v2f o;
v.pos.xyz += -v.normal.xyz * _thickness;
o.pos = mul(UNITY_MATRIX_MVP, v.pos);
return o;
}
half4 frag ( v2f i ) : COLOR {
return _OutlineColor;
}
ENDCG
}
CGPROGRAM
#pragma surface surf Lambert
sampler2D _MainTex;
fixed4 _Color;
struct Input {
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o) {
fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
Fallback "Legacy Shaders/VertexLit"
}
1 Like