xft_displacement_screen.shader 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
  2. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
  3. Shader "Xffect/displacement/screen" {
  4. Properties {
  5. _DispMap ("Displacement Map (RG)", 2D) = "white" {}
  6. _MaskTex ("Mask (R)", 2D) = "white" {}
  7. _DispScrollSpeedX ("Map Scroll Speed X", Float) = 0
  8. _DispScrollSpeedY ("Map Scroll Speed Y", Float) = 0
  9. _StrengthX ("Displacement Strength X", Float) = 1
  10. _StrengthY ("Displacement Strength Y", Float) = -1
  11. }
  12. Category {
  13. Tags { "Queue"="Transparent+99" "RenderType"="Transparent" }
  14. Blend SrcAlpha OneMinusSrcAlpha
  15. //AlphaTest Greater .01
  16. Cull Off Lighting Off ZWrite Off ZTest Always
  17. BindChannels {
  18. Bind "Color", color
  19. Bind "Vertex", vertex
  20. Bind "TexCoord", texcoord
  21. }
  22. SubShader {
  23. GrabPass {
  24. Name "BASE"
  25. Tags { "LightMode" = "Always" }
  26. }
  27. Pass {
  28. Name "BASE"
  29. Tags { "LightMode" = "Always" }
  30. CGPROGRAM
  31. #pragma vertex vert
  32. #pragma fragment frag
  33. #pragma fragmentoption ARB_precision_hint_fastest
  34. #include "UnityCG.cginc"
  35. struct appdata_t {
  36. float4 vertex : POSITION;
  37. fixed4 color : COLOR;
  38. float2 texcoord: TEXCOORD0;
  39. float2 param : TEXCOORD1;
  40. };
  41. struct v2f {
  42. float4 vertex : POSITION;
  43. fixed4 color : COLOR;
  44. float2 uvmain : TEXCOORD0;
  45. float2 param : TEXCOORD1;
  46. float4 uvgrab : TEXCOORD2;
  47. };
  48. uniform half _StrengthX;
  49. uniform half _StrengthY;
  50. uniform float4 _DispMap_ST;
  51. uniform sampler2D _DispMap;
  52. uniform sampler2D _MaskTex;
  53. uniform half _DispScrollSpeedY;
  54. uniform half _DispScrollSpeedX;
  55. v2f vert (appdata_t v)
  56. {
  57. v2f o;
  58. o.vertex = UnityObjectToClipPos(v.vertex);
  59. #if UNITY_UV_STARTS_AT_TOP
  60. float scale = -1.0;
  61. #else
  62. float scale = 1.0;
  63. #endif
  64. o.uvgrab.xy = (float2(o.vertex.x, o.vertex.y*scale) + o.vertex.w) * 0.5;
  65. o.uvgrab.zw = o.vertex.zw;
  66. o.uvmain = TRANSFORM_TEX( v.texcoord, _DispMap );
  67. o.color = v.color;
  68. o.param = v.param;
  69. return o;
  70. }
  71. sampler2D _GrabTexture;
  72. half4 frag( v2f i ) : COLOR
  73. {
  74. //scroll displacement map.
  75. half2 mapoft = half2(_Time.y*_DispScrollSpeedX, _Time.y*_DispScrollSpeedY);
  76. //get displacement color
  77. half4 offsetColor = tex2D(_DispMap, i.uvmain + mapoft);
  78. //get offset
  79. half oftX = offsetColor.r * _StrengthX * i.param.x;
  80. half oftY = offsetColor.g * _StrengthY * i.param.x;
  81. i.uvgrab.x += oftX;
  82. i.uvgrab.y += oftY;
  83. half4 col = tex2Dproj( _GrabTexture, UNITY_PROJ_COORD(i.uvgrab));
  84. //intensity is controlled by particle color.
  85. col.a = i.color.a;
  86. //use mask's red channel to determine visibility.
  87. fixed4 tint = tex2D( _MaskTex, i.uvmain );
  88. col.a *= tint.r;
  89. return col;
  90. }
  91. ENDCG
  92. }
  93. }
  94. // ------------------------------------------------------------------
  95. // Fallback for older cards and Unity non-Pro
  96. SubShader {
  97. Blend SrcAlpha OneMinusSrcAlpha
  98. Pass {
  99. Name "BASE"
  100. SetTexture [_MainTex] { combine texture * primary double, texture * primary }
  101. }
  102. }
  103. }
  104. }