Expensive repaints and gaussian blur


#1

I have made a goniometer component for a plugin I am developing, and was curious to see if I could replicate the glow effect seen in the latest version of Flux Stereo Tool plugin. They seem to achieve the glow by blurring the graph image before drawing a new buffer on it, which causes previous buffers to become blurrier over successive repaints.

I implemented a similar blurring in Juce using:

ImageConvolutionKernel imageKernel(3);
imageKernel.createGaussianBlur(8.f);
imageKernel.applyToImage(myImg, myImg, myImg.getBounds());

My plugin is repainting at 25fps and with the gaussian blur enabled the frame rate drops noticeably and CPU usage jumps (as measured in my DAW, Reaper). On the other hand Stereo Tool repaints at 30fps and stays perfectly smooth, and barely touches the CPU. My guess is that they are using hardware acceleration to render their goniometer?

The fancy blur isn’t necessary for my plugin, but I am curious how one would go about implementing that sort of animated eye candy in Juce without compromising performance?


#2

Yeah, JUCE’s Gaussian blur is insanely slow and isn’t designed for animated stuff as far as I know.

What I would do is make the goniometer an OpenGL component (read: not using the JUCE OpenGL renderer, but a straight OpenGL context) and draw your data using two passes with different pixel shaders. That should be super fast!


#3

That is great information, thank you. I don’t have a clue about using OpenGL but at least I know where to focus my efforts.


#4

I’m having fun with that stuff right now : http://glslsandbox.com/

It’s a gallery of pixel shaders, you just need to copy and paste the shaders code in a JUCE project which handles OpenGL and shaders (have a look for the demo examples and the OpenGLGraphicsContextCustomShader class), and you get the same result, accelerated by the hardware GPU.


#5

Trippy stuff! I’ll try to get one of these working in Juce to dip my toes in the OpenGL waters…


#6

Don’t forget to add an instruction to multiply gl_FragColor with “pixelAlpha” at the end of the shaders code to make them work if necessary :wink:


#7

Maybe you can fake the blurring a bit by using a Trails like effect. So instead of a Blur just keep a copy of the previous paint (in an Image) and draw on top of that. In this case you only need an Alpha blend.


#8

Good suggestion, and I am already doing that. You need an “afterimage” for a goniometer I think, otherwise the visual information changes too quickly to make sense of. The blurring effect would be purely eye candy!