RadialBlur.shader 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
  2. Shader "Hidden/RadialBlur"
  3. {
  4. Properties {
  5. _MainTex ("Base (RGB)", 2D) = "" {}
  6. }
  7. // Shader code pasted into all further CGPROGRAM blocks
  8. CGINCLUDE
  9. #include "UnityCG.cginc"
  10. struct v2f {
  11. float4 pos : SV_POSITION;
  12. float2 uv : TEXCOORD0;
  13. float2 blurVector : TEXCOORD1;
  14. };
  15. sampler2D _MainTex;
  16. float4 _BlurRadius4;
  17. float4 _SunPosition;
  18. float4 _MainTex_TexelSize;
  19. v2f vert( appdata_img v ) {
  20. v2f o;
  21. o.pos = UnityObjectToClipPos(v.vertex);
  22. o.uv.xy = v.texcoord.xy;
  23. o.blurVector = (_SunPosition.xy - v.texcoord.xy) * _BlurRadius4.xy;
  24. return o;
  25. }
  26. #define SAMPLES_FLOAT 6.0f
  27. #define SAMPLES_INT 6
  28. half4 frag(v2f i) : SV_Target
  29. {
  30. half4 color = half4(0,0,0,0);
  31. for(int j = 0; j < SAMPLES_INT; j++)
  32. {
  33. half4 tmpColor = tex2D(_MainTex, i.uv.xy);
  34. color += tmpColor;
  35. i.uv.xy += i.blurVector;
  36. }
  37. return color / SAMPLES_FLOAT;
  38. }
  39. ENDCG
  40. Subshader
  41. {
  42. Blend One Zero
  43. Pass {
  44. ZTest Always Cull Off ZWrite Off
  45. CGPROGRAM
  46. #pragma vertex vert
  47. #pragma fragment frag
  48. ENDCG
  49. } // Pass
  50. } // Subshader
  51. Fallback off
  52. } // shader