Antialiasing?

1,327 views
Skip to first unread message

Damien

unread,
Feb 18, 2012, 1:40:59 PM2/18/12
to Kivy users support
Hello all,

Any way to draw anti-aliased bezier curves or activate FSAA in Kivy?
I tried a few things with kivy.graphics.opengl.glHint and methods from
OpenGL.raw.GL, but none of these did the trick.

Regards,
Damien

Senthil Seveelavanan

unread,
Mar 11, 2012, 6:57:43 AM3/11/12
to Kivy users support
+ 1

Does anybody know how to enable anti-aliasing?

Senthil

Wojciech Danilo

unread,
Feb 4, 2013, 12:01:25 AM2/4/13
to kivy-...@googlegroups.com
I'm also interested in Bezier curves with antialiasing - is it doable? how?

Mathieu Virbel

unread,
Feb 10, 2013, 9:00:15 PM2/10/13
to kivy-...@googlegroups.com
Anti aliasing is already activated by default (multisampling) if your
graphics card support it.

But the GL_LINES are most of the times not impacted by it. Try to give a
width != 1 to Line or Bezier, and it should be a little bit better.

Mathieu

Le 04/02/2013 06:01, Wojciech Danilo a �crit :
> I'm also interested in Bezier curves with antialiasing - is it doable? how?
>
> W dniu niedziela, 11 marca 2012 11:57:43 UTC+1 u�ytkownik Senthil
> Seveelavanan napisaďż˝:
>
> + 1
>
> Does anybody know how to enable anti-aliasing?
>
> Senthil
>
> On Feb 18, 6:40 pm, Damien <damien.d...@gmail.com> wrote:
> > Hello all,
> >
> > Any way to draw anti-aliased bezier curves or activate FSAA in Kivy?
> > I tried a few things with kivy.graphics.opengl.glHint and methods
> from
> > OpenGL.raw.GL <http://OpenGL.raw.GL>, but none of these did the
> trick.
> >
> > Regards,
> > Damien
>
> --
> You received this message because you are subscribed to the Google
> Groups "Kivy users support" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to kivy-users+...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

João Ventura

unread,
Mar 24, 2014, 4:10:11 PM3/24/14
to kivy-...@googlegroups.com
Hi there,

sorry for bringing back this topic, but I just need a confirmation. Antialliasing is not enabled via software, am I right?

I'm writing an app with Kivy which makes use of line and circle usage, and, as can be seen in the following picture, it is plain ugly without anti-aliasing in my low resolution screen, having some artifacts.. I added more segments, but the effect is the same. Raising the width hides the problem but does not fix it..

My graphics card is an Nvidia from a 2008 laptop, I'm in Xubuntu 13.04 with Nvidia drivers so I guess I should have OpenGL anti-aliasing as per Mathieu's answer.

I've checked the code at kivy/graphics/vertex_instructions_line.pxi and I see that the points are "manually" calculated, but I couldn't find where they are draw in the source code. My question is, it this easily solvable, probably using a drawing "provider"? Or an algorithm for anti-aliasing should/could be implemented?

Thanks


Alexander Taylor

unread,
Mar 24, 2014, 4:35:42 PM3/24/14
to kivy-...@googlegroups.com
There's actually been a great deal of improvement here just recently - no general solution in master yet, but great antialiasing is a lot more possible now. One possibility is to draw in the smaa widget in the kivy garden, https://github.com/kivy-garden/garden.smaa. Another is to use your own antialiasing shader, I have an experimental branch that in principle makes this quite easy though it doesn't have a good simple aa shader right now. I also recently saw some great antialiased graphs from tito that didn't use either of these methods, but I'm not sure how that was achieved.

qua-non non

unread,
Mar 24, 2014, 5:21:52 PM3/24/14
to kivy-...@googlegroups.com
I believe the charts from tito were merged into garden.graph, you can take inspiration from that.


--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

João Ventura

unread,
Mar 24, 2014, 5:25:33 PM3/24/14
to kivy-...@googlegroups.com
Hi Alexander,

thanks for your input. I've already seen garden.smaa, but I would really need it to work also on mobile platforms, and it seems that that sub-project is only working on desktops.

As qua-non suggested, I'm going to check out garden.graph.

Thank you both for the suggestions.

João Ventura

unread,
Mar 25, 2014, 8:13:18 AM3/25/14
to kivy-...@googlegroups.com
Hi there,

I have just checked out the garden graph project, and SmoothLinePlot(Plot) as is seems quite good for drawing anti-aliased lines.
Any chance that this can get directly to kivy.graphics.vertex_instructions_line, maybe as a flag such as "antialiasing=True"? Anti-aliasing is a quite common requirement for any modern graphics package these days..


Mathieu Virbel

unread,
Mar 25, 2014, 2:41:58 PM3/25/14
to kivy-...@googlegroups.com

Hi,

Just a note about your first screenshot. What you see is the anti aliasing from your graphics card. And yes it sucks.

There is a lot of alternative for antialiasing vector graphics that give multiple result. None of them is straightforward, and is either harder to integrate into the pipeline, or more heavy at rendering time.

For example, the choice made in the SmoothLinePlot is tedious: if you have 100x line, 100x shader need to be binded, line need to be drawed, and shader unbinded. If you know what you are doing, the best solution is bind the shader once, draw all the line you want, unbind.

Also, SmoothLinePlot works great for this single use case. It would not work if the line width is bigger without a more complex shader. Everything as a limitation.

antialiasing=True doesn't make sense at all. It's like saying beautiful=True. The _method_ matters, and the usage of it have a cost.

My point is, i want to provide a SmoothLine that will encapsulate the line shader and Line instruction. Please take note that the shader require to draw a rectangle with a black/white gradient. The smooth is adjusted depending the gradient width.

It's a complex problem, on which there is no easy solution except if you think per-app.

Mathieu

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

João Ventura

unread,
Mar 25, 2014, 3:21:02 PM3/25/14
to kivy-...@googlegroups.com
Hi Mathieu,

thanks for your input!

I'm writing an app in Kivy, and for the same app on PySide (with Qt4) I used anti-aliasing to draw some lines and circles. Also, my Kivy app in my low-res Android tablet suffers from the same problem in lines/circles being draw, hence the necessity to have anti-aliasing in my Kivy app.

I understand somewhat the anti-aliasing problem as you have put it. It is basically a trade-off, where you trade performance for aesthetics. However, I can't be of much help because I come from a TextMining field, so things like shaders, openGL internals, etc., are pretty new to me. I've been through Kivy's graphics vertex instructions source code but things are very new to me. My suggestion for "anti-aliasing=True" comes from the fact that in other graphics packages, you set a flag if you want to use anti-aliasing:

- Qt: setRenderHint( QPainter::Antialiasing )
- Android:
Paint.setFlags(Paint.ANTI_ALIAS_FLAG)

Regarding your SmoothLinePlot, it seems to be working fine, although I still do not know the performance hit that it may give. I will find out later if it is impeditive for my specific case, but I think not.

However, everything considered, I'm in favor that Kivy should have an implementation of anti-aliasing, even if experimental and low-performance. Anything is better than nothing.


Thanks!

João Ventura

unread,
Mar 25, 2014, 3:27:37 PM3/25/14
to kivy-...@googlegroups.com
Since this post is one of the first results for "kivy antialiasing" on google, for reference here is a working example of anti-aliasing based on Mathieu's example on https://github.com/kivy-garden/garden.graph. It uses the gradient shader that Mathieu mentioned previously (GRADIENT_DATA)..

from kivy.app import App
from kivy.graphics import Line
from kivy.graphics.texture import Texture
from kivy.uix.widget import Widget

   
GRADIENT_DATA
= (
   
"\x00\x00\x00\x07\x07\x07\x0f\x0f\x0f\x17\x17\x17\x1f\x1f\x1f"
   
"'''///777???GGGOOOWWW___gggooowww\x7f\x7f\x7f\x87\x87\x87"
   
"\x8f\x8f\x8f\x97\x97\x97\x9f\x9f\x9f\xa7\xa7\xa7\xaf\xaf\xaf"
   
"\xb7\xb7\xb7\xbf\xbf\xbf\xc7\xc7\xc7\xcf\xcf\xcf\xd7\xd7\xd7"
   
"\xdf\xdf\xdf\xe7\xe7\xe7\xef\xef\xef\xf7\xf7\xf7\xff\xff\xff"
   
"\xf6\xf6\xf6\xee\xee\xee\xe6\xe6\xe6\xde\xde\xde\xd5\xd5\xd5"
   
"\xcd\xcd\xcd\xc5\xc5\xc5\xbd\xbd\xbd\xb4\xb4\xb4\xac\xac\xac"
   
"\xa4\xa4\xa4\x9c\x9c\x9c\x94\x94\x94\x8b\x8b\x8b\x83\x83\x83"
   
"{{{sssjjjbbbZZZRRRJJJAAA999111)))   \x18\x18\x18\x10\x10\x10"
   
"\x08\x08\x08\x00\x00\x00")


class TestApp(App):
   
def build(self):
        widget
= Widget()
       
# Create texture
        tex
= Texture.create(size=(1, 64), colorfmt='rgb')
        tex
.blit_buffer(GRADIENT_DATA, colorfmt='rgb')
       
# Draw lines with the texture
       
with widget.canvas:
           
Line(circle=(200,200,150), close=True, width=1.01, texture=tex)
           
Line(circle=(300,300,150), close=True, width=1.00, texture=None)
       
return widget
       
if __name__ == "__main__":    
   
TestApp().run()


Mathieu Virbel

unread,
Mar 27, 2014, 3:48:25 AM3/27/14
to kivy-...@googlegroups.com
It will work only with latest 1.8.1-dev, because it require a fix in Line.

And to be clear: your application is already antialiasing by your hardware, but you don't like it and want another one :) It's really not about having antialiasing = True. GPU doesn't work the same as image rastering. Qt have its own drawing engine, which is different. Any graphics library that render on an image (cairo) will have a better antialiasing here, but don't do anything realtime. Kivy does realtime, and use GPU, which is a constraint and have limitation for vector. This is also why Kronos consortium doesn't push the OpenVG, and almost no manufacters support it.

_every_ OpenGL/Direct3d based applications have the same issue using the default / basic approach.

Mathieu


Wackazong

unread,
Oct 10, 2016, 11:02:53 AM10/10/16
to Kivy users support
I am using an EffectWidget with

effects: ew.HorizontalBlurEffect(size=0.1), ew.VerticalBlurEffect(size=0.1), ew.FXAAEffect()

And its looking quite nice IMHO. Just use it on graphics, not on text or buttons.
Reply all
Reply to author
Forward
0 new messages