unity – How can I optimize this blur shader?

I’m trying to do a bit of shader development. I found this optimized version of gaussian blur (shadertoy demo), rewrote it in ShaderLab::

Shader "Custom/Effects/Blur"
        _MainTex ("Texture", 2D) = "white" {}
        _Offset ("Offset", Range(1, 100)) = 10
            #pragma vertex vert
            #pragma fragment frag
            #include "UnityCG.cginc"
            struct appdata
                float4 vertex : POSITION;
                fixed2 uv : TEXCOORD0;
            struct v2f
                fixed2 uv : TEXCOORD0;
                float4 vertex : SV_POSITION;
                half2 uv1 : TEXCOORD6;
                half2 uv2 : TEXCOORD7;
            half _Offset;
            sampler2D _MainTex;
            float4 _MainTex_ST;
            v2f vert (appdata v)
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.uv = TRANSFORM_TEX(v.uv, _MainTex);
                float direction = o.uv * _Offset;
                half2 off =  half2(1.3333333333333333, 1.3333333333333333)* direction;
                half2 resolution = _ScreenParams.xy;
                o.uv1 = o.uv + (off / resolution);
                o.uv2 = o.uv - (off / resolution);
                return o;
            fixed4 frag (v2f i) : SV_Target
                fixed4 color = tex2D(_MainTex, i.uv) * 0.29411764705882354;
                color += tex2Dlod(_MainTex,float4(i.uv1, 0, 3)) * 0.35294117647058826;
                color += tex2Dlod(_MainTex, float4(i.uv2, 0, 3)) * 0.35294117647058826;
                return color;

and added it as a ScriptableRenderFeature:

using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
using System;
public class BlurFeature : ScriptableRendererFeature
    class BlurPass : ScriptableRenderPass
        private string profilerTag;
        private Material materialToBlit;
        private RenderTargetIdentifier cameraColorTargetIdent;
        private RenderTargetHandle tempTexture;
        public BlurPass(string profilerTag, RenderPassEvent renderPassEvent, Material material) : base()
            this.profilerTag = profilerTag;
            this.renderPassEvent = renderPassEvent;
            this.materialToBlit = material;
        public void Setup(RenderTargetIdentifier cameraColorTargetIdent)
            this.cameraColorTargetIdent = cameraColorTargetIdent;
        // called each frame before Execute, use it to set up things the pass will need
        public override void Configure(CommandBuffer cmd, RenderTextureDescriptor cameraTextureDescriptor)
            // create a temporary render texture that matches the camera
            cmd.GetTemporaryRT(tempTexture.id, cameraTextureDescriptor);
            base.Configure(cmd, cameraTextureDescriptor);
        // This method is called before executing the render pass.
        // It can be used to configure render targets and their clear state. Also to create temporary render target textures.
        // When empty this render pass will render to the active camera render target.
        // You should never call CommandBuffer.SetRenderTarget. Instead call <c>ConfigureTarget</c> and <c>ConfigureClear</c>.
        // The render pipeline will ensure target setup and clearing happens in a performant manner.
        public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderingData)
        // Here you can implement the rendering logic.
        // Use <c>ScriptableRenderContext</c> to issue drawing commands or execute command buffers
        // https://docs.unity3d.com/ScriptReference/Rendering.ScriptableRenderContext.html
        // You don't have to call ScriptableRenderContext.submit, the render pipeline will call it at specific points in the pipeline.
        public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
            // fetch a command buffer to use
            CommandBuffer cmd = CommandBufferPool.Get(profilerTag);
            cmd.Blit(cameraColorTargetIdent, tempTexture.Identifier(), materialToBlit, 0);
            cmd.Blit(tempTexture.Identifier(), cameraColorTargetIdent);
        public override void FrameCleanup(CommandBuffer cmd)
        // Cleanup any allocated resources that were created during the execution of this render pass.
        public override void OnCameraCleanup(CommandBuffer cmd)
    public class BlurSettings
        public bool IsEnabled = true;
        public RenderPassEvent RenderPassedOrder = RenderPassEvent.AfterRendering;
        public Material Material;
    public BlurSettings settings = new BlurSettings();
    RenderTargetHandle renderTextureHandle;
    BlurPass myRenderPass;
    /// <inheritdoc/>
    public override void Create()
        myRenderPass = new BlurPass("BLur Pass", settings.RenderPassedOrder, settings.Material);
    // Here you can inject one or multiple render passes in the renderer.
    // This method is called when setting up the renderer once per-camera.
    public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
        if (!settings.IsEnabled)
        var cameraColorTargetIdent = renderer.cameraColorTarget;

Basically it just grabs the rendered screen (from backbuffer?), applies material with the shader to it and then renders it to the screen.

After adding the shader I tested it’s performance on a mobile device. Before adding the shader the FPS was around 37 and with the shader applied the FPS dropped to 20.

How can optimize the shader so the performance implication won’t be that significant?

LibGDX Shader that converts image to single colour with blur

I made a shader which turns all the colours of the texture to black but I also want it to be blurred.

#ifdef GL_ES
    precision mediump float;

varying vec4 v_color;
varying vec2 v_texCoords;

uniform sampler2D u_texture;

void main() {
  vec4 c = v_color * texture2D(u_texture, v_texCoords);
  gl_FragColor = vec4(0,0,0, c.a);

A simple gaussian blur with good performance is what I want. I tried various blur shaders but haven’t managed to get any to work well.

This shadertoy shader looks ideal but not sure how to convert it or make it output only one colour https://www.shadertoy.com/view/Xltfzj

EDIT: I managed to convert the above mentioned shadertoy but the output doesn’t seem to really be blurred, just almost transparent. Not sure whether I converted it correctly or not though:

#ifdef GL_ES
    #define PRECISION mediump
    precision PRECISION float;
    precision PRECISION int;

varying vec4 v_color;
varying vec2 v_texCoords;

uniform sampler2D u_texture;
uniform vec2 resolution;

void main() {
    float Pi = 6.28318530718; // Pi*2
    float Directions = 16.0; // BLUR DIRECTIONS (Default 16.0 - More is better but slower)
    float Quality = 4.0; // BLUR QUALITY (Default 4.0 - More is better but slower)
    float Size = 8.0; // BLUR SIZE (Radius)
    vec2 Radius = Size / resolution.xy;
    // Normalised pixel coordinates (from 0 to 1)
    vec2 uv = gl_FragCoord.xy / resolution.xy;
    // Pixel colour
    vec4 Color = texture2D(u_texture, v_texCoords);
    // Blur calculations
    for( float d=0.0; d<Pi; d+=Pi/Directions) {
        for(float i=1.0/Quality; i<=1.0; i+=1.0/Quality) {
            Color += texture2D( u_texture, uv+vec2(cos(d),sin(d))*Radius*i);        
    // // Output to screen
    Color /= Quality * Directions - 15.0;
    gl_FragColor =  Color;

Original texture with desired output.

enter image description here

Photo Competition 2021-04-26: All Blur

Theme: All Blur

In the spirit of Why would one shoot a fully blurred picture?, let’s see some abstract and semi-abstract works.

This theme was suggested by mattdm.

Voting Rules

  • Vote up as many images as you like
  • Please, up votes only! Do NOT vote down your competitors! If you don’t like an image, don’t vote
  • Voting closes on April 26, 2021 at 12:01 AM UTC (00:01 UTC if you prefer a 24-hour time). The winner will be chosen based on votes at that time.

Submission Rules

  1. One photo submission per answer. Up to three (3) entries allowed.
  2. Post only photos taken by yourself or the person with you.
  3. All entries should include:
    • a title for the photo
    • a location and date, if known
    • camera, lens, and exposure settings, if known
    • any other explanatory notes, comments, etc., that you want to include (completely optional)
  4. The submitted image must conform to this site’s content license, Creative Commons Attribution-ShareAlike 4.0 (CC BY-SA 4.0) with attribution required.
  5. Do not use this as a forum for photo critique. Use chat instead, or ask a new question about your image.

Next Contest

Suggest a theme by writing a new answer at the Photo of the Week Theme Ideas thread. Please make sure to check the PotW theme ideas Archive first, to make sure you aren’t recycling a theme.

The highest-voted theme will be the next theme.

Good luck!

How to disable wallpaper blur effect on Samsung Galaxy Tab A8.0

so, I went to change my homescreen wallpaper on my samsung galaxy tab a8.0(sm-t290) and every wallpaper comes out as blurry.

in the gallery they work all well and fine, but as a wallpaper? nope.

lock screen looks good.

but the homescreen? well, the astronomy wallpapers I like..look like something my cat yarked up.

how do I fix this?

computer vision – How to apply average blur without using any cv2 function

I tried to get an average blur of an image using cv2 function and the other using self-built function. But the output I am getting in both the cases is quite different. As in the latter one I am getting a black layer above the required image. Can someone help me?

import numpy as np
import math
import cv2 as cv2
img = cv2.imread(“cube.jpg”,1)

 n,m,l= img.shape
 edge = np.full((n, m,l), 255)
 for i in range(1, n-1):
    for j in range(1, m-1):
        for k in range(l):
            edge(i)(j)(k) = 1/9*(img(i-1)(j-1)(k)+img(i-1)(j)(k)+img(i-1)(j+1)(k)+img(i)(j-1)(k)+img(i)(j)(k)+img(i)(j+1)(k)+img(i+1)(j-1)(k)+img(i+1)(j)(k)+img(i+1)(j+1)(k))

#img = img.astype(np.uint32)
Hori = np.concatenate((blur, edge), axis=1)
cv2.imshow('image', Hori.astype(np.uint8))


output of the program

Provide background blur on front camera for third party apps

For reasons too tedious to list, I’m currently having to use my Android Phone with Microsoft Teams for video calls and meetings.

Teams on Android doesn’t provide background blur or replacement. Anyone know of an App that can do this? Something that cuts in between Teams and the Selfie/Front Facing Camera to blur or replace the background?

This is on a stock OnePlus Nord, unrooted.

beginner – How can I blur a specific part of an HTML table using CSS

Okay, so I’ve been getting into code lately, and I want to blur an image in an HTML single-cell table, and then have the box of text not blurred. Currently, the text box is embedded inside the first single-cell table, but it is a second single-cell table. How can I keep the same box of text while at the same time unblurring it and blurring the photo behind it. (The rainforest is a placeholder)

font {
  text-shadow: 2px 2px #FF0000;

table.img {
  -webkit-filter: blur(1); /* Safari 6.0 - 9.0 */
filter: blur(1px);}


<lj-raw><table width="500" height="225" background="https://www.innovationnewsnetwork.com/wp-content/uploads/2020/06/iStock-Ramdan_Nain-696x392.jpg" align="center" cellpadding="20" cellspacing="0" class="img">
        <td valign="bottom">

            <table align="right" bgcolor="" background="https://i.imgur.com/7wjAm4b.png" cellpadding="10" cellspacing="0"><tr><td>
<div align="right">
<font size="5px" color="#FFFFFF 

" face="impact" text-shadow="10px 4px 10px">
<font size="2" color="#fff" face="impact">
                    <br>- Subtitle

multi-strobe-like motion blur outdoors?

This photo (cropped here) appears on p. 48 of the October 2020 issue of the Experimental Aircraft Association’s Sport Aviation magazine. The upper blade of the propeller shows the motion blur that is typical of airplane photographs, and that is found in every other photo in the magazine article.

But the lower blade of the propeller appears as a dozen closely spaced distinct blades.
What could explain this? The photographer, Jim Busha, assures me that he used no strobes, nor did he use some exotic shutter technique or other arcane settings on his camera. The color looks like evening sunlight, contrasted to the cyan daylight illuminating the other blade and the fuselage. (Other photos show that both the prop and fuselage are mostly black and near-white, with olive-green mountains.)

crop of photo of airplane