GlassBlur.shader 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. Shader "Custom/GlassBlur"
  2. {
  3. Properties
  4. {
  5. _MainTex ("Base (RGB)", 2D) = "white" {}
  6. _Distortion ("Distortion", Range(0.0,1.0)) = 0.5
  7. _BlurSize ("Blur Size", Range(0.0,1.0)) = 0.2
  8. }
  9. SubShader
  10. {
  11. Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
  12. LOD 200
  13. Blend SrcAlpha OneMinusSrcAlpha
  14. ZWrite Off
  15. AlphaTest Greater 0.5
  16. Cull Off
  17. Pass
  18. {
  19. CGPROGRAM
  20. #pragma vertex vert
  21. #pragma fragment frag
  22. #include "UnityCG.cginc"
  23. struct appdata_t
  24. {
  25. float4 vertex : POSITION;
  26. float2 texcoord : TEXCOORD0;
  27. };
  28. struct v2f
  29. {
  30. float2 uv : TEXCOORD0;
  31. float4 pos : SV_POSITION;
  32. };
  33. sampler2D _MainTex;
  34. float4 _MainTex_ST;
  35. float _Distortion;
  36. float _BlurSize;
  37. v2f vert (appdata_t v)
  38. {
  39. v2f o;
  40. o.pos = UnityObjectToClipPos(v.vertex);
  41. o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
  42. return o;
  43. }
  44. fixed4 frag (v2f i) : SV_Target
  45. {
  46. float2 uv = i.uv;
  47. float2 offset = float2(_Distortion, _Distortion) * _BlurSize;
  48. float4 col = tex2D(_MainTex, uv);
  49. col += tex2D(_MainTex, uv + float2(offset.x, offset.y));
  50. col += tex2D(_MainTex, uv + float2(-offset.x, offset.y));
  51. col += tex2D(_MainTex, uv + float2(offset.x, -offset.y));
  52. col += tex2D(_MainTex, uv + float2(-offset.x, -offset.y));
  53. col /= 5.0;
  54. return col;
  55. }
  56. ENDCG
  57. }
  58. }
  59. FallBack "Diffuse"
  60. }