Shader "Unlit/Outline" { Properties { _OutlineColor ("描边颜色", Color) = (0,0,0,1) _OutlineWidth ("描边宽度", Range(0.001, 0.1)) = 0.015 } SubShader { Tags { "RenderType"="Opaque" "Queue"="Geometry+10" } LOD 100 Pass { Cull Front ZWrite On CGPROGRAM #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" struct appdata { float4 vertex : POSITION; float3 normal : NORMAL; }; struct v2f { float4 pos : SV_POSITION; }; fixed4 _OutlineColor; float _OutlineWidth; v2f vert (appdata v) { v2f o; // 沿法线方向外扩顶点 float3 expandedPos = v.vertex.xyz + v.normal * _OutlineWidth; o.pos = UnityObjectToClipPos(float4(expandedPos, 1.0)); return o; } fixed4 frag (v2f i) : SV_Target { return _OutlineColor; } ENDCG } } FallBack "Unlit/Texture" }