CelShader_createrole.shader 4.3 KB

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