I’m trying to use Java2D to create a glowing effect behind shapes (for example, text), and the performance seems to stink.
I’m using a Gaussian kernel with the ConvolveOp along with a RescaleOp to even out the blur. I’d like to be able to blit about 100 convolutions in about 100ms, but I’m definitely not seeing that level of performance. (Btw, I’m keeping the Gaussian very small - a radius of 3).
Basically, my setup looks like this:
- Render highlight colored shape to pre-multiplied buffer
- Filter with gaussian into another pre-multiplied buffer
- Filter with rescale
- Blit from pre-multiplied buffer to screen compatible back buffer
- Render foreground colored shape to screen compatible back buffer on top of blurred shape.
Anybody have any suggestions for speeding this up?
Two problems I see:
- The convolve has to happen on a pre-multiplied buffer which makes the blit to my backbuffer/screen slow.
- I have to clear my buffer on each run.
I can’t see how to get away from either of those problems.
One strategy I was considering was stuffing as mamy shapes as possible into the same buffer and performing the blur on them all at once. One problem I see with that is that the Gaussian may take longer to run because it would be operating on dead pixels in space unoccupied by neighboring shapes.
Another obvious solution is caching the blurred images, but that’s more of a last resort thing.
God bless,
-Toby Reyelts