DistortionParticlesCutout.shader 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
  2. Shader "Effects/Distortion/ParticlesCutOut" {
  3. Properties {
  4. _TintColor ("Tint Color", Color) = (1,1,1,1)
  5. _MainTex ("Base (RGB) Gloss (A)", 2D) = "black" {}
  6. _CutOut ("CutOut (A)", 2D) = "black" {}
  7. _BumpMap ("Normalmap", 2D) = "bump" {}
  8. _ColorStrength ("Color Strength", Float) = 1
  9. _BumpAmt ("Distortion", Float) = 10
  10. _InvFade ("Soft Particles Factor", Range(0,10)) = 1.0
  11. }
  12. Category {
  13. Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Opaque" }
  14. Blend SrcAlpha OneMinusSrcAlpha
  15. Cull Off
  16. Lighting Off
  17. ZWrite Off
  18. Fog { Mode Off}
  19. SubShader {
  20. GrabPass {
  21. Name "BASE"
  22. Tags { "LightMode" = "Always" }
  23. }
  24. Pass {
  25. Name "BASE"
  26. Tags { "LightMode" = "Always" }
  27. CGPROGRAM
  28. #pragma vertex vert
  29. #pragma fragment frag
  30. #pragma fragmentoption ARB_precision_hint_fastest
  31. #pragma multi_compile_particles
  32. #include "UnityCG.cginc"
  33. struct appdata_t {
  34. float4 vertex : POSITION;
  35. float2 texcoord: TEXCOORD0;
  36. fixed4 color : COLOR;
  37. };
  38. struct v2f {
  39. float4 vertex : POSITION;
  40. float4 uvgrab : TEXCOORD0;
  41. float2 uvbump : TEXCOORD1;
  42. float2 uvmain : TEXCOORD2;
  43. float2 uvcutout : TEXCOORD3;
  44. fixed4 color : COLOR;
  45. #ifdef SOFTPARTICLES_ON
  46. float4 projPos : TEXCOORD4;
  47. #endif
  48. };
  49. sampler2D _MainTex;
  50. sampler2D _CutOut;
  51. sampler2D _BumpMap;
  52. float _BumpAmt;
  53. float _ColorStrength;
  54. sampler2D _GrabTexture;
  55. float4 _GrabTexture_TexelSize;
  56. fixed4 _TintColor;
  57. float4 _BumpMap_ST;
  58. float4 _MainTex_ST;
  59. float4 _CutOut_ST;
  60. v2f vert (appdata_t v)
  61. {
  62. v2f o;
  63. o.vertex = UnityObjectToClipPos(v.vertex);
  64. #ifdef SOFTPARTICLES_ON
  65. o.projPos = ComputeScreenPos (o.vertex);
  66. COMPUTE_EYEDEPTH(o.projPos.z);
  67. #endif
  68. o.color = v.color;
  69. #if UNITY_UV_STARTS_AT_TOP
  70. float scale = -1.0;
  71. #else
  72. float scale = 1.0;
  73. #endif
  74. o.uvgrab.xy = (float2(o.vertex.x, o.vertex.y*scale) + o.vertex.w) * 0.5;
  75. o.uvgrab.zw = o.vertex.w;
  76. o.uvbump = TRANSFORM_TEX( v.texcoord, _BumpMap );
  77. o.uvmain = TRANSFORM_TEX( v.texcoord, _MainTex );
  78. o.uvcutout = TRANSFORM_TEX( v.texcoord, _CutOut );
  79. return o;
  80. }
  81. sampler2D _CameraDepthTexture;
  82. float _InvFade;
  83. half4 frag( v2f i ) : COLOR
  84. {
  85. #ifdef SOFTPARTICLES_ON
  86. if(_InvFade > 0.0001) {
  87. float sceneZ = LinearEyeDepth (UNITY_SAMPLE_DEPTH(tex2Dproj(_CameraDepthTexture, UNITY_PROJ_COORD(i.projPos))));
  88. float partZ = i.projPos.z;
  89. float fade = saturate (_InvFade * (sceneZ-partZ));
  90. i.color.a *= fade;
  91. }
  92. #endif
  93. // calculate perturbed coordinates
  94. half2 bump = UnpackNormal(tex2D( _BumpMap, i.uvbump )).rg;
  95. float2 offset = bump * _BumpAmt * _GrabTexture_TexelSize.xy;
  96. i.uvgrab.xy = offset * i.uvgrab.z + i.uvgrab.xy;
  97. half4 col = tex2Dproj( _GrabTexture, UNITY_PROJ_COORD(i.uvgrab));
  98. //half4 tint = tex2D( _MainTex, i.uvmain );
  99. //return col * tint;
  100. fixed4 tex = tex2D(_MainTex, i.uvmain) * i.color;
  101. fixed4 cut = tex2D(_CutOut, i.uvcutout) * i.color;
  102. fixed4 emission = col * i.color + tex * _ColorStrength * _TintColor;
  103. emission.a = _TintColor.a * i.color.a * (cut.a);
  104. return emission;
  105. }
  106. ENDCG
  107. }
  108. }
  109. SubShader {
  110. Blend DstColor Zero
  111. Pass {
  112. Name "BASE"
  113. SetTexture [_MainTex] { combine texture }
  114. }
  115. }
  116. }
  117. }