YanCheng_Metrology/Assets/ArtRes/Shaders/OutLineShader.shader

111 lines
2.7 KiB
Plaintext

Shader "Custom/OutLineShader"
{
Properties
{
_MainTex("Base (RGB)", 2D) = "white" {}
_OutlineColor("Outline Color", Color) = (.0, .0, .0, .0)
_OutlineWidth("Outline Width", Range(0, 10)) = .0
_MaskTex("Mask Texture", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType" = "Overlay" }
Pass
{
Name "OUTLINE"
ZWrite Off
ZTest Always
Blend SrcAlpha OneMinusSrcAlpha
ColorMask RGB
Stencil
{
Ref 1
Comp Always
Pass Replace
}
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float4 pos : POSITION;
};
float _OutlineWidth;
float4 _OutlineColor;
sampler2D _MaskTex;
v2f vert(appdata v)
{
v2f o;
float2 offset = float2(_OutlineWidth / _ScreenParams.x, _OutlineWidth / _ScreenParams.y);
o.pos = UnityObjectToClipPos(v.vertex) + float4(offset, 0, 0) * v.vertex.w;
return o;
}
half4 frag(v2f i) : COLOR
{
// Apply mask texture to control where the outline is visible
float mask = tex2D(_MaskTex, i.pos.xy / i.pos.w).r;
return _OutlineColor * mask;
}
ENDCG
}
Pass
{
Name "BASE"
ZWrite Off
ZTest Always
Blend SrcAlpha OneMinusSrcAlpha
ColorMask RGB
Stencil
{
Ref 1
Comp Equal
Pass Keep
}
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float4 pos : POSITION;
float2 uv : TEXCOORD0;
};
sampler2D _MainTex;
v2f vert(appdata v)
{
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
half4 frag(v2f i) : COLOR
{
return tex2D(_MainTex, i.uv);
}
ENDCG
}
}
}