A good blur shader?

GrampsGramps Posts: 21Member

I have had pretty good success with shaders except when it comes to blurring. Most I have seen seem to make 4 or more copies of the screen and turn them somewhat transparent and offset. It kind of looks blurry but more like a prism effect than a real blur.

Does anyone know of any actual blur shaders?

Answers

  • GrampsGramps Posts: 21Member

    The posting process errored when I made the original question and posted three times. Sorry, admins!

  • TwistedTwiglegTwistedTwigleg Posts: 1,049Admin

    @Gramps said:
    The posting process errored when I made the original question and posted three times. Sorry, admins!

    No worries, it happens.
    I removed the duplicate. Thanks for reporting, I appreciate it :smile:

  • GrampsGramps Posts: 21Member

    Cheers, sir! Thanks for getting those.

  • CalinouCalinou Posts: 217Admin Godot Developer

    Performing high-quality blurring in real-time is a relatively difficult task; Intel had a look at it in 2014. I'm not sure if this could be implemented in Godot 3's shader language though.

  • MegalomaniakMegalomaniak Posts: 1,087Admin

    Ah yes, good job me... before going to sleep last night I posted the following as a reply to one of the archived double posts:

    @Gramps said:
    Most I have seen seem to make 4 or more copies of the screen and turn them somewhat transparent and offset. It kind of looks blurry but more like a prism effect than a real blur.

    That could well be describing either a method that is based on framebuffer mipmaps or instanced framebuffer copies offset to get a blur effect. For the former you can check an example in the demos repository.

  • GrampsGramps Posts: 21Member
    edited February 9

    @Calinou Hmm, I wondered. I've seen it quite a bit in other games and wanted to implement it for myself. I've seen a few examples in Godot but no working code. Any snippets I've seen so far don't actually work.

    @Megalomaniak Yeah, I am using that method now. Kinda of does the trick but looks kinda crude as a blur. I'll check out the demo repo you linked and see if it works better. Cheers!

  • SchorschSchorsch Posts: 2Member
    edited February 22

    Instead of making copies of the frame and moving it, you can just get the same effect if you the the color of the current pixel, all the colors of the surrounding pixels and divide it by the number of pixels you used. Let me make a simple example. Let us say you are looking for the new color of pixel at (3, 5). You would take the color itself and the surrounding pixels on (2, 4), (3, 4), (4, 4), (2, 5), (4, 5), (2, 6), (3, 6), (4, 6) and sum all those. After that you divide by the number of pixels, in this case 9. You pixel shader makes this for every pixel and by that you get a blurred image. You could take only some neighbouring pixels, or the next outer neighbours, or just the ones on one side. That depends on the effect that you want to get. If you want, you can even take other pixels, not the ones which are direct neighbours but pixels which are further apart of your current pixel. With this solution, you can mimic the effect of making some copies and moving them around.
    I made a simple example using shader toy:
    https://www.shadertoy.com/view/wsXSR7

    this method is a simplification of the gaussian blur. You can read that up if you want to extend it. It is really simple. Basically, you calculate a weighted sum of the neighbours colors. In most cases, you want the weight to scale with the distance from your center. Maybe just read the wikipedia article i linked.
    If you have any questions, feel free to ask.

    edit: i extended my example. blur1 takes the direct neighbours. blur2 takes the direct neighbours and those direct neighbours and blur_with_size takes the number of 'neighbour levels' as parameter. The bigger it is the blurrier it gets.

Sign In or Register to comment.