simple outline shader, using the vertex normal
Beneath is a method of drawing outlines around our mesh - or rather, we're expanding the mesh, giving it a flat colour and then drawing the mesh as normal on top of it. Note that we have two CGPROGRAM blocks, which get executed in order.
This type of outline requires the transparent tag to work properly, and this could cause problems elsewhere.. Also it only outlines the extremities of a shape - or you could say, just the alpha edges.
Next post will feature a more advanced shader
Shader "Dave/Unlit/simpleOutline"
{
Properties
{
_MainTex("Texture",2D) = "white"{}
_OutlineColor("Outline Colour",color)=(0,0,0,1)
_Outline("Outline Width",Range(-0.1,0.1))=0.005
}
SubShader{
Tags{"Queue"="Transparent"}
ZWrite off
CGPROGRAM
#pragma surface surf Lambert vertex:vert
struct Input {
float2 uv_MainTex;
};
float _Outline;
float4 _OutlineColor;
void vert(inout appdata_full v) {
v.vertex.xyz += v.normal * _Outline;
}
sampler2D _MainTex;
void surf(Input IN, inout SurfaceOutput o) {
o.Emission = _OutlineColor.rgb;
}
ENDCG
ZWrite on
CGPROGRAM
#pragma surface surf Lambert
struct Input {
float2 uv_MainTex;
float3 normal;
};
sampler2D _MainTex;
void surf(Input IN, inout SurfaceOutput o) {
o.Albedo = tex2D(_MainTex, IN.uv_MainTex).rgb;
}
ENDCG
}
Fallback "Diffuse"
}
Comments
Post a Comment