65 lines
1.7 KiB
Plaintext
65 lines
1.7 KiB
Plaintext
|
|
Shader "Custom/OutlineUnlit"
|
||
|
|
{
|
||
|
|
Properties
|
||
|
|
{
|
||
|
|
_MainColor ("Main Color", Color) = (0.1, 0.3, 0.8, 0.3)
|
||
|
|
_OutlineColor ("Outline Color", Color) = (0.2, 0.5, 1, 1)
|
||
|
|
_OutlineWidth ("Outline Width", Range(0, 0.3)) = 0.08
|
||
|
|
}
|
||
|
|
SubShader
|
||
|
|
{
|
||
|
|
Tags { "RenderType"="Transparent" "Queue"="Transparent" }
|
||
|
|
Blend SrcAlpha OneMinusSrcAlpha
|
||
|
|
ZWrite Off
|
||
|
|
|
||
|
|
// Pass 1: 膨胀描边
|
||
|
|
Pass
|
||
|
|
{
|
||
|
|
Name "OUTLINE"
|
||
|
|
Cull Front
|
||
|
|
CGPROGRAM
|
||
|
|
#pragma vertex vert
|
||
|
|
#pragma fragment frag
|
||
|
|
#include "UnityCG.cginc"
|
||
|
|
|
||
|
|
float _OutlineWidth;
|
||
|
|
float4 _OutlineColor;
|
||
|
|
|
||
|
|
struct appdata { float4 vertex : POSITION; float3 normal : NORMAL; };
|
||
|
|
struct v2f { float4 pos : SV_POSITION; };
|
||
|
|
|
||
|
|
v2f vert(appdata v)
|
||
|
|
{
|
||
|
|
v2f o;
|
||
|
|
float3 n = normalize(v.normal);
|
||
|
|
v.vertex.xyz += n * _OutlineWidth;
|
||
|
|
o.pos = UnityObjectToClipPos(v.vertex);
|
||
|
|
return o;
|
||
|
|
}
|
||
|
|
|
||
|
|
fixed4 frag(v2f i) : SV_Target { return _OutlineColor; }
|
||
|
|
ENDCG
|
||
|
|
}
|
||
|
|
|
||
|
|
// Pass 2: 内芯填充
|
||
|
|
Pass
|
||
|
|
{
|
||
|
|
Name "FILL"
|
||
|
|
Cull Back
|
||
|
|
CGPROGRAM
|
||
|
|
#pragma vertex vert
|
||
|
|
#pragma fragment frag
|
||
|
|
#include "UnityCG.cginc"
|
||
|
|
|
||
|
|
float4 _MainColor;
|
||
|
|
|
||
|
|
struct appdata { float4 vertex : POSITION; };
|
||
|
|
struct v2f { float4 pos : SV_POSITION; };
|
||
|
|
|
||
|
|
v2f vert(appdata v) { v2f o; o.pos = UnityObjectToClipPos(v.vertex); return o; }
|
||
|
|
fixed4 frag(v2f i) : SV_Target { return _MainColor; }
|
||
|
|
ENDCG
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|