12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- Shader "Custom/outline"
- {
- Properties
- {
- _OutlineWidth("Outline Width",Float) = 7.0
- _OutlineZbias("Outline Zbias",Float) = -10
- _OutlineColor("Outline Color",Color) = (1,1,1,1)
- }
- SubShader
- {
- Tags { "RenderType"="Opaque" }
- LOD 200
- Pass
- {
- Cull Front
- CGPROGRAM
- #pragma vertex vert
- #pragma fragment frag
- #include "UnityCG.cginc"
- #include "AutoLight.cginc"
- struct appdata
- {
- float4 vertex : POSITION;
- float2 texcoord0 : TEXCOORD0;
- float3 normal : NORMAL;
- float4 color : COLOR;
- };
- struct v2f
- {
- float4 pos : SV_POSITION;
- float2 uv : TEXCOORD0;
- float4 vertex_color : TEXCOORD3;
- };
- float _OutlineWidth;
- float _OutlineZbias;
- float4 _OutlineColor;
- v2f vert(appdata v)
- {
- v2f o;
- float3 pos_view = UnityObjectToViewPos(v.vertex);
- float3 normal_world = UnityObjectToWorldNormal(v.normal);
- float3 outline_dir = normalize(mul((float3x3)UNITY_MATRIX_V, normal_world));
- outline_dir.z = _OutlineZbias * (1.0 - v.color.b);
- pos_view += outline_dir * _OutlineWidth * 0.001 * v.color.a;
- o.pos = mul(UNITY_MATRIX_P, float4(pos_view, 1.0));
- o.uv = v.texcoord0;
- o.vertex_color = v.color;
- return o;
- }
- half4 frag(v2f i) : SV_Target
- {
- half3 outlineColor = _OutlineColor.xyz;
- return float4(outlineColor, 1.0);
- }
- ENDCG
- }
- }
- FallBack "Diffuse"
- }
|