How to improve skia anti-aliasing on very big screen?

602 views
Skip to first unread message

璞王

unread,
Aug 28, 2023, 3:21:00 AM8/28/23
to skia-discuss
Hi everyone, I am developing a whitboard android APP based on skia targeting to a very large meeting screen like ZOOM DTEN D7. The big screen's resolution is 3840x2160, and supports up to 4xMSAA.
Polygons rendered are very jaggy, although I enabled 4xMSAA (tools/sk_app/android/GLWindowContext_android.cpp). I also tried raster render backend (tools/sk_app/android/RasterWindowContext_android.cpp), but did not works well too.
skia-4xMSAA-very jaggy polygon.jpg
I try to draw ploygons to a 7680x4320 offscreen surface and then downscale to the screen, just like what the example tools/viewer/ThinAASlide.cpp dose. This mitigates a little, but there are still obvious sawteeth especially sloping lines.
skia - ThinAA - jaggy lines.jpg
I found the mapbox anroid demo has very nice polygons. If you don't look very closely, you can't see the jagged edges at all. I think the blur in the fragment shader is the real solution.
So any suggestion how to improve skia anti-aliasing effect on the big screen?
mapbox - very fine polygon.jpg
below is the fragment shader of mapbox-gl-js\src\shaders\line.fragment.glsl
void main() {
    #pragma mapbox: initialize highp vec4 color
    #pragma mapbox: initialize lowp float blur
    #pragma mapbox: initialize lowp float opacity

    // Calculate the distance of the pixel from the line in pixels.
    float dist = length(v_normal) * v_width2.s;

    // Calculate the antialiasing fade factor. This is either when fading in
    // the line in case of an offset line (v_width2.t) or when fading out
    // (v_width2.s)
    float blur2 = (blur + 1.0 / u_device_pixel_ratio) * v_gamma_scale;
    float alpha = clamp(min(dist - (v_width2.t - blur2), v_width2.s - dist) / blur2, 0.0, 1.0);

    gl_FragColor = color * (alpha * opacity);

#ifdef OVERDRAW_INSPECTOR
    gl_FragColor = vec4(1.0);
#endif
}

Brian Osman

unread,
Aug 28, 2023, 8:44:16 AM8/28/23
to skia-d...@googlegroups.com
I'd suggest NOT enabling MSAA (but still making sure to call setAntialias(true) on your SkPaint). That will cause Skia to use shader techniques for anti-aliasing, which are generally higher quality than MSAA.

--
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/9436b6c2-5703-40d2-943c-8901d5817f5en%40googlegroups.com.

璞王

unread,
Aug 29, 2023, 3:32:40 AM8/29/23
to skia-discuss
Thanks a lot. After I disabled MSAA, skia draws better quality, but there are still quality gaps compared to mapbox. Maybe the u_device_pixel_ratio in the mapbox shader is the key point, mapbox set it some value related to physics DPI. That would be great if skia expose a  ’u_device_pixel_ratio‘  like parameter in GrContextOptions, so users can adjust shader anti-aliasing quality too.

John Stiles

unread,
Aug 29, 2023, 7:52:41 AM8/29/23
to skia-d...@googlegroups.com
Could we have an apples-to-apples screenshot of the same path in mapbox vs Skia?
Your earlier Mapbox screenshot showed a differently colored path with a cluttered background. A proper screenshot would help us see what it is doing differently. Thanks :)

Greg Daniel

unread,
Aug 29, 2023, 9:05:30 AM8/29/23
to skia-d...@googlegroups.com
Also how did you stop enabling MSAA? There are two things that would need to change to fully not use it.

1) Don't pass a sampleCount into any SkSurface (or GrBackendTexture).

2) Skia may internally use MSAA to speed up various path draws. You can disable Skia's internal use my setting GrContextOptions::fInternalMultisampleCount to be 0.



璞王

unread,
Aug 30, 2023, 9:30:18 AM8/30/23
to skia-discuss
Yes, that is what I did to disable skia MSAA. I find setting 1 or 0 into GrBackendRenderTarget makes no difference, and the same to whether I set EGL_SAMPLES&EGL_SAMPLE_BUFFERS to 0 or 4. All the settings result to a same drawing quality (better than skia msaa enabled).

Sorry for my previous message, I didn't look closely. Mapbox draws sawteeth sloping lines too.
EA7F63186A2137BC27CD7A4F0.jpg
Reply all
Reply to author
Forward
0 new messages