Blur background of widget

579 views
Skip to first unread message

Tim H.

unread,
Jun 9, 2014, 2:28:34 PM6/9/14
to kivy-...@googlegroups.com
I would like to blur the background of a translucent widget (as seen in iOS7 and many other toolkits).
Is this somehow possible?

A perfect solution would look like this:
with self.canvas:
    Callback(self.blur_background)
    Color(1, 1, 1, 0.5)
    Rectangle(pos=self.pos, size=self.size)
And in self.blur_background apply a blur shader on the current OpenGL state in the area of the widget, but I don't know if this is possible.

But even if its not, can someone think of a quick'n'dirty alternative i.e. without gaussian blur but with something easier?

Many thanks in advance
Tim H. 

Alexander Taylor

unread,
Jun 9, 2014, 3:24:32 PM6/9/14
to kivy-...@googlegroups.com
If you use kivy's master branch, there's a new EffectWidget which makes it easy to apply opengl effects to its children, you can see the doc at http://kivy.org/docs/api-kivy.uix.effectwidget.html

You would want to use the HorizontalBlurEffect and VerticalBlurEffect. Note that the EffectWidget can only apply the effect to its children, so you'd need to structure your code such that the right widgets were blurred.

Tim H.

unread,
Jun 10, 2014, 4:19:28 AM6/10/14
to kivy-...@googlegroups.com
But if I would just use the EffectWidget the whole background would be blurred. If I only want to blur the area behind the widget, I would need to get the "pixels" behind the widget, put these as a texture in the EffectWidget and blur only that.

So how do I get the pixels behind the widget?
Something like fbo.texture.get_region(widget.x, widget.y, widget.width, widget.height)?
But does that work during the draw process?

Alexander Taylor

unread,
Jun 10, 2014, 5:53:55 AM6/10/14
to kivy-...@googlegroups.com
I don't know if there's a 'right' way to do this that I'm missing, but it seems like you need multiple layers, with all the background layers rendered in Fbos very similarly to the EffectWidget. The difference is that instead of applying an effect to all of them, you'd want to draw a single rectangle in the effect Fbo in the position and size of the foreground widget whose background you want to blur. That takes care of blurring the output where the widget is, and you'd finally want to make the EffectWidget always draw it's unchanged input behind everything else (so the non-blurred part appears).

Maybe there's an easier way, but that's all that comes to mind.

Tim H.

unread,
Jun 10, 2014, 6:25:46 AM6/10/14
to kivy-...@googlegroups.com
This makes sense, but this also means that there can be only one layer that will be blurred partitially because every additional layer would double the performance impact.

In the next days I will try this and report about the performance.
Reply all
Reply to author
Forward
0 new messages