WarpTunnelDistortion.shader 2.8 KB

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