WarpTunnelDistortion.shader 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. // Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
  2. Shader "FORGE3D/Warp Tunnel Distortion" {
  3. Properties {
  4. _TintColor ("Tint Color", Color) = (0.5,0.5,0.5,0.5)
  5. _Speed("UV Speed", Float) = 1.0
  6. _WiggleX("_WiggleX", Float) = 1.0
  7. _WiggleY("_WiggleY", Float) = 1.0
  8. _WiggleDist("Wiggle distance", Float) = 1.0
  9. _Offset("Vertex offset", float) = 0
  10. _TintColor("Tint", Color) = (1.0, 1.0, 1.0, 1.0)
  11. _MainTex("Distortion map", 2D) = "" {}
  12. _Dist("Distortion ammount", Float) = 10.0
  13. }
  14. Category {
  15. Tags { "Queue"="Transparent+1" "RenderType"="Transparent" }
  16. Cull Back Lighting Off ZWrite Off
  17. Fog { Color (0,0,0,0) }
  18. ZTest LEqual
  19. SubShader {
  20. GrabPass {
  21. Name "BASE"
  22. Tags { "LightMode" = "Always" }
  23. }
  24. Pass {
  25. CGPROGRAM
  26. #pragma vertex vert
  27. #pragma fragment frag
  28. #pragma multi_compile_particles
  29. #include "UnityCG.cginc"
  30. sampler2D _MainTex;
  31. fixed4 _TintColor;
  32. struct appdata_t {
  33. float4 vertex : POSITION;
  34. fixed4 color : COLOR;
  35. float2 texcoord : TEXCOORD0;
  36. float4 normal : NORMAL;
  37. };
  38. struct v2f {
  39. float4 vertex : SV_POSITION;
  40. fixed4 color : COLOR;
  41. float2 texcoord : TEXCOORD0;
  42. float4 posWorld : TEXCOORD1;
  43. float4 uvgrab : TEXCOORD2;
  44. float4 projPos : TEXCOORD3;
  45. };
  46. float4 _MainTex_ST;
  47. float _Speed;
  48. float _WiggleX, _WiggleY, _WiggleDist;
  49. float _Offset;
  50. float _Dist;
  51. sampler2D _CameraDepthTexture;
  52. float _InvFade;
  53. sampler2D _GrabTexture;
  54. float4 _GrabTexture_TexelSize;
  55. v2f vert (appdata_t v)
  56. {
  57. v2f o;
  58. o.posWorld = mul(unity_ObjectToWorld, v.vertex);
  59. v.vertex.xyz += normalize(v.normal.xyz) * _Offset;
  60. o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
  61. o.vertex.x += sin(_Time.y * _WiggleX) * _WiggleDist;
  62. o.vertex.y -= sin(_Time.y * _WiggleY) * _WiggleDist;
  63. o.color = v.color;
  64. o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex);
  65. o.projPos = ComputeScreenPos (o.vertex);
  66. COMPUTE_EYEDEPTH(o.projPos.z);
  67. #if UNITY_UV_STARTS_AT_TOP
  68. float scale = -1.0;
  69. #else
  70. float scale = 1.0;
  71. #endif
  72. o.uvgrab.xy = (float2(o.vertex.x, o.vertex.y*scale) + o.vertex.w) * 0.5;
  73. o.uvgrab.zw = o.vertex.zw;
  74. return o;
  75. }
  76. fixed4 frag (v2f i) : SV_Target
  77. {
  78. i.texcoord.y += _Time.x * _Speed;
  79. float4 packedTex = tex2D(_MainTex, i.texcoord);
  80. float local1 = packedTex.z * 2.4;
  81. float2 local2 = packedTex.rg * 2.25;
  82. packedTex.rg = local1 * local2;
  83. half2 bump = UnpackNormal(packedTex).rg;
  84. float2 offset = bump * _Dist * _GrabTexture_TexelSize.xy;
  85. i.uvgrab.xy = offset * i.uvgrab.z + i.uvgrab.xy;
  86. half4 col = tex2Dproj( _GrabTexture, UNITY_PROJ_COORD(i.uvgrab));
  87. return col;
  88. }
  89. ENDCG
  90. }
  91. }
  92. }
  93. }