Mole_Particles_Alpha_UVAnim_Dissolution.shader 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. Shader "MoleGame/Particles/Alpha_UVAnim_Dissolution"
  2. {
  3. Properties {
  4. _MainTex ("MainTex", 2D) = "white" {}
  5. _TintColor ("Color", Color) = (0,0,0,1)
  6. _U_Speed ("U_Speed", Float ) = 0
  7. _V_Speed ("V_Speed", Float ) = -1
  8. _Add ("Add", Float ) = 1
  9. _Dissolution_T ("Dissolution_T", 2D) = "white" {}
  10. _Dissolution_01 ("Dissolution_01", Float ) = 0
  11. _U_Speed_02 ("U_Speed_02", Float ) = 0
  12. _V_Speed_02 ("V_Speed_02", Float ) = -1
  13. _Fresnel ("Fresnel", Float ) = 1
  14. _DissolutionAdd ("DissolutionAdd", Float ) = 0 // 溶解系数,0表示关闭
  15. //[HideInInspector]_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
  16. }
  17. SubShader {
  18. Tags {
  19. "IgnoreProjector"="True"
  20. "Queue"="Transparent"
  21. "RenderType"="Transparent"
  22. }
  23. Pass {
  24. Name "FORWARD"
  25. Tags {
  26. "LightMode"="ForwardBase"
  27. }
  28. Blend SrcAlpha OneMinusSrcAlpha
  29. Cull Off
  30. //AlphaToMask On
  31. CGPROGRAM
  32. #pragma vertex vert
  33. #pragma fragment frag
  34. //#define UNITY_PASS_FORWARDBASE
  35. #include "UnityCG.cginc"
  36. //#pragma multi_compile_fwdbase
  37. #pragma target 3.0
  38. uniform sampler2D _MainTex;
  39. uniform half4 _MainTex_ST;
  40. uniform half4 _TintColor;
  41. uniform half _U_Speed;
  42. uniform half _V_Speed;
  43. uniform half _Add;
  44. uniform sampler2D _Dissolution_T;
  45. uniform half4 _Dissolution_T_ST;
  46. uniform half _Dissolution_01;
  47. uniform half _U_Speed_02;
  48. uniform half _V_Speed_02;
  49. uniform half _Fresnel;
  50. uniform float _DissolutionAdd;
  51. struct VertexInput {
  52. half4 vertex : POSITION;
  53. half3 normal : NORMAL;
  54. half4 texcoord0 : TEXCOORD0;
  55. fixed4 vertexColor : COLOR;
  56. };
  57. struct VertexOutput {
  58. half4 pos : SV_POSITION;
  59. half4 uv : TEXCOORD0;
  60. half4 posWorld : TEXCOORD1;
  61. half3 normalDir : TEXCOORD2;
  62. fixed4 vertexColor : COLOR;
  63. };
  64. VertexOutput vert (VertexInput v) {
  65. VertexOutput o = (VertexOutput)0;
  66. o.uv = v.texcoord0;
  67. o.vertexColor = v.vertexColor;
  68. o.normalDir = UnityObjectToWorldNormal(v.normal);
  69. // 计算顶点动画,_DissolutionAdd = 0 时表示关闭
  70. half2 uv_t = (o.uv + (fmod(_Time.y, 10) * half2(_U_Speed_02, _V_Speed_02)));
  71. float4 _Dissolution_T_var = tex2Dlod(_Dissolution_T,float4(TRANSFORM_TEX(uv_t, _Dissolution_T),0.0,0));
  72. v.vertex.xyz += (_Dissolution_T_var.r * v.normal * _DissolutionAdd);
  73. o.posWorld = mul(unity_ObjectToWorld, v.vertex);
  74. o.pos = UnityObjectToClipPos( v.vertex );
  75. return o;
  76. }
  77. float4 frag(VertexOutput i, float facing : VFACE) : COLOR {
  78. //float isFrontFace = ( facing >= 0 ? 1 : 0 );
  79. fixed faceSign = sign(facing);//( facing >= 0 ? 1 : -1 );
  80. i.normalDir = normalize(i.normalDir);
  81. i.normalDir *= faceSign;
  82. fixed3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
  83. fixed3 normalDirection = i.normalDir;
  84. half2 uv_t = (i.uv+(fmod(_Time.y,10)*half2(_U_Speed,_V_Speed)));
  85. fixed4 _Dissolution_T_var = tex2D(_Dissolution_T,TRANSFORM_TEX(uv_t, _Dissolution_T));
  86. _Dissolution_01 = max(_Dissolution_01, 0.0001);
  87. fixed z = max(i.uv.z, 0.0001);
  88. clip(((_Dissolution_T_var.r/_Dissolution_01)*z + _DissolutionAdd) - 0.5);
  89. ////// Emissive:
  90. fixed4 _MainTex_var = tex2D(_MainTex,TRANSFORM_TEX(uv_t, _MainTex));
  91. fixed fresnel = pow(1.0-max(0,dot(normalDirection, viewDirection)),_Fresnel);
  92. fixed3 col = fresnel * (_MainTex_var.rgb*i.vertexColor.rgb*_TintColor.rgb*_Add);
  93. fixed alpha = _MainTex_var.a*i.vertexColor.a*_TintColor.a;
  94. return fixed4(col,alpha);
  95. }
  96. ENDCG
  97. }
  98. }
  99. }