// WireShader.shader Shader "Custom/WireShader" { Properties { _Color ("Color", Color) = (1,1,1,1) _Thickness ("Thickness", Range(0, 0.1)) = 0.02 } SubShader { Tags { "RenderType"="Opaque" "Queue"="Geometry+1" } LOD 100 Pass { CGPROGRAM #pragma vertex vert #pragma fragment frag #pragma multi_compile_fog #include "UnityCG.cginc" struct appdata { float4 vertex : POSITION; }; struct v2f { float4 vertex : SV_POSITION; UNITY_FOG_COORDS(0) }; fixed4 _Color; float _Thickness; v2f vert (appdata v) { v2f o; // 将顶点稍微向摄像机方向偏移,避免深度冲突 float3 viewPos = UnityObjectToViewPos(v.vertex); viewPos.z -= _Thickness * 10; // 轻微深度偏移 o.vertex = UnityViewToClipPos(viewPos); UNITY_TRANSFER_FOG(o,o.vertex); return o; } fixed4 frag (v2f i) : SV_Target { fixed4 col = _Color; UNITY_APPLY_FOG(i.fogCoord, col); return col; } ENDCG } } }