Blur Effect

There is a “easy” way to blur a background, a behind window, with Unity Indie?

I would like to blur the background when the player pause the game. But it not just a background (if it was I guess I could have two images and change between them), that are buttons, objects and all kind of things… So, I don’t know how could I do this.

I know that it’s easier with the Unity Pro – Unity - Blur Behind Window - Questions & Answers - Unity Discussions, but I just have the Unity Indie…

Easy answer is: not possible.

Long answer below…

I can think of only two ways, very much like your linked answer:

  1. camera script. set up two cameras, with proper clear flags and culling masks, one will blur all.
  2. post processing a captured image. no idea how to go here.

I’m not sure how Unity’s indie limitations work, how they prevent every image effect to work for instance. I’m sure there’s something that can be done in Windows with DLLs, or even Mac… Not so positive if it’s possible on any other medium.

But the point here is: if it’s easy to do in Unity Pro, why bother trying to do it in Unity Indie? The whole point of unity indie is making things work, not look good. You only need them to look good if you’re selling them, to which point you should be making money to buy such “cheap” licenses.

Edit

I got on my email an ingenious solution from Jessespike that, oddly, I can’t see here or “get permission to see” it when I click on the link. So, here it is:

Just force the texture to draw a smaller mipmap.
this.gameObject.renderer.material.mainTexture.mipMapBias = 3;

If you can do that on every “background” texture in scene (just use tags), then maybe you achieve a satisfying effect…

Yet another idea I thought after that, which is probably the best you can get:

  • (4) Using the two cameras setup from item 1, add in the front of the blurring one a transparent object with a transparent shader. Then you can either leave it at that (for simplicity) or animate its texture with a sequence of “blurring” getting stronger images (which can all be in one file) and a script from unify community, such as Animating Tiled Texture or SpriteManager

Recently I’ve found this.

Here’s a nice shader that works well.

From: https://forum.unity3d.com/threads/solved-dynamic-blurred-background-on-ui.345083/#post-2853442

Shader "Unlit/FrostedGlass"
{
    Properties
    {
        _Radius("Radius", Range(1, 255)) = 1
    }
 
    Category
    {
        Tags{ "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Opaque" }
     
        SubShader
        {
            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 = mul(UNITY_MATRIX_MVP, 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 _Radius;
 
                half4 frag(v2f i) : COLOR
                {
                    half4 sum = half4(0,0,0,0);
 
                    #define GRABXYPIXEL(kernelx, kernely) tex2Dproj( _GrabTexture, UNITY_PROJ_COORD(float4(i.uvgrab.x + _GrabTexture_TexelSize.x * kernelx, i.uvgrab.y + _GrabTexture_TexelSize.y * kernely, i.uvgrab.z, i.uvgrab.w)))
 
                    sum += GRABXYPIXEL(0.0, 0.0);
                    int measurments = 1;
 
                    for (float range = 0.1f; range <= _Radius; range += 0.1f)
                    {
                        sum += GRABXYPIXEL(range, range);
                        sum += GRABXYPIXEL(range, -range);
                        sum += GRABXYPIXEL(-range, range);
                        sum += GRABXYPIXEL(-range, -range);
                        measurments += 4;
                    }
 
                    return sum / measurments;
                }
                ENDCG
            }
            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 = mul(UNITY_MATRIX_MVP, 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 _Radius;
 
                half4 frag(v2f i) : COLOR
                {
 
                    half4 sum = half4(0,0,0,0);
                    float radius = 1.41421356237 * _Radius;
 
                    #define GRABXYPIXEL(kernelx, kernely) tex2Dproj( _GrabTexture, UNITY_PROJ_COORD(float4(i.uvgrab.x + _GrabTexture_TexelSize.x * kernelx, i.uvgrab.y + _GrabTexture_TexelSize.y * kernely, i.uvgrab.z, i.uvgrab.w)))
 
                    sum += GRABXYPIXEL(0.0, 0.0);
                    int measurments = 1;
 
                    for (float range = 1.41421356237f; range <= radius * 1.41; range += 1.41421356237f)
                    {
                        sum += GRABXYPIXEL(range, 0);
                        sum += GRABXYPIXEL(-range, 0);
                        sum += GRABXYPIXEL(0, range);
                        sum += GRABXYPIXEL(0, -range);
                        measurments += 4;
                    }
 
                    return sum / measurments;
                }
                ENDCG
            }
        }
    }
}

Improved version giving a better blur with higher strength. Came up with this after a while.

Gaussian Blur

alt text