123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359 |
- // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
- /**
- * Gaussian Blur
- *
- * Author(s): Flying Banana
- * Date Created: 25-Jul-2015
- */
- /**
- * This is a two-pass blur shader. Performance-wise this gives the best result.
- */
- Shader "UI/Blur/UIBlur" {
- Properties {
- _TintColor ("Tint Color", Color) = (1, 1, 1, 0.2)
- _Size ("Spacing", Range(0, 10)) = 5.0
- _Vibrancy ("Vibrancy", Range(0, 2)) = 0.2
-
- [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
- }
-
- Category {
- // We must be transparent, so other objects are drawn before this one.
- Tags {
- "Queue"="Transparent"
- "IgnoreProjector"="True"
- "RenderType"="Opaque"
- }
- Stencil {
- Ref [_Stencil]
- Comp [_StencilComp]
- Pass [_StencilOp]
- ReadMask [_StencilReadMask]
- WriteMask [_StencilWriteMask]
- }
- SubShader {
- GrabPass {
- Tags { "LightMode" = "Always" }
- }
-
- // Vertical blur
- Pass {
- Name "VERTICAL"
- Tags { "LightMode" = "Always" }
-
- CGPROGRAM
- #pragma vertex vert
- #pragma fragment frag
- #pragma fragmentoption ARB_precision_hint_fastest
- #include "UnityCG.cginc"
-
- struct appdata_t {
- float4 vertex : POSITION;
- float2 texcoord: TEXCOORD0;
- };
-
- struct v2f {
- float4 vertex : POSITION;
- float4 uvgrab : TEXCOORD0;
- };
-
- v2f vert (appdata_t v) {
- v2f o;
- o.vertex = UnityObjectToClipPos(v.vertex);
- #if UNITY_UV_STARTS_AT_TOP
- float scale = -1.0;
- #else
- float scale = 1.0;
- #endif
- o.uvgrab.xy = (float2(o.vertex.x, o.vertex.y*scale) + o.vertex.w) * 0.5;
- o.uvgrab.zw = o.vertex.zw;
- return o;
- }
-
- sampler2D _GrabTexture;
- float4 _GrabTexture_TexelSize;
- float _Size;
-
- half4 frag( v2f i ) : COLOR {
- half4 sum = half4(0,0,0,0);
-
- #define GRABPIXEL(weight,kernely) tex2Dproj( _GrabTexture, UNITY_PROJ_COORD(float4(i.uvgrab.x, i.uvgrab.y + _GrabTexture_TexelSize.y * kernely * _Size * 1.61, i.uvgrab.z, i.uvgrab.w))) * weight
-
- sum += GRABPIXEL(0.05, -4.0);
- sum += GRABPIXEL(0.09, -3.0);
- sum += GRABPIXEL(0.12, -2.0);
- sum += GRABPIXEL(0.15, -1.0);
- sum += GRABPIXEL(0.18, 0.0);
- sum += GRABPIXEL(0.15, +1.0);
- sum += GRABPIXEL(0.12, +2.0);
- sum += GRABPIXEL(0.09, +3.0);
- sum += GRABPIXEL(0.05, +4.0);
-
- return sum;
- }
-
- ENDCG
- }
- GrabPass {
- Tags { "LightMode" = "Always" }
- }
- // Horizontal blur
- Pass {
- Name "HORIZONTAL"
-
- Tags { "LightMode" = "Always" }
-
- CGPROGRAM
- #pragma vertex vert
- #pragma fragment frag
- #pragma fragmentoption ARB_precision_hint_fastest
- #include "UnityCG.cginc"
-
- struct appdata_t {
- float4 vertex : POSITION;
- float2 texcoord: TEXCOORD0;
- };
-
- struct v2f {
- float4 vertex : POSITION;
- float4 uvgrab : TEXCOORD0;
- };
-
- v2f vert (appdata_t v) {
- v2f o;
- o.vertex = UnityObjectToClipPos(v.vertex);
- #if UNITY_UV_STARTS_AT_TOP
- float scale = -1.0;
- #else
- float scale = 1.0;
- #endif
- o.uvgrab.xy = (float2(o.vertex.x, o.vertex.y*scale) + o.vertex.w) * 0.5;
- o.uvgrab.zw = o.vertex.zw;
- return o;
- }
-
- sampler2D _GrabTexture;
- float4 _GrabTexture_TexelSize;
- float _Size;
-
- half4 frag( v2f i ) : COLOR {
- half4 sum = half4(0,0,0,0);
-
- #define GRABPIXEL(weight,kernelx) tex2Dproj( _GrabTexture, UNITY_PROJ_COORD(float4(i.uvgrab.x + _GrabTexture_TexelSize.x * kernelx * _Size * 1.61, i.uvgrab.y, i.uvgrab.z, i.uvgrab.w))) * weight
-
- sum += GRABPIXEL(0.05, -4.0);
- sum += GRABPIXEL(0.09, -3.0);
- sum += GRABPIXEL(0.12, -2.0);
- sum += GRABPIXEL(0.15, -1.0);
- sum += GRABPIXEL(0.18, 0.0);
- sum += GRABPIXEL(0.15, +1.0);
- sum += GRABPIXEL(0.12, +2.0);
- sum += GRABPIXEL(0.09, +3.0);
- sum += GRABPIXEL(0.05, +4.0);
-
- return sum;
- }
-
- ENDCG
- }
-
- GrabPass {
- Tags { "LightMode" = "Always" }
- }
-
- // Vertical blur
- Pass {
- Name "VERTICAL"
- Tags { "LightMode" = "Always" }
-
- CGPROGRAM
- #pragma vertex vert
- #pragma fragment frag
- #pragma fragmentoption ARB_precision_hint_fastest
- #include "UnityCG.cginc"
-
- struct appdata_t {
- float4 vertex : POSITION;
- float2 texcoord: TEXCOORD0;
- };
-
- struct v2f {
- float4 vertex : POSITION;
- float4 uvgrab : TEXCOORD0;
- };
-
- v2f vert (appdata_t v) {
- v2f o;
- o.vertex = UnityObjectToClipPos(v.vertex);
- #if UNITY_UV_STARTS_AT_TOP
- float scale = -1.0;
- #else
- float scale = 1.0;
- #endif
- o.uvgrab.xy = (float2(o.vertex.x, o.vertex.y*scale) + o.vertex.w) * 0.5;
- o.uvgrab.zw = o.vertex.zw;
- return o;
- }
-
- sampler2D _GrabTexture;
- float4 _GrabTexture_TexelSize;
- float _Size;
-
- half4 frag( v2f i ) : COLOR {
- half4 sum = half4(0,0,0,0);
-
- #define GRABPIXEL(weight,kernely) tex2Dproj( _GrabTexture, UNITY_PROJ_COORD(float4(i.uvgrab.x, i.uvgrab.y + _GrabTexture_TexelSize.y * kernely * _Size, i.uvgrab.z, i.uvgrab.w))) * weight
-
- sum += GRABPIXEL(0.05, -4.0);
- sum += GRABPIXEL(0.09, -3.0);
- sum += GRABPIXEL(0.12, -2.0);
- sum += GRABPIXEL(0.15, -1.0);
- sum += GRABPIXEL(0.18, 0.0);
- sum += GRABPIXEL(0.15, +1.0);
- sum += GRABPIXEL(0.12, +2.0);
- sum += GRABPIXEL(0.09, +3.0);
- sum += GRABPIXEL(0.05, +4.0);
-
- return sum;
- }
-
- ENDCG
- }
- GrabPass {
- Tags { "LightMode" = "Always" }
- }
- // Horizontal blur
- Pass {
- Name "HORIZONTAL"
-
- Tags { "LightMode" = "Always" }
-
- CGPROGRAM
- #pragma vertex vert
- #pragma fragment frag
- #pragma fragmentoption ARB_precision_hint_fastest
- #include "UnityCG.cginc"
-
- struct appdata_t {
- float4 vertex : POSITION;
- float2 texcoord: TEXCOORD0;
- };
-
- struct v2f {
- float4 vertex : POSITION;
- float4 uvgrab : TEXCOORD0;
- };
-
- v2f vert (appdata_t v) {
- v2f o;
- o.vertex = UnityObjectToClipPos(v.vertex);
- #if UNITY_UV_STARTS_AT_TOP
- float scale = -1.0;
- #else
- float scale = 1.0;
- #endif
- o.uvgrab.xy = (float2(o.vertex.x, o.vertex.y*scale) + o.vertex.w) * 0.5;
- o.uvgrab.zw = o.vertex.zw;
- return o;
- }
-
- sampler2D _GrabTexture;
- float4 _GrabTexture_TexelSize;
- float _Size;
-
- half4 frag( v2f i ) : COLOR {
- half4 sum = half4(0,0,0,0);
-
- #define GRABPIXEL(weight,kernelx) tex2Dproj(_GrabTexture, UNITY_PROJ_COORD(float4(i.uvgrab.x + _GrabTexture_TexelSize.x * kernelx * _Size, i.uvgrab.y, i.uvgrab.z, i.uvgrab.w))) * weight
-
- sum += GRABPIXEL(0.05, -4.0);
- sum += GRABPIXEL(0.09, -3.0);
- sum += GRABPIXEL(0.12, -2.0);
- sum += GRABPIXEL(0.15, -1.0);
- sum += GRABPIXEL(0.18, 0.0);
- sum += GRABPIXEL(0.15, +1.0);
- sum += GRABPIXEL(0.12, +2.0);
- sum += GRABPIXEL(0.09, +3.0);
- sum += GRABPIXEL(0.05, +4.0);
-
- return sum;
- }
-
- ENDCG
- }
-
- // Distortion
- GrabPass {
- Tags { "LightMode" = "Always" }
- }
-
- Pass {
- Tags { "LightMode" = "Always" }
-
- CGPROGRAM
- #pragma vertex vert
- #pragma fragment frag
- #pragma fragmentoption ARB_precision_hint_fastest
- #include "UnityCG.cginc"
-
- struct appdata_t {
- float4 vertex : POSITION;
- float2 texcoord: TEXCOORD0;
- };
-
- struct v2f {
- float4 vertex : POSITION;
- float4 uvgrab : TEXCOORD0;
- };
-
- v2f vert (appdata_t v) {
- v2f o;
- o.vertex = UnityObjectToClipPos(v.vertex);
- #if UNITY_UV_STARTS_AT_TOP
- float scale = -1.0;
- #else
- float scale = 1.0;
- #endif
- o.uvgrab.xy = (float2(o.vertex.x, o.vertex.y*scale) + o.vertex.w) * 0.5;
- o.uvgrab.zw = o.vertex.zw;
-
- return o;
- }
-
- half4 _TintColor;
- float _Vibrancy;
- sampler2D _GrabTexture;
- float4 _GrabTexture_TexelSize;
-
- half4 frag( v2f i ) : COLOR {
- half4 col = tex2Dproj( _GrabTexture, UNITY_PROJ_COORD(i.uvgrab));
- col.xyz *= 1 + _Vibrancy;
- col = lerp (col, _TintColor, _TintColor.w);
- return col;
- }
-
- ENDCG
- }
- }
- }
- }
|