DistortionCullBack.shader 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
  2. // Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
  3. Shader "Portals/Distortion" {
  4. Properties {
  5. [HDR]_TintColor ("Tint Color", Color) = (1,1,1,1)
  6. _MainTex ("Base (RGB) Gloss (A)", 2D) = "black" {}
  7. _BumpMap ("Normalmap", 2D) = "bump" {}
  8. _BumpAmt ("Distortion", Float) = 10
  9. _InvFade ("Soft Particles Factor", Range(0,10)) = 1.0
  10. }
  11. Category {
  12. Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
  13. Blend SrcAlpha OneMinusSrcAlpha
  14. Cull Off
  15. Lighting Off
  16. ZWrite Off
  17. Fog { Mode Off}
  18. SubShader {
  19. GrabPass {
  20. // "_GrabTexture"
  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. fixed4 color : COLOR;
  44. //#ifdef SOFTPARTICLES_ON
  45. float4 projPos : TEXCOORD3;
  46. //#endif
  47. };
  48. sampler2D _MainTex;
  49. sampler2D _BumpMap;
  50. float _BumpAmt;
  51. sampler2D _GrabTexture;
  52. float4 _GrabTexture_TexelSize;
  53. fixed4 _TintColor;
  54. float4 _BumpMap_ST;
  55. float4 _MainTex_ST;
  56. v2f vert (appdata_t v)
  57. {
  58. v2f o;
  59. o.vertex = UnityObjectToClipPos(v.vertex);
  60. //#ifdef SOFTPARTICLES_ON
  61. o.projPos = ComputeScreenPos (o.vertex);
  62. COMPUTE_EYEDEPTH(o.projPos.z);
  63. //#endif
  64. o.color = v.color;
  65. #if UNITY_UV_STARTS_AT_TOP
  66. float scale = -1.0;
  67. #else
  68. float scale = 1.0;
  69. #endif
  70. o.uvgrab.xy = (float2(o.vertex.x, o.vertex.y*scale) + o.vertex.w) * 0.5;
  71. o.uvgrab.zw = o.vertex.w;
  72. #if UNITY_SINGLE_PASS_STEREO
  73. o.uvgrab.xy = TransformStereoScreenSpaceTex(o.uvgrab.xy, o.uvgrab.w);
  74. #endif
  75. o.uvgrab.z /= distance(_WorldSpaceCameraPos, mul(unity_ObjectToWorld, v.vertex))/10;
  76. o.uvbump = TRANSFORM_TEX( v.texcoord, _BumpMap );
  77. o.uvmain = TRANSFORM_TEX( v.texcoord, _MainTex );
  78. return o;
  79. }
  80. sampler2D _CameraDepthTexture;
  81. float _InvFade;
  82. half4 frag(v2f i) : COLOR
  83. {
  84. //#ifdef SOFTPARTICLES_ON
  85. float sceneZ = LinearEyeDepth(UNITY_SAMPLE_DEPTH(tex2Dproj(_CameraDepthTexture, UNITY_PROJ_COORD(i.projPos))));
  86. float partZ = i.projPos.z;
  87. float fade = 1-saturate(_InvFade * (sceneZ - partZ));
  88. if (_InvFade < 0.001) fade = 0;
  89. //i.color.a *= fade;
  90. //#endif
  91. half2 bump = UnpackNormal(tex2D( _BumpMap, i.uvbump )).rg;
  92. float2 offset = bump * _BumpAmt * _GrabTexture_TexelSize.xy;
  93. i.uvgrab.xy = offset * i.uvgrab.z + i.uvgrab.xy;
  94. half4 col = tex2Dproj( _GrabTexture, UNITY_PROJ_COORD(i.uvgrab));
  95. fixed4 tex = tex2D(_MainTex, i.uvmain) * i.color;
  96. fixed4 emission = col * i.color + tex * _TintColor + fade * _TintColor;
  97. emission.a = _TintColor.a * i.color.a;
  98. return emission;
  99. }
  100. ENDCG
  101. }
  102. }
  103. }
  104. }