Is there a way to blur a sprite?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Syl

Greets!

If you know eh.

:bust_in_silhouette: Reply From: johnygames

You could create a sprite and assign a new shader to it. This sprite would then act as a filter that blurs anything that is behind it. You can then do whatever you want with it, have it follow your character, use it as a screen/canopy, like a window or something.

Create a snew shader and copy-paste this code in it:

shader_type canvas_item;
render_mode unshaded;

uniform int blurSize : hint_range(0,20);

void fragment()
{
COLOR = textureLod(SCREEN_TEXTURE, SCREEN_UV, float(blurSize)/10.0);
}

A new field will appear below the material called “Blur Size”. Increase that in order to increase the effect. Anything that is behind the object carrying the shader shall appear blured. To make the filter object stay on the top layer, just increase its Z Value under the Z Index Menu on the right. Does this help?

It helps and it’s a good learning, cheers! What would be really cool, would be to have it in the modulate of the CanvasItem visibility.

Syl | 2020-02-27 23:56

The built-in CanvasItem shader needs to remain as simple as possible for performance reasons. If we start adding more features such as HSL or blurring, it will become much slower to compile and run.

Calinou | 2020-02-28 09:36

I see, thxs for the info.

Syl | 2020-02-28 10:45

Thanks for that answer.

One more question:

As soon as if have a Blur SIze > 0, there is a visible “edge” around the Sprite.
Is there an easy way to get around this?

whiteshampoo | 2020-05-07 12:58