Gaussian blur post processing material

thanks man, really cool
i didn’t know about this section : float2 invSize = float2(0.01, 0.01);

PS : can you tell me what does [unroll(15)] do ?

That was mentioned above, play with it for your situation. Unroll allows you to have larger for loops.

Thanks for the explanation.
yet still one question : the filter does not seem to work for black and white pictures for me but it works perfectly with colored ones. is it the same with you ?

ps : shall we open a new thread to discuss about bilateral over there ?

From the MSDN HLSL Docs “Unroll the loop until it stops executing. Can optionally specify the maximum number of times the loop is to execute. Not compatible with the [loop] attribute.”

So it would convert a loop to a set of instructions that run n times.
HTH

Hello Kory, sorry for bothering you about this old topic. I am trying to get this Guassian Blur to work, but copy pasting your material crashes the UE 4.11.2. Do you have a fix for that by any chance? -.O

Load it into 4.10 and get it to work there, then upgrade that project to 4.11 and reopen it in the newer engine. You can then copy/paste it back here for others.

How can I make the blur stronger ?

@plangton by extending the kernel fruther, but it already is huge. The current 15x15 matrix gives you 225 sampling points per pixel, that will be taken for every pixel on your 1920x1080 screen. Ugh?! I suggest you to try to find an approximation to this method that takes significantly less samples there you can have the freedom to extend it even larger, thus making it stronger.

Hey! Thanks for this! Was a huge help! In the end you said it was possible to separate the blur into horizontal and vertical passes. I added 2 materials to a global postprocess volume; one of them was used to blur the image horizontally and the other in the vertical direction i.e, in separate passes as I decreased the priority of one of them. However, my results are less than desirable. Could you show me how you would write the shader for separate passes?

This code works perfectly in 4.18.3, does not in 4.20.1. It doesn’t give any errors, the shader just doesn’t compile.


float3 res = 0;
float2 invSize = GetPostProcessInputSize(0).zw;
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] = { 2*a, a, 0, -1*a, -2*a};

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

return float4(res, 1);

Any ideas?

I understand there was a change with how scene texture lookups work in custom nodes that went into effect in 4.19, so basically a few lines of the code probably need rewritten.

Im not very knowledgeable about shader code, so that’s as much help as I can be…

How do I set sigma on this function?

Hey guys, this is not working in 4.21 (i guess even in earlier versions). Can someone give it a touch up please? Thanks

Hi there.

got it running on 4.21. According to Kory’s post, i changed the shader a little to this:


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] = { -2, -1, 0, 1, 2 };

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

return float4(res, 1);

Paste this into custom node and add two inputs: “uv” and “SceneTexture” and set output type to “CMOT Float 4”. That’s it. :slight_smile:

->

regards

What part of the code controls the amount of blur? I will like to make it stronger.

Hello. When I try to reuse any of the code excerpts mentioned above, I get the following error:

[SM5] /Engine/Generated/Material.ush(1522,18-43): error X3004: undeclared identifier ‘GetPostProcessInputSize’

Does anyone know how it can be fixed?

Many thanks.

Same Error how did you guys get this working in 4.22 ?

Use the modified code from **Daniel Mø :slight_smile: **

Just add a multiplier to “float offsets” See screenshot

[ATTACH=JSON]{“data-align”:“none”,“data-size”:“full”,“data-tempid”:“temp_186462_1584745071456_800”,“title”:“Screenshot_1.png”}[/ATTACH]
https://forums.unrealengine.com/core/image/gif;base64
​​

The image is missing from the above response by RysenSpark about how to control the amount of blur. How do you control the amount of blur? If I adjust the offset numbers I get a more spread out blur, but staggered. Do I have to adjust the weights too to get more “samples”? Or adjust the “5” in the loop to match the number of offsets? This is what I get with a line of “float offsets] = { -20, -10, 0, 10, 20 };”.