Particle Alpha Blend Smoothstep Blood Lit.shader 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
  2. Shader "Particles/Alpha Blended Smoothstep Blood Lit" {
  3. Properties {
  4. _Columns ("Flipbook Columns", int) = 1
  5. _Rows ("Flipbook Rows", int) = 1
  6. _TintColor ("Tint Color", Color) = (0.5,0.5,0.5,0.5)
  7. _ChannelMask ("Channel Mask Color", Color) = (0,0,0,1)
  8. _MainTex ("Particle Texture", 2D) = "white" {}
  9. _EdgeMin ("SmoothStep Edge Min", float) = 0.05
  10. _EdgeSoft ("SmoothStep Softness", float) = 0.05
  11. _NormalMap ("Normal Map", 2D) = "bump" {}
  12. _HighlightColor ("Highlight Color", Color) = (1,1,1,0)
  13. _Reflect ("Reflection Matcap", 2D) = "black" {}
  14. _Detail ("Detail Tex", 2D) = "gray" {}
  15. _DetailTile ("Detail Tiling", float) = 6.0
  16. _DetailPan ("Detail Alpha Pan", float) = 0.1
  17. _DetailAlphaAffect ("Detail Alpha Affect", float) = 1.0
  18. _DetailBrightAffect("Detail Brightness Affect", float) = 0.5
  19. _UVOff ("UV Offset Map", 2D) = "bump" {}
  20. _OffPow ("UV Offset Power", float) = 0.1
  21. _OffTile ("UV Offset Tiling", float) = 1.0
  22. _Overbright ("Overbright", float) = 0.0
  23. _InvFade ("Soft Particles Factor", Range(0.01,8.0)) = 3.0
  24. }
  25. Category {
  26. Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
  27. Blend SrcAlpha OneMinusSrcAlpha
  28. ColorMask RGB
  29. Cull Off Lighting Off ZWrite Off
  30. SubShader {
  31. Pass {
  32. CGPROGRAM
  33. #pragma vertex vert
  34. #pragma fragment frag
  35. #pragma multi_compile_particles
  36. #pragma multi_compile_fog
  37. #include "UnityCG.cginc"
  38. sampler2D _MainTex;
  39. sampler2D _Detail;
  40. sampler2D _NormalMap;
  41. sampler2D _UVOff;
  42. sampler2D _Reflect;
  43. fixed4 _TintColor;
  44. fixed4 _ChannelMask;
  45. fixed4 _HighlightColor;
  46. fixed _EdgeMin;
  47. fixed _EdgeSoft;
  48. fixed _Overbright;
  49. fixed _DetailTile;
  50. fixed _DetailPan;
  51. fixed _OffPow;
  52. fixed _OffTile;
  53. fixed _DetailBrightAffect;
  54. fixed _DetailAlphaAffect;
  55. fixed _Columns;
  56. fixed _Rows;
  57. fixed4 _LightColor0;
  58. struct appdata_t {
  59. float4 vertex : POSITION;
  60. fixed4 color : COLOR;
  61. float2 texcoord : TEXCOORD0;
  62. };
  63. struct v2f {
  64. float4 vertex : SV_POSITION;
  65. fixed4 color : COLOR;
  66. float2 texcoord : TEXCOORD0;
  67. UNITY_FOG_COORDS(1)
  68. #ifdef SOFTPARTICLES_ON
  69. float4 projPos : TEXCOORD2;
  70. #endif
  71. };
  72. float4 _MainTex_ST;
  73. v2f vert (appdata_t v)
  74. {
  75. v2f o;
  76. o.vertex = UnityObjectToClipPos(v.vertex);
  77. #ifdef SOFTPARTICLES_ON
  78. o.projPos = ComputeScreenPos (o.vertex);
  79. COMPUTE_EYEDEPTH(o.projPos.z);
  80. #endif
  81. o.color = v.color;
  82. o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex);
  83. UNITY_TRANSFER_FOG(o,o.vertex);
  84. return o;
  85. }
  86. sampler2D_float _CameraDepthTexture;
  87. float _InvFade;
  88. fixed4 frag (v2f i) : SV_Target
  89. {
  90. #ifdef SOFTPARTICLES_ON
  91. float sceneZ = LinearEyeDepth (SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(i.projPos)));
  92. float partZ = i.projPos.z;
  93. float fade = saturate (_InvFade * (sceneZ-partZ));
  94. i.color.a *= fade;
  95. #endif
  96. //Calculate General Scene Illumination
  97. float3 lightColor = _LightColor0.rgb + UNITY_LIGHTMODEL_AMBIENT.rgb;
  98. //Create a mask to reign in the effects of the UV Offset ------------------------------- NOT DONE (replace with mask texture?)
  99. fixed edgeMask = 1 - distance(i.texcoord, fixed2(0.5,0.5));
  100. edgeMask = saturate(2 * frac(_Rows*i.texcoord.x));
  101. edgeMask *= saturate(2 * frac(-_Rows*i.texcoord.x));
  102. edgeMask *= saturate(2 * frac(_Columns*i.texcoord.y));
  103. edgeMask *= saturate(2 * frac(-_Columns*i.texcoord.y));
  104. //Caluculate UV Offset.
  105. //Detail texture can have its position randomized or be animated by changing the brigness of the green channel value.
  106. fixed4 UVOff = tex2D(_UVOff, (i.texcoord + fixed2(i.color.y * 154.6, i.color.y * 798.3)) * _OffTile) * 2 - 1;
  107. fixed2 UVOff2 = 0.1 * fixed2(UVOff.g * _OffPow, UVOff.a * _OffPow) * edgeMask;
  108. //Manually unpack normal
  109. fixed4 normalMap4 = (tex2D(_NormalMap, i.texcoord + UVOff2));
  110. fixed3 normalMap = UnpackNormal(normalMap4) * 0.5 + 0.5;
  111. //Calculate Detail Texture.
  112. //Detail texture can have its position randomized or be animated by changing the brigness of the green channel value.
  113. fixed4 detail = tex2D(_Detail, _DetailTile * i.texcoord + fixed2(i.color.y * 1.32 + i.color.a * _DetailPan, 0) + UVOff2);
  114. detail.a = lerp(1, detail.a, _DetailAlphaAffect);
  115. detail.a *= lerp(1, detail.rgb, _DetailAlphaAffect);
  116. detail.rgb = lerp((1 - detail.rgb), detail.rgb, _DetailBrightAffect + 0.5);
  117. //Read main texture and declare col. Make sure that tex has an alpha channel.
  118. //If needed, use unity's "alpha from brightness" option on the texture import settings.
  119. fixed4 tex = tex2D(_MainTex, i.texcoord + UVOff2);
  120. fixed4 col = fixed4(_TintColor.rgb, 1);
  121. tex.a = length(tex * _ChannelMask);
  122. // return tex;
  123. //
  124. col.a *= tex.a * i.color.a * detail.a;
  125. //Read Matcap. Lighting brigtness can be set with the brightness of the red channel value.
  126. fixed3 matcap = tex2D(_Reflect, lerp(normalMap.xy, normalMap.xy * 1.5, detail.a));
  127. fixed3 highlight = i.color.b * lightColor * matcap * _HighlightColor.rgb * 2;
  128. col.a = smoothstep(_EdgeMin, _EdgeMin + _EdgeSoft, col.a);
  129. col.rgb = col.rgb * detail.rgb * i.color.r * (_Overbright + 1);
  130. col = fixed4(highlight + col.rgb * lightColor, col.a * _TintColor.a + length(highlight * col.a)*0.5);
  131. UNITY_APPLY_FOG(i.fogCoord, col);
  132. //
  133. // return float4(i.color.rgb, col.a);
  134. // return float4(UVOff2 * 0.5 + 0.5, 0, col.a);
  135. return col;
  136. }
  137. ENDCG
  138. }
  139. }
  140. }
  141. }
  142. //Shader "Particles/Alpha Blended Smoothstep detail" {
  143. //Properties {
  144. // _TintColor ("Tint Color", Color) = (0.5,0.5,0.5,0.5)
  145. // _MainTex ("Particle Texture", 2D) = "white" {}
  146. // _NormalTex ("Normal Texture", 2D) = "bump" {} //
  147. //
  148. // _Detail ("detail", 2D) = "white" {}
  149. // _DetailTile ("detail Tiling", float) = 1.0
  150. // _EdgeMin ("Edge Min", float) = 0.2
  151. // _EdgeSoft ("Edge Softness", float) = 0.1
  152. //
  153. // _LightDir ("Light Direction", Color) = (0,1,0,0)
  154. // _HighSharp ("Highlight Sharpness", float) = 1.0
  155. // _Overbright ("Overbright", float) = 2.0
  156. // _InvFade ("Soft Particles Factor", Range(0.01,3.0)) = 1.0
  157. //}
  158. //
  159. //Category {
  160. // Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
  161. // Blend SrcAlpha OneMinusSrcAlpha
  162. // ColorMask RGB
  163. // Cull Off Lighting Off ZWrite Off
  164. //
  165. // SubShader {
  166. // Pass {
  167. //
  168. // CGPROGRAM
  169. // #pragma vertex vert
  170. // #pragma fragment frag
  171. // #pragma multi_compile_particles
  172. // #pragma multi_compile_fog
  173. //
  174. // #include "UnityCG.cginc"
  175. //
  176. // sampler2D _MainTex;
  177. // sampler2D _Detail;
  178. // sampler2D _NormalTex; //
  179. // fixed4 _TintColor;
  180. // fixed4 _LightDir;
  181. // fixed _EdgeMin;
  182. // fixed _EdgeSoft;
  183. // fixed _Overbright;
  184. // fixed _DetailTile;
  185. // fixed _HighSharp;
  186. //
  187. // struct appdata_t {
  188. // float4 vertex : POSITION;
  189. // fixed4 color : COLOR;
  190. // float2 texcoord : TEXCOORD0;
  191. // float3 normal : NORMAL; //
  192. // float4 tangent : TANGENT; //
  193. // };
  194. //
  195. // struct v2f {
  196. // float4 vertex : SV_POSITION;
  197. // fixed4 color : COLOR;
  198. // float2 texcoord : TEXCOORD0;
  199. // UNITY_FOG_COORDS(1)
  200. // #ifdef SOFTPARTICLES_ON
  201. // float4 projPos : TEXCOORD2;
  202. // #endif
  203. // float3 normalWorld : TEXCOORD3;//
  204. // float3 tangentWorld : TEXCOORD4;//
  205. // float3 binormalWorld : TEXCOORD5;//
  206. // };
  207. //
  208. // float4 _MainTex_ST;
  209. //
  210. // v2f vert (appdata_t v)
  211. // {
  212. //
  213. // v2f o;
  214. // o.normalWorld = normalize(mul(float4(v.normal, 0.0), _World2Object).xyz); //
  215. // o.tangentWorld = normalize(mul(_Object2World, v.tangent).xyz); //
  216. // o.binormalWorld = normalize(cross(o.normalWorld, o.tangentWorld) * v.tangent.w); //
  217. //
  218. // o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
  219. // #ifdef SOFTPARTICLES_ON
  220. // o.projPos = ComputeScreenPos (o.vertex);
  221. // COMPUTE_EYEDEPTH(o.projPos.z);
  222. // #endif
  223. // o.color = v.color;
  224. // o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex);
  225. // UNITY_TRANSFER_FOG(o,o.vertex);
  226. // return o;
  227. // }
  228. //
  229. // sampler2D_float _CameraDepthTexture;
  230. // float _InvFade;
  231. //
  232. // fixed4 frag (v2f i) : SV_Target
  233. // {
  234. // #ifdef SOFTPARTICLES_ON
  235. // float sceneZ = LinearEyeDepth (SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(i.projPos)));
  236. // float partZ = i.projPos.z;
  237. // float fade = saturate (_InvFade * (sceneZ-partZ));
  238. // i.color.a *= fade;
  239. // #endif
  240. //
  241. // fixed4 tex = tex2D(_MainTex, i.texcoord);
  242. // fixed4 col = i.color.r * _TintColor;
  243. // fixed4 detail = tex2D(_Detail, _DetailTile * i.texcoord + fixed2(i.color.y, 0));
  244. // fixed3 norm = UnpackNormal(tex2D(_NormalTex, _DetailTile * i.texcoord + fixed2(i.color.y, 0)));
  245. // col.rgb += float3(4,4,4) * i.color.b * pow(clamp(dot(norm, _LightDir),0,1), 16 * _HighSharp) * _HighSharp;
  246. // col.a *= tex.a * i.color.a;
  247. // col.a = smoothstep(_EdgeMin, _EdgeMin + _EdgeSoft, col.a);
  248. // col.rgb = col.rgb * detail.rgb;
  249. // UNITY_APPLY_FOG(i.fogCoord, col);
  250. // return fixed4(col.rgb * _Overbright, col.a);
  251. // }
  252. // ENDCG
  253. // }
  254. // }
  255. //}
  256. //}