You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
Shader "Unlit/OutLine"
{
Properties
{
_Ref("Ref",Float) = 1
_LineColor("LineColor",Color) = (1,1,1,1)
_LineWidth("LineWidth",Float) = 1
}
SubShader
{
Tags{"Queue" = "Transparent" "RenderType" = "Transparent" "IgnoreProjector" = "true"}
Blend SrcAlpha OneMinusSrcAlpha
Pass
{
ColorMask 0
ZTest Always
ZWrite Off
Stencil
{
ref [_Ref]
Comp Always
Pass Replace
}
}
Pass
{
ZWrite Off
ZTest Always
Stencil
{
ref [_Ref]
Comp NotEqual
Pass Replace
}
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
float3 normal : NORMAL;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
float _LineWidth;
float4 _LineColor;
v2f vert (appdata v)
{
v2f o;
// float4 pos = mul(UNITY_MATRIX_MV, v.vertex); //计算观察空间坐标
// float3 normal = mul((float3x3)UNITY_MATRIX_IT_MV, v.normal); //法线转到观察空间
// normal.z = -0.5; //trick: 手动把法线z分量设为负值( 其实是View空间的z正方向)
// //尽可能避免背面扩张后的顶点挡住正面的面片
// pos = pos + float4(normalize(normal), 0) * _LineWidth; //观察空间下,进行法线外扩
// o.vertex = mul(UNITY_MATRIX_P, pos); //变换到裁切空间
v.vertex = v.vertex + half4(v.normal,1) * _LineWidth;
o.vertex = UnityObjectToClipPos(v.vertex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
return _LineColor;
}
ENDCG
}
}
}