Wave.shader 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. Shader "YXJ/Unlit/Wave"
  2. {
  3. Properties
  4. {
  5. _MainTex("Base (RGB)", 2D) = "white" {}
  6. _Color("Tint", Color) = (1,1,1,1)
  7. _ColorStrength("ColorStrength",Float) = 0
  8. _WaveStrength("Wave Strength",Float) = 0.01
  9. _WaveFactor("Wave Factor",Float) = 50
  10. _TimeScale("Time Scale",Float) = 10
  11. _Fade("Fade",Float) = 1
  12. }
  13. SubShader
  14. {
  15. Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
  16. Blend SrcAlpha OneMinusSrcAlpha
  17. ColorMask RGB
  18. Cull [_Cull] Lighting Off ZWrite Off
  19. Pass
  20. {
  21. ZTest Greater
  22. CGPROGRAM
  23. #pragma vertex vert
  24. #pragma fragment frag
  25. struct appdata
  26. {
  27. float4 vertex : POSITION;
  28. float2 uv : TEXCOORD0;
  29. };
  30. struct v2f {
  31. float4 vertex:SV_POSITION;
  32. float2 uv:TEXCOORD0;
  33. };
  34. sampler2D _MainTex;
  35. fixed4 _Color;
  36. float _WaveStrength;
  37. float _WaveFactor;
  38. float _TimeScale;
  39. float _Fade;
  40. float _ColorStrength;
  41. v2f vert(appdata v)
  42. {
  43. v2f o;
  44. o.uv = v.uv;
  45. o.vertex = UnityObjectToClipPos(v.vertex);
  46. return o;
  47. }
  48. fixed4 frag(v2f IN) :COLOR
  49. {
  50. fixed2 uvDir = normalize(IN.uv - fixed2(0.5, 0.5));
  51. fixed dis = distance(IN.uv, fixed2(0.5, 0.5));
  52. fixed2 uv = IN.uv + _WaveStrength * uvDir * sin(_Time.y * _TimeScale + dis * _WaveFactor);
  53. fixed4 col = tex2D(_MainTex, uv) * _Color * sin(1 - abs(2 * IN.uv.x - 1) + _Fade) * sin (1 - abs(2 * IN.uv.y - 1) + _Fade) * _ColorStrength;
  54. col.a *= 0.5;
  55. return col;
  56. }
  57. ENDCG
  58. }
  59. Pass
  60. {
  61. ZTest Less
  62. CGPROGRAM
  63. #pragma vertex vert
  64. #pragma fragment frag
  65. struct appdata
  66. {
  67. float4 vertex : POSITION;
  68. float2 uv : TEXCOORD0;
  69. };
  70. struct v2f {
  71. float4 vertex:SV_POSITION;
  72. float2 uv:TEXCOORD0;
  73. };
  74. sampler2D _MainTex;
  75. fixed4 _Color;
  76. float _WaveStrength;
  77. float _WaveFactor;
  78. float _TimeScale;
  79. float _Fade;
  80. float _ColorStrength;
  81. v2f vert(appdata v)
  82. {
  83. v2f o;
  84. o.uv = v.uv;
  85. o.vertex = UnityObjectToClipPos(v.vertex);
  86. return o;
  87. }
  88. fixed4 frag(v2f IN) :COLOR
  89. {
  90. fixed2 uvDir = normalize(IN.uv - fixed2(0.5, 0.5));
  91. fixed dis = distance(IN.uv, fixed2(0.5, 0.5));
  92. fixed2 uv = IN.uv + _WaveStrength * uvDir * sin(_Time.y * _TimeScale + dis * _WaveFactor);
  93. return tex2D(_MainTex, uv) * _Color * sin(1 - abs(2 * IN.uv.x - 1) + _Fade) * sin (1 - abs(2 * IN.uv.y - 1) + _Fade) * _ColorStrength;
  94. }
  95. ENDCG
  96. }
  97. }
  98. FallBack "Diffuse"
  99. }