Yanling.shader 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. Shader "Custom/YanlingShader" {
  2. Properties {
  3. _MainTex ("贴图", 2D) = "white" {}
  4. _Cutout("透明剔除值",Float) = 0.1
  5. _SwirlArea("区域", Vector) = (400,800,0,0)
  6. _SwirlCenterXPercent("扭曲中心X偏移比例", Range(0,1)) = 0.5
  7. _SwirlCenterYPercent("扭曲中心Y偏移比例", Range(0,1)) = 0.3
  8. _Radius("扭曲半径", Float) = 400
  9. _SwirlValue("扭曲程度", Float) = 1
  10. }
  11. SubShader {
  12. Blend SrcAlpha OneMinusSrcAlpha
  13. Pass {
  14. CGPROGRAM
  15. #pragma vertex vert
  16. #pragma fragment frag
  17. sampler2D _MainTex;
  18. fixed4 _SwirlArea;
  19. fixed _SwirlCenterXPercent;
  20. fixed _SwirlCenterYPercent;
  21. fixed _Radius;
  22. fixed _SwirlValue;
  23. fixed _Cutout;
  24. struct vin_vct
  25. {
  26. fixed4 vertex : POSITION;
  27. fixed4 color : COLOR;
  28. fixed2 texcoord : TEXCOORD0;
  29. };
  30. struct v2f_vct
  31. {
  32. fixed4 vertex : SV_POSITION;
  33. fixed4 color : COLOR;
  34. fixed2 texcoord : TEXCOORD0;
  35. };
  36. v2f_vct vert(vin_vct v)
  37. {
  38. v2f_vct o;
  39. o.vertex = UnityObjectToClipPos(v.vertex);
  40. o.color = v.color;
  41. o.texcoord = v.texcoord;
  42. return o;
  43. }
  44. fixed4 frag(v2f_vct i) : SV_Target
  45. {
  46. fixed2 swirlArea = fixed2(_SwirlArea.x, _SwirlArea.y);
  47. fixed2 center = fixed2(_SwirlArea.x * _SwirlCenterXPercent, _SwirlArea.y * _SwirlCenterYPercent);
  48. fixed2 targetPlace = i.texcoord * swirlArea;
  49. targetPlace -= center;
  50. fixed dis = length(targetPlace);
  51. if(dis < _Radius)
  52. {
  53. fixed percent = (_Radius - dis) / _Radius;
  54. fixed delta = percent * _SwirlValue;
  55. fixed s = sin(delta);
  56. fixed c = cos(delta);
  57. targetPlace = fixed2(dot(targetPlace, fixed2(c, -s)), dot(targetPlace, fixed2(s, c)));
  58. }
  59. targetPlace += center;
  60. fixed4 c = tex2D(_MainTex, targetPlace/swirlArea) * i.color;
  61. clip(c.a - _Cutout);
  62. c.a = 0.7f;
  63. c.b += 0.3f;
  64. return c;
  65. }
  66. ENDCG
  67. }
  68. }
  69. FallBack "Mobile/Particles/Addtive"
  70. }