Adjacent polygons don't line up well if antialiased

67 views
Skip to the first unread message

Luboš Luňák

unread,
15 Jun 2020, 07:07:4815/06/2020
to skia-d...@googlegroups.com

Hello,

AFAIK when drawing two adjacent polygons (sharing one edge) it is guaranteed
that they will line up perfectly, resulting in a shape as if just one merged
polygon was drawn. And that is indeed the case with Skia too, but only if
antialiasing is disabled, not if AA is enabled, such as in the example below
(2nd and 3rd point is the same edge as 1st and 4th point in the next
polygon). If you zoom in, you can see drawing artefacts. Is this a Skia bug,
or is this not guaranteed with AA-ed polygons? I've tried with other toolkits
(Qt5) and there it works correctly even with AA enabled.

https://fiddle.skia.org/c/6efe6f12706374d93d63d2143297ec2d

--
Luboš Luňák
l.l...@collabora.com

Greg Daniel

unread,
15 Jun 2020, 08:09:1515/06/2020
to skia-discuss
This is working as intended. For normal AA each shape is drawn independently. So after one shape is draw, pixels around the edge will have some level of anti aliasing applied to them. In other words they will look lighter than the main paint to take into account the partial coverage. However, once we draw a pixel we no longer know what part of a pixel was partially covered. All we see is that there is a pixel with a lighter color. So then come the second draw, it is simply blending as if the whole destination was that lighter color. For non-AA this doesn't happen cause a pixel that sits along a shared edge will only ever belong to one shape or the other. So there is no double blending.

The only type of AA that allows shapes drawn next to each other to seam correctly is using multisampling (i.e. MSAA). This is because it basically acts like the non-AA case and individual sample locations with a pixel will only belong to what shape of the other along the edge.

Greg

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/skia-discuss/202006151307.43154.l.lunak%40collabora.com.

Shawn Riordan

unread,
15 Jun 2020, 09:18:2515/06/2020
to skia-discuss
The way we fix it is this:

- Collect a list of filled shapes who share an edge but do not overlap each other and have the same blendmode.
- Create a layer and initialize it with the SkColor kTransparent.
- Draw all those elements into a layer with the kPlus blendmode active.
- Draw the layer back to the main canvas.

Christopher Dalton

unread,
15 Jun 2020, 10:21:0515/06/2020
to skia-d...@googlegroups.com
Drawing into a new layer with kPlus will work, but you might (or might not) find it's faster in your case to build an SkPath with all the polygons together and then call drawPath() once.


--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages