VortexEffect.shader 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
  2. Shader "Hidden/Twist Effect" {
  3. Properties {
  4. _MainTex ("Base (RGB)", 2D) = "white" {}
  5. }
  6. SubShader
  7. {
  8. Pass
  9. {
  10. ZTest Always Cull Off ZWrite Off
  11. Fog { Mode off }
  12. CGPROGRAM
  13. #pragma vertex vert
  14. #pragma fragment frag
  15. #pragma fragmentoption ARB_precision_hint_fastest
  16. #include "UnityCG.cginc"
  17. uniform sampler2D _MainTex;
  18. uniform float4 _MainTex_ST;
  19. uniform float4 _MainTex_TexelSize;
  20. uniform float _Angle;
  21. uniform float4 _CenterRadius;
  22. struct v2f {
  23. float4 pos : POSITION;
  24. float2 uv : TEXCOORD0;
  25. float2 uvOrig : TEXCOORD1;
  26. };
  27. v2f vert (appdata_img v)
  28. {
  29. v2f o;
  30. o.pos = UnityObjectToClipPos(v.vertex);
  31. float2 uv = v.texcoord.xy - _CenterRadius.xy;
  32. o.uv = TRANSFORM_TEX(uv, _MainTex); //MultiplyUV (UNITY_MATRIX_TEXTURE0, uv);
  33. o.uvOrig = uv;
  34. return o;
  35. }
  36. float4 frag (v2f i) : COLOR
  37. {
  38. float2 offset = i.uvOrig;
  39. float angle = 1.0 - length(offset / _CenterRadius.zw);
  40. angle = max (0, angle);
  41. angle = angle * angle * _Angle;
  42. float cosLength, sinLength;
  43. sincos (angle, sinLength, cosLength);
  44. float2 uv;
  45. uv.x = cosLength * offset[0] - sinLength * offset[1];
  46. uv.y = sinLength * offset[0] + cosLength * offset[1];
  47. uv += _CenterRadius.xy;
  48. return tex2D(_MainTex, uv);
  49. }
  50. ENDCG
  51. }
  52. }
  53. Fallback off
  54. }