FadeOut.shader 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. Shader "Hero/FadeOut" {
  2. Properties
  3. {
  4. _Color("Main Color", Color) = (1,1,1,1)
  5. _MainTex("Main Texture", 2D) = "white" {}
  6. _MaskTex("Mask (RGB)", 2D) = "white" {}
  7. _Strength("Strength", Range(0, 2)) = 2
  8. _Muti_Color("Muti Color", Color) = (1,1,1,1)
  9. _Add_Color("Add Color", Color) = (0,0,0,1)
  10. _Rim_Color("Rim Color", Color) = (1,1,1,1)
  11. _Rim_Strength("Rim Strength", Range(0, 1)) = 0
  12. _ClrStrength("ClrStrength", Range(0, 1.7)) = 1.7
  13. _Alpha("Alpha",Range(0, 1)) = 1
  14. _StatueDegree("StatueDegree", Range(0, 1)) = 0
  15. }
  16. SubShader
  17. {
  18. Tags {
  19. "IgnoreProjector" = "True"
  20. "Queue" = "Transparent"
  21. "RenderType" = "Transparent"
  22. }
  23. Pass
  24. {
  25. Name "FORWARD"
  26. Tags {
  27. "LightMode" = "ForwardBase"
  28. }
  29. Blend SrcAlpha OneMinusSrcAlpha
  30. CGPROGRAM
  31. #pragma fragmentoption ARB_precision_hint_fastest
  32. #pragma vertex vert
  33. #pragma fragment frag
  34. #pragma multi_compile_fog
  35. #include "UnityCG.cginc"
  36. #include "AutoLight.cginc"
  37. uniform fixed3 _LightColor0;
  38. sampler2D _MainTex;
  39. float4 _MainTex_ST;
  40. fixed4 _Color;
  41. fixed _Strength;
  42. half _ClrStrength;
  43. fixed4 _Rim_Color;
  44. fixed4 _Muti_Color;
  45. fixed4 _Add_Color;
  46. fixed _Rim_Strength;
  47. float _Alpha;
  48. fixed _StatueDegree;
  49. struct V2f {
  50. fixed4 pos : SV_POSITION;
  51. fixed2 uv0 : TEXCOORD0;
  52. fixed4 posWorld : TEXCOORD1;
  53. fixed3 normalDir : TEXCOORD2;
  54. fixed3 fres : TEXCOORD3;
  55. fixed3 col : COLOR;
  56. fixed3 lightProbe : TEXCOORD5;
  57. UNITY_FOG_COORDS(4)
  58. };
  59. V2f vert(appdata_full v) {
  60. V2f o;
  61. o.uv0 = TRANSFORM_TEX(v.texcoord, _MainTex);
  62. float3 worldNormal = UnityObjectToWorldNormal(v.normal);
  63. o.normalDir = worldNormal;
  64. o.posWorld = mul(unity_ObjectToWorld, v.vertex);
  65. o.pos = UnityObjectToClipPos(v.vertex);
  66. UNITY_TRANSFER_FOG(o,o.pos);
  67. fixed3 lightDirection = _WorldSpaceLightPos0.xyz;
  68. fixed3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - o.posWorld.xyz);
  69. float sqrRim = sqrt(_Rim_Strength);
  70. float rsqrRim = (1 - sqrt(sqrRim));
  71. float ff = saturate(1 - max(0, dot(o.normalDir, viewDirection)));
  72. o.fres = pow(ff, rsqrRim * 20)* _Rim_Color.rgb;
  73. o.col = lerp(max(0,dot(lightDirection, o.normalDir))*_LightColor0,UNITY_LIGHTMODEL_AMBIENT.rgb,0.2);
  74. fixed3 shCol = ShadeSH9(float4(worldNormal,1));
  75. float f = step(0.001,shCol.r*shCol.g*shCol.b);
  76. o.lightProbe = fixed3(1, 1, 1);// *(1 - f) + shCol * f;
  77. return o;
  78. }
  79. fixed4 frag(V2f i) : SV_Target
  80. {
  81. fixed4 diff = tex2D(_MainTex, i.uv0) * _Color * _ClrStrength;
  82. fixed4 col = fixed4((diff.rgb * _Muti_Color + diff.rgb * i.col + _Add_Color.rgb + i.fres), _Alpha);
  83. fixed3 lpCol = col.rgb;
  84. col.rgb = lpCol * _Strength;
  85. fixed grey = dot(col.rgb, fixed3(0.299, 0.587, 0.114));
  86. col.rgb = lerp(col.rgb, fixed3(grey, grey, grey), _StatueDegree);
  87. UNITY_APPLY_FOG(i.fogCoord, col);
  88. return col;
  89. }
  90. ENDCG
  91. } //normal pass
  92. }
  93. //FallBack "Diffuse"
  94. }