WarpJumpDistortion.shader 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. Shader "FORGE3D/Warp Jump Distortion" {
  2. Properties {
  3. _TintColor("Tint", Color) = (1.0, 1.0, 1.0, 1.0)
  4. _Dist("Distortion ammount", Float) = 10.0
  5. _Normal("Distortion map", 2D) = "" {}
  6. _InvFade ("Soft Particles Factor", Range(0.01,3.0)) = 1.0
  7. }
  8. Category {
  9. Tags { "Queue"="Transparent" "RenderType"="Transparent" }
  10. Cull Back Lighting Off ZWrite Off
  11. Fog { Mode off }
  12. //ZTest LEqual
  13. SubShader {
  14. GrabPass {
  15. Name "BASE"
  16. Tags { "LightMode" = "Always" }
  17. }
  18. Pass {
  19. Name "BASE"
  20. Tags { "LightMode" = "Always" }
  21. Blend SrcAlpha OneMinusSrcAlpha
  22. AlphaTest Greater 0
  23. CGPROGRAM
  24. #pragma vertex vert
  25. #pragma fragment frag
  26. #pragma fragmentoption ARB_precision_hint_fastest
  27. #pragma multi_compile_particles
  28. #include "UnityCG.cginc"
  29. float4 _TintColor;
  30. float _Dist;
  31. sampler2D _Normal;
  32. sampler2D _CameraDepthTexture;
  33. float _InvFade;
  34. sampler2D _GrabTexture;
  35. float4 _GrabTexture_TexelSize;
  36. struct appdata_t {
  37. float4 vertex : POSITION;
  38. fixed4 color : COLOR;
  39. float2 texcoord: TEXCOORD0;
  40. };
  41. struct v2f {
  42. float4 vertex : POSITION;
  43. fixed4 color : COLOR;
  44. float4 uvgrab : TEXCOORD0;
  45. float2 uvmain : TEXCOORD1;
  46. float4 projPos : TEXCOORD2;
  47. };
  48. float4 _Normal_ST;
  49. v2f vert (appdata_t v)
  50. {
  51. v2f o;
  52. o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
  53. o.projPos = ComputeScreenPos (o.vertex);
  54. COMPUTE_EYEDEPTH(o.projPos.z);
  55. #if UNITY_UV_STARTS_AT_TOP
  56. float scale = -1.0;
  57. #else
  58. float scale = 1.0;
  59. #endif
  60. o.uvgrab.xy = (float2(o.vertex.x, o.vertex.y*scale) + o.vertex.w) * 0.5;
  61. o.uvgrab.zw = o.vertex.zw;
  62. o.uvmain = TRANSFORM_TEX( v.texcoord, _Normal );
  63. o.color = v.color;
  64. return o;
  65. }
  66. float4 frag(v2f i) : COLOR
  67. {
  68. float sceneZ = LinearEyeDepth (UNITY_SAMPLE_DEPTH(tex2Dproj(_CameraDepthTexture, UNITY_PROJ_COORD(i.projPos))));
  69. float partZ = i.projPos.z;
  70. float fade = saturate (_InvFade * (sceneZ-partZ));
  71. i.color.a *= fade;
  72. float4 packedTex = tex2D(_Normal, i.uvmain);
  73. float local1 = packedTex.z * 2.4;
  74. float2 local2 = packedTex.rg * 2.25;
  75. packedTex.rg = local1 * local2;
  76. half2 bump = UnpackNormal(packedTex).rg;
  77. float2 offset = bump * _Dist * _GrabTexture_TexelSize.xy;
  78. i.uvgrab.xy = offset * i.uvgrab.z + i.uvgrab.xy;
  79. half4 col = tex2Dproj( _GrabTexture, UNITY_PROJ_COORD(i.uvgrab));
  80. return float4(col.rgb, _TintColor.a * packedTex.a * i.color.a);
  81. }
  82. ENDCG
  83. }
  84. }
  85. }
  86. }