源战役客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 line
2.0 KiB

  1. Shader "SaberShad/RadiusBlur"
  2. {
  3. Properties
  4. {
  5. [HideInInspector]_MainTex ("Texture", 2D) = "white" {}
  6. // 径向模糊数据 xy分量代表径向中心点 z分量代表偏移
  7. _RadiusData("Radius Data", Vector) = (0.5, 0.5, 0.0, 1.0)
  8. // y分量代表迭代次数的倒数 例如迭代30次就是1/30
  9. _RadiusIterationData("Radius Iteration", Vector) = (1.0, 1.0, 0.0, 0.0)
  10. }
  11. SubShader
  12. {
  13. CGINCLUDE
  14. #include "UnityCG.cginc"
  15. sampler2D _MainTex;
  16. float4 _MainTex_ST;
  17. float4 _MainTex_TexelSize;
  18. half3 _RadiusData;
  19. half2 _RadiusIterationData;
  20. struct a2f_rb
  21. {
  22. float4 vertex : POSITION;
  23. float2 uv : TEXCOORD0;
  24. };
  25. struct v2f_rb
  26. {
  27. float4 vertex : SV_POSITION;
  28. float2 texcoord: TEXCOORD0;
  29. };
  30. v2f_rb RadiusBlurVertex(a2f_rb v)
  31. {
  32. v2f_rb o;
  33. o.vertex = UnityObjectToClipPos(v.vertex);
  34. o.texcoord = v.uv;
  35. // #if UNITY_UV_STARTS_AT_TOP
  36. // o.texcoord = o.texcoord * float2(1.0, -1.0) + float2(0.0, 1.0);
  37. // #endif
  38. o.texcoord = TRANSFORM_TEX(o.texcoord, _MainTex);
  39. return o;
  40. }
  41. half4 RadiusBlurFragment(v2f_rb i): SV_Target
  42. {
  43. half2 radiusRange = (_RadiusData.xy - i.texcoord.xy) * _RadiusData.z;
  44. half4 color = 0.0;
  45. [unroll(30)]
  46. for(int j = 0; j < _RadiusIterationData.x; j++)
  47. {
  48. color += tex2D(_MainTex, i.texcoord);
  49. i.texcoord += radiusRange;
  50. }
  51. return color * _RadiusIterationData.y;
  52. }
  53. ENDCG
  54. Cull Off ZWrite Off ZTest Always
  55. Pass
  56. {
  57. CGPROGRAM
  58. #pragma vertex RadiusBlurVertex
  59. #pragma fragment RadiusBlurFragment
  60. ENDCG
  61. }
  62. }
  63. }