Fast blur in JAVA2D

Hello,

I need some fast blur for a sketch I am making. So far I have only tried filter(), but

  1. it is slow
  2. I need to blur only an area, not the entire image

The blur needs to run smoothly at 60 fps. Is this possible with JAVA2D?

Hi @lqdev I assume you already tried the Pimage filter in processing And the frameRate() function?
https://processing.org/reference/PImage_filter_.html
Can you explain your project in more detail please? :slight_smile:

Hi,

Have you tried the blur pass from the PostFx library ? It’s pretty fast.

1 Like

The problem is, that I need the JAVA2D renderer, because it’s the only one that supports clip() properly.

Well instead of writing an efficient bur implementation in JAVA2D (which is not really possible), I would recommend you to write a shader which clips the output of your sketch :slight_smile:

But first, tell us a bit more about the clipping problem you experience in P2D?

I have already switched to FX2D, which solves my blur problems (and I used a clip()/noClip() support workaround), and improves overall performance a lot.

Anyways, the problem with clip() in P2D and P3D is that transformations don’t apply to the clip. An issue has already been reported on this problem.

1 Like

The solution for FX2D is very simple! However, it works different than filter(), but for my case it is perfect. Unfortunately this won’t work on other renderers, here’s the code:

void draw() {
  GraphicsContext ctx = ((Canvas) surface.getNative()).getGraphicsContext2D();
  GaussianBlur blur = new GaussianBlur();
  blur.setRadius(10);
  ctx.setEffect(blur);
  // do some drawing, anything drawn from here on will be blured
  // to disable the effect, do:
  ctx.setEffect(null);
}

JavaFX includes multiple more effects, like Glow and DropShadow, be sure to check them out if you want lag-free effects.
Don’t remember which package they’re from, you’ll have to search yourself.

2 Likes