TouShi.shader 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
  2. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
  3. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
  4. Shader "Hero/TouShi" {
  5. Properties
  6. {
  7. _Color("Main Color", Color) = (1,1,1,1)
  8. _MainTex("Main Texture", 2D) = "white" {}
  9. _MaskTex("Mask (RGB)", 2D) = "white" {}
  10. _Strength("Strength", Range(0, 2)) = 2
  11. _Muti_Color("Muti Color", Color) = (1,1,1,1)
  12. _Add_Color("Add Color", Color) = (0,0,0,1)
  13. _OutlineColor ("Outline Color", Color) = (0,0,0,1)
  14. _Outline ("Outline width", Range (0, 0.1)) = .01
  15. _OutlineStrength("OutlineStrength", Range (0, 1)) = .75
  16. _ClrStrength("ClrStrength", Range(0, 1.7)) = 1.7
  17. _StatueDegree("StatueDegree", Range(0, 1)) = 0
  18. }
  19. SubShader
  20. {
  21. Tags {
  22. "RenderType" = "Opaque"
  23. }
  24. LOD 100
  25. // note that a vertex shader is specified here but its using the one above
  26. Pass
  27. {
  28. Name "OUTLINE"
  29. Tags{ "LightMode" = "Always" }
  30. Cull Front
  31. ZWrite On
  32. /*ColorMask RGB*/
  33. Blend SrcAlpha OneMinusSrcAlpha
  34. CGPROGRAM
  35. #pragma vertex vert
  36. #pragma fragment frag
  37. #include "UnityCG.cginc"
  38. uniform fixed4 _OutlineColor;
  39. uniform half _Outline;
  40. half _OutlineStrength;
  41. sampler2D _MainTex;
  42. float4 _MainTex_ST;
  43. sampler2D _MaskTex;
  44. struct appdata {
  45. float4 vertex : POSITION;
  46. float3 normal : NORMAL;
  47. float4 texCoord : TEXCOORD0;
  48. };
  49. struct v2f {
  50. float4 pos : POSITION;
  51. float4 tex : TEXCOORD0;
  52. };
  53. v2f vert(appdata v) {
  54. // just make a copy of incoming vertex data but scaled according to normal direction
  55. v2f o;
  56. o.pos = UnityObjectToClipPos(v.vertex);
  57. float3 norm = mul((float3x3)UNITY_MATRIX_IT_MV, v.normal);
  58. float2 offset = TransformViewToProjection(norm.xy);
  59. o.pos.xy += offset * _Outline * 0.5;
  60. o.tex.xy = TRANSFORM_TEX(v.texCoord, _MainTex);
  61. return o;
  62. }
  63. fixed4 frag(v2f i) :COLOR
  64. {
  65. fixed4 cDark = tex2D(_MainTex, i.tex.xy);
  66. cDark = cDark * _OutlineStrength;// *cDark * cDark;
  67. cDark.a = 1; // weapon had alpha?
  68. cDark.rgb = cDark.rgb + _OutlineColor.rgb;
  69. return cDark;
  70. }
  71. ENDCG
  72. } // outline Pass
  73. Pass
  74. {
  75. Name "FORWARD"
  76. Tags {
  77. "LightMode" = "ForwardBase"
  78. }
  79. CGPROGRAM
  80. #pragma fragmentoption ARB_precision_hint_fastest
  81. #pragma vertex vert
  82. #pragma fragment frag
  83. #pragma multi_compile_fog
  84. #include "UnityCG.cginc"
  85. #include "AutoLight.cginc"
  86. uniform fixed3 _LightColor0;
  87. sampler2D _MainTex;
  88. float4 _MainTex_ST;
  89. fixed4 _Color;
  90. fixed _Strength;
  91. half _ClrStrength;
  92. fixed4 _Muti_Color;
  93. fixed4 _Add_Color;
  94. fixed _StatueDegree;
  95. struct V2f {
  96. fixed4 pos : SV_POSITION;
  97. fixed2 uv0 : TEXCOORD0;
  98. fixed4 posWorld : TEXCOORD1;
  99. fixed3 normalDir : TEXCOORD2;
  100. fixed3 col : COLOR;
  101. UNITY_FOG_COORDS(4)
  102. };
  103. V2f vert(appdata_full v) {
  104. V2f o;
  105. o.uv0 = TRANSFORM_TEX(v.texcoord, _MainTex);
  106. float3 worldNormal = UnityObjectToWorldNormal(v.normal);
  107. o.normalDir = worldNormal;
  108. o.posWorld = mul(unity_ObjectToWorld, v.vertex);
  109. o.pos = UnityObjectToClipPos(v.vertex);
  110. UNITY_TRANSFER_FOG(o,o.pos);
  111. fixed3 lightDirection = _WorldSpaceLightPos0.xyz;
  112. fixed3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - o.posWorld.xyz);
  113. float ff = saturate(1 - max(0, dot(o.normalDir, viewDirection)));
  114. o.col = lerp(max(0,dot(lightDirection, o.normalDir))*_LightColor0,UNITY_LIGHTMODEL_AMBIENT.rgb,0.2 );
  115. return o;
  116. }
  117. fixed4 frag(V2f i) : SV_Target{
  118. fixed4 diff = tex2D(_MainTex, i.uv0) * _Color * _ClrStrength;
  119. fixed4 col = fixed4((diff.rgb * _Muti_Color + diff.rgb * i.col + _Add_Color.rgb),1);
  120. fixed3 lpCol = diff.rgb;
  121. col.rgb = lpCol * _Strength;
  122. fixed grey = dot(col.rgb, fixed3(0.299, 0.587, 0.114));
  123. col.rgb = lerp(col.rgb, fixed3(grey, grey, grey), _StatueDegree);
  124. UNITY_APPLY_FOG(i.fogCoord, col);
  125. return col;
  126. }
  127. ENDCG
  128. } //normal pass
  129. }
  130. //FallBack "Diffuse"
  131. }