帮我写一个描边的shader
时间: 2023-02-21 14:29:21 浏览: 53
好的,这是一个简单的描边shader的代码例子:
```
Shader "Custom/Outline" {
Properties {
_Color ("Outline Color", Color) = (1,1,1,1)
_Thickness ("Outline Thickness", Range (0.0, 0.1)) = 0.03
}
SubShader {
Tags {"Queue"="Geometry+1"}
Pass {
ZWrite On
ZTest AlwaysEqual
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_fog
#include "UnityCG.cginc"
struct appdata {
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f {
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
v2f vert (appdata v) {
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
sampler2D _MainTex;
float4 _MainTex_ST;
float4 _Color;
float _Thickness;
float4 frag (v2f i) : SV_Target {
float4 col = _Color;
col.a = texture(_MainTex, i.uv).r;
return col * col.a * smoothstep(0.5 - _Thickness, 0.5 + _Thickness, col.a);
}
ENDCG
}
}
FallBack "Diffuse"
}
```
这个shader可以在你的物体表面添加一个颜色为白色、厚度为0.03的轮廓。你可以通过修改`_Color`和`_Thickness`属性来调整描边的颜色和厚度。