123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
-
- Shader "Unlit/Outline"
- {
- Properties{
- _Color("Main Tint", Color) = (1, 1, 1, 1)
- _MainTex("Texture", 2D) = "white" {}
- _OutlineWidth("OutlineWidth", Range(0, 1)) = 0.1
- _OutlineColor("OutlineColor", Color) = (1, 1, 1, 1)
- _AlphaBlend("AlphaBlend", Range(0, 1)) = 0.8
- _AlphaTest("AlphaTest", Range(0, 1)) = 0.5
- }
- SubShader
- {
-
-
-
- Tags{ "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" }
-
- Pass{
-
- ZWrite On
-
-
-
- ColorMask 0
- CGPROGRAM
- #pragma vertex vert
- #pragma fragment frag
- #include "Lighting.cginc"
- sampler2D _MainTex;
- float4 _MainTex_ST;
- fixed _AlphaTest;
- struct a2v {
- float4 vertex : POSITION;
- float4 texcoord : TEXCOORD0;
- };
- struct v2f {
- float4 pos : SV_POSITION;
- float2 uv : TEXCOORD2;
- };
- v2f vert(a2v v) {
- v2f o;
- o.pos = UnityObjectToClipPos(v.vertex);
- o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
- return o;
- }
- fixed4 frag(v2f i) : SV_Target{
- fixed4 texColor = tex2D(_MainTex, i.uv);
- clip(texColor.a - _AlphaTest);
- return fixed4(0,0,0,1);
- }
- ENDCG
- }
-
- Pass{
-
- Tags{ "LightMode" = "ForwardBase" }
- Cull Off
- ZWrite Off
-
-
-
-
- Blend SrcAlpha OneMinusSrcAlpha
- CGPROGRAM
- #pragma vertex vert
- #pragma fragment frag
- #include "Lighting.cginc"
- fixed4 _Color;
- sampler2D _MainTex;
- float4 _MainTex_ST;
- fixed _AlphaBlend;
- struct a2v {
- float4 vertex : POSITION;
- float3 normal : NORMAL;
- float4 texcoord : TEXCOORD0;
- };
- struct v2f {
- float4 pos : SV_POSITION;
- float3 worldNormal : TEXCOORD0;
- float3 worldPos : TEXCOORD1;
- float2 uv : TEXCOORD2;
- };
- v2f vert(a2v v) {
- v2f o;
- o.pos = UnityObjectToClipPos(v.vertex);
- o.worldNormal = UnityObjectToWorldNormal(v.normal);
- o.worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
- o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
- return o;
- }
- fixed4 frag(v2f i) : SV_Target{
- fixed3 worldNormal = normalize(i.worldNormal);
- fixed3 worldLightDir = normalize(UnityWorldSpaceLightDir(i.worldPos));
- fixed4 texColor = tex2D(_MainTex, i.uv);
- fixed3 albedo = texColor.rgb * _Color;
- fixed3 ambient = UNITY_LIGHTMODEL_AMBIENT.xyz * albedo;
- fixed3 diffuse = _LightColor0.rgb * albedo * max(0, dot(worldNormal, worldLightDir));
-
- return fixed4(ambient + diffuse, texColor.a * _AlphaBlend);
- }
- ENDCG
- }
-
- Pass{
- Cull Front
- CGPROGRAM
- #pragma vertex vert
- #pragma fragment frag
- #include "UnityCG.cginc"
- sampler2D _MainTex;
- float4 _MainTex_ST;
- fixed _AlphaTest;
- float _OutlineWidth;
- float4 _OutlineColor;
- struct a2v
- {
- float4 vertex : POSITION;
- float4 normal : NORMAL;
- float4 texcoord : TEXCOORD0;
- };
- struct v2f
- {
- float4 pos : SV_POSITION;
- float2 uv : TEXCOORD2;
- };
- v2f vert(a2v 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;
- float4 newNoraml = float4(normalize(normal), 0);
- pos = pos + newNoraml * _OutlineWidth;
- o.pos = mul(UNITY_MATRIX_P, pos);
- o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
- return o;
- }
- fixed4 frag(v2f i) : SV_Target
- {
- fixed4 texColor = tex2D(_MainTex, i.uv);
-
- clip(texColor.a - _AlphaTest);
- return _OutlineColor;
- }
- ENDCG
- }
- }
- FallBack "Diffuse"
- }
|