Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Shader "UI/Blur"{
- Properties{
- [PerRendererData]_MainTex("Sprite Texture", 2D) = "white" {}
- _Color("Tint", Color) = (1,1,1,1)
- _Horizontal("Horizontal Deviation", Range(1, 50)) = 30
- _Vertical("Vertical Deviation", Range(1, 50)) = 30
- [Toggle]_Fix("(BETA)Fix Y Position", Float) = 0
- [HideInInspector]_StencilComp("Stencil Comparison", Float) = 8
- [HideInInspector]_Stencil("Stencil ID", Float) = 0
- [HideInInspector]_StencilOp("Stencil Operation", Float) = 0
- [HideInInspector]_StencilWriteMask("Stencil Write Mask", Float) = 255
- [HideInInspector]_StencilReadMask("Stencil Read Mask", Float) = 255
- [HideInInspector]_UseUIAlphaClip("Use Alpha Clip", Float) = 0
- [HideInInspector]_ColorMask("Color Mask", Float) = 15
- }
- SubShader{
- Tags {
- "Queue" = "Transparent"
- "IgnoreProjector" = "True"
- "RenderType" = "Transparent"
- "PreviewType" = "Plane"
- "CanUseSpriteAtlas" = "True"
- }
- Stencil{
- Ref[_Stencil]
- Comp[_StencilComp]
- Pass[_StencilOp]
- ReadMask[_StencilReadMask]
- WriteMask[_StencilWriteMask]
- }
- Cull Off
- Lighting Off
- ZWrite Off
- ZTest[unity_GUIZTestMode]
- Blend SrcAlpha OneMinusSrcAlpha
- ColorMask[_ColorMask]
- GrabPass {
- Tags{
- "LightMode" = "Always"
- }
- }
- //Horizontal blur pass
- Pass {
- Tags{
- "LightMode" = "Always"
- }
- CGPROGRAM
- #pragma vertex vert
- #pragma fragment frag
- #pragma fragmentoption ARB_precision_hint_fastest
- #include "UnityCG.cginc"
- struct appdata_t {
- half4 vertex : POSITION;
- half2 texcoord: TEXCOORD0;
- half4 worldPosition : TEXCOORD1;
- half4 color : COLOR;
- };
- uint _Fix;
- struct v2f {
- half4 vertex : SV_POSITION;
- half4 uvgrab : TEXCOORD0;
- half2 position : TEXCOORD1;
- half4 color : COLOR;
- };
- v2f vert(appdata_t v) {
- #if UNITY_UV_STARTS_AT_TOP
- float scale = -1.0;
- #else
- float scale = 1.0;
- #endif
- v2f o;
- o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
- o.uvgrab.xy = (float2(o.vertex.x, o.vertex.y*scale) + o.vertex.w) * 0.5;
- o.uvgrab.zw = 0;
- o.position = v.texcoord;
- o.color = v.color;
- if (_Fix)
- o.uvgrab.y += 0.115 / 2;
- return o;
- }
- sampler2D _MainTex;
- sampler2D _GrabTexture;
- half4 _Color;
- half _Horizontal;
- half4 frag(v2f i) : COLOR{
- half4 sum = half4(0,0,0,0);
- half iterations = _Horizontal * 3;
- #define GFunc(x,d) (1/(sqrt(2*3.14*d*d))) * exp(-(x*x / (2*d*d)))
- for(int j = -iterations /2; j<iterations /2; j++)
- sum += tex2D(_GrabTexture, float2(i.uvgrab.x + j * _Horizontal / 500.0 / iterations, i.uvgrab.y)) * GFunc(j, _Horizontal);
- sum.a = tex2D(_MainTex, i.position).a;
- return sum * _Color;
- }
- ENDCG
- }
- GrabPass{
- Tags{
- "LightMode" = "Always"
- }
- }
- //Vertical blur pass
- Pass{
- Tags{
- "LightMode" = "Always"
- }
- CGPROGRAM
- #pragma vertex vert
- #pragma fragment frag
- #pragma fragmentoption ARB_precision_hint_fastest
- #include "UnityCG.cginc"
- struct appdata_t {
- half4 vertex : POSITION;
- half2 texcoord: TEXCOORD0;
- half4 worldPosition : TEXCOORD1;
- half4 color : COLOR;
- };
- struct v2f {
- half4 vertex : SV_POSITION;
- half4 uvgrab : TEXCOORD0;
- half2 position : TEXCOORD1;
- half4 color : COLOR;
- };
- uint _Fix;
- v2f vert(appdata_t v) {
- #if UNITY_UV_STARTS_AT_TOP
- float scale = -1.0;
- #else
- float scale = 1.0;
- #endif
- v2f o;
- o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
- o.uvgrab.xy = (float2(o.vertex.x, o.vertex.y*scale) + o.vertex.w) * 0.5;
- o.uvgrab.zw = 0;
- o.position = v.texcoord;
- o.color = v.color;
- if (_Fix)
- o.uvgrab.y += 0.115 / 2;
- return o;
- }
- sampler2D _MainTex;
- sampler2D _GrabTexture;
- half4 _Color;
- half _Vertical;
- half4 frag(v2f i) : COLOR{
- half4 sum = half4(0,0,0,0);
- half iterations = _Vertical * 3;
- #define GFunc(x,d) (1/(sqrt(2*3.14*d*d))) * exp(-(x*x / (2*d*d)))
- for (int j = -iterations / 2; j < iterations / 2; j++)
- sum += tex2D(_GrabTexture, float2(i.uvgrab.x, i.uvgrab.y + j * _Vertical / 500.0 / iterations)) * GFunc(j, _Vertical);
- sum.a = tex2D(_MainTex, i.position).a;
- return sum * _Color;
- }
- ENDCG
- }
- //Sprite pass
- Pass {
- CGPROGRAM
- #pragma vertex vert
- #pragma fragment frag
- #include "UnityCG.cginc"
- #include "UnityUI.cginc"
- #pragma multi_compile __ UNITY_UI_ALPHACLIP
- struct appdata_t
- {
- float4 vertex : POSITION;
- float4 color : COLOR;
- float2 texcoord : TEXCOORD0;
- };
- struct v2f
- {
- float4 vertex : SV_POSITION;
- fixed4 color : COLOR;
- half2 texcoord : TEXCOORD0;
- float4 worldPosition : TEXCOORD1;
- };
- fixed4 _Color;
- fixed4 _TextureSampleAdd;
- float4 _ClipRect;
- v2f vert(appdata_t v) {
- v2f o;
- o.worldPosition = v.vertex;
- o.vertex = mul(UNITY_MATRIX_MVP, o.worldPosition);
- o.texcoord = v.texcoord;
- #ifdef UNITY_HALF_TEXEL_OFFSET
- o.vertex.xy += (_ScreenParams.zw - 1.0)*float2(-1,1);
- #endif
- o.color = v.color * _Color;
- return o;
- }
- sampler2D _MainTex;
- fixed4 frag(v2f i) : SV_Target{
- half4 color = (tex2D(_MainTex, i.texcoord) + _TextureSampleAdd) * i.color;
- color.a *= UnityGet2DClipping(i.worldPosition.xy, _ClipRect);
- #ifdef UNITY_UI_ALPHACLIP
- clip(color.a - 0.001);
- #endif
- return color;
- }
- ENDCG
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement