Particle_Softrim_Dissolve_alpha.shader 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
  2. Shader "Unity5/Particle Softrim Dissolve/Alpha Blend"
  3. {
  4. Properties {
  5. _MainTex ("Particle Texture", 2D) = "white" {}
  6. _Opacity ("Opacity", Range (0,1)) = 1
  7. _SoftRim ("Rim", Range(0,1.5)) = 1
  8. _EdgeColor ("Edge Color", Color) = (1,0,0)
  9. _EdgeWidth ("Edge Width", Range(0,1)) = 0.1
  10. _EdgeRamp ("Edge Ramp", 2D) = "white" {}
  11. }
  12. Category {
  13. Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
  14. //Blend One One
  15. //Blend SrcAlpha One
  16. Blend SrcAlpha OneMinusSrcAlpha
  17. Cull Off Lighting Off ZWrite Off
  18. SubShader {
  19. Pass {
  20. CGPROGRAM
  21. #pragma vertex vert
  22. #pragma fragment frag
  23. #pragma multi_compile SOFTDISSOLVE_ON SOFTDISSOLVE_OFF
  24. #pragma multi_compile OPACITYSLIDER_ON OPACITYSLIDER_OFF
  25. #pragma multi_compile STRETCH_ON STRETCH_OFF
  26. #pragma multi_compile SOFTRIM_ON SOFTRIM_OFF
  27. #pragma multi_compile EDGE_ON EDGE_OFF
  28. #include "UnityCG.cginc"
  29. sampler2D _MainTex;
  30. #if EDGE_ON
  31. sampler2D _EdgeRamp;
  32. #endif
  33. struct appdata_t {
  34. fixed4 vertex : POSITION;
  35. fixed4 color : COLOR;
  36. fixed2 texcoord : TEXCOORD0;
  37. #if SOFTRIM_ON
  38. fixed4 normal : NORMAL;
  39. #endif
  40. };
  41. struct v2f {
  42. fixed4 vertex : SV_POSITION;
  43. fixed4 color : COLOR;
  44. fixed2 texcoord : TEXCOORD0;
  45. };
  46. fixed4 _MainTex_ST;
  47. #if OPACITYSLIDER_ON
  48. fixed _Opacity;
  49. #endif
  50. #if SOFTRIM_ON
  51. fixed _SoftRim;
  52. #endif
  53. #if EDGE_ON
  54. fixed3 _EdgeColor;
  55. fixed _EdgeWidth;
  56. fixed4 _EdgeRamp_ST;
  57. #endif
  58. v2f vert (appdata_t v)
  59. {
  60. v2f o;
  61. o.vertex = UnityObjectToClipPos(v.vertex);
  62. #if SOFTRIM_ON
  63. fixed3 viewDir = normalize(ObjSpaceViewDir(v.vertex));
  64. #if STRETCH_ON
  65. //viewDir.x = -abs(viewDir.x);
  66. //viewDir.y = abs(viewDir.y);
  67. //viewDir.z = abs(viewDir.z);
  68. viewDir.x = 1;
  69. viewDir.y = 1;
  70. viewDir.z = 1;
  71. //v.normal.x = -abs(v.normal.x);
  72. //v.normal.y = -abs(v.normal.y);
  73. //v.normal.z = abs(v.normal.z);
  74. v.normal.x = 0;
  75. v.normal.y = -abs(v.normal.y);
  76. v.normal.z = 1;
  77. #endif
  78. fixed dotProduct = dot(v.normal, viewDir);
  79. o.color.rgb = v.color.rgb;
  80. o.color.a = smoothstep(1 - _SoftRim, 1.0, dotProduct)*v.color.a;
  81. #else
  82. o.color = v.color;
  83. #endif
  84. o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex);
  85. return o;
  86. }
  87. fixed4 frag (v2f i) : SV_Target
  88. {
  89. fixed4 tex = tex2D(_MainTex, i.texcoord);
  90. #if SOFTDISSOLVE_ON
  91. fixed sf = smoothstep(0,(1-tex.a),i.color.a);
  92. #else
  93. fixed sf = step(1-i.color.a,tex.a);
  94. #endif
  95. #if EDGE_ON
  96. #if SOFTDISSOLVE_ON
  97. if (sf < _EdgeWidth && sf > i.color.a)
  98. {
  99. //sf=1;
  100. //tex.rgb = _EdgeColor;
  101. fixed4 ramp = tex2D (_EdgeRamp, fixed2(sf,1));
  102. tex.rgb = ramp.rgb*_EdgeColor;
  103. }
  104. #else
  105. if (tex.a*i.color.a<_EdgeWidth && sf > i.color.a)
  106. {
  107. sf=tex.a;
  108. fixed4 ramp = tex2D (_EdgeRamp, fixed2(tex.a*i.color.a,1));
  109. //tex.rgb = _EdgeColor;
  110. tex.rgb = ramp.rgb*_EdgeColor;
  111. }
  112. #endif
  113. #endif
  114. #if OPACITYSLIDER_ON
  115. clip(sf*tex.a*_Opacity);
  116. return fixed4(tex.rgb*i.color.rgb,sf*tex.a*_Opacity);
  117. #else
  118. clip(sf*tex.a);
  119. return fixed4(tex.rgb*i.color.rgb,sf*tex.a);
  120. #endif
  121. }
  122. ENDCG
  123. }
  124. }CustomEditor "Shader_softrim_dissolve"
  125. }
  126. }