Gaussian blur post processing material

since all searches seem to lead to this thread and it didnt have a solution yet…there you go:


float3 res = 0;

//new - get invSize from here
float2 invSize = View.ViewSizeAndInvSize.zw;

//new - we need to fix uv coordinates like this (still seems to be a bug in 4.21)
uv = ViewportUVToSceneTextureUV(uv,14);

int TexIndex = 14;
float weights] =
{
  0.01, 0.02, 0.04, 0.02, 0.01,
  0.02, 0.04, 0.08, 0.04, 0.02,
  0.04, 0.08, 0.16, 0.08, 0.04,
  0.02, 0.04, 0.08, 0.04, 0.02,
  0.01, 0.02, 0.04, 0.02, 0.01
};

float offsets] = { -4, -2, 0, 4, 2 };

if(Mask <= 0.01) return SceneTextureLookup(uv, TexIndex, false);

uv *= 0.5;
for (int i = 0; i < 5; ++i)
{
  float v = uv.y + offsets* * invSize.y * Mask * BlurStrength;
  int temp = i * 5;
  for (int j = 0; j < 5; ++j)
  {
    float u = uv.x + offsets[j] * invSize.x * Mask * BlurStrength;
    float2 uvShifted = uv + float2(u, v);
    float weight = weights[temp + j];
    float3 tex = SceneTextureLookup(uvShifted, TexIndex, false);
    res += tex * weight;
  }
}

return float4(res, 1);

add two more inputs:
**Mask **- a 0-1 value that can mask pixels from the blur (i needed to only blur pixels close the the camera, hence the scenedepth node; play around with the 0.005 multiplier to modify the distance; its kinda a cheap depth of field effect…)
**BlurStrength **- guess what :slight_smile: dont overdo it though, its not increasing the sample count, only the ‘offset’ of the blurred pixel

have fun!

5 Likes