Skip to content

ttencate/blur_godot4

Repository files navigation

Blur Example in Godot 4

This is an example of a shader for Gaussian blur in Godot 4.

Screenshot of blur

It works in two passes: first horizontal (X) then vertical (Y). Linear texture filtering is used to cut the number of required texture samples in two. This article describes both techniques in detail.

The shader Blur.gdshader was generated by the editor script ShaderGenerator.gd. This script hardcodes a fixed blur radius into the shader, which can be configured by editing the script. The larger the radius, the more texture samples, and the greater the performance cost.

The radius can be adjusted at runtime with a shader uniform, but this has a few caveats:

  1. Choosing a smaller radius does not reduce the number of texture lookups, so it does not improve performance. If you need a blur of a different, fixed radius, it's recommended to generate a different shader for that instead. If you need to turn off the blur, you should just turn off the shader.

  2. Choosing a larger radius than what the shader was designed for will result in artifacts, because the shader will start skipping pixels.

  3. The linear texture filtering trick is probably not 100% mathematically correct anymore, although visually this doesn't seem to matter.

As such, runtime radius adjustment is mostly useful for fading the shader's effect in and out.

About

Example of a Gaussian blur shader in Godot 4

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published