How to draw a perfect 1px solid line

Hi everyone,

I’m trying draw Hard Grid using Skia on a 1920x1080 screen.
I am encountering inconsistent sharpness when drawing thin lines.

Space: PixelTopLeft (using WithinPhysicalScreenSpace)
I drew three test lines with different StrokeWidths:
0.1 & 0.3: The lines appear blurry and faint (grayish).
0.2: This one appears sharp/ideal in my test.
My questions:
Why does 0.2 look sharp while others blur? Is this a sub-pixel alignment artifact?Is this due to my Skia line width settings or anti-aliasing settings?

What is the best practice to get a perfect, solid 1px hard line?

Thanks!

Raster.vl (40.8 KB)

A stroke width of 0 draws a pixel perfect line.

1 Like

@joreg I tried a width of 0.00, and it looks the same as 0.01, with a grayish color.

please share the patch

Raster.vl (49.6 KB)

hmm looks good to me. also on your screenshot. the way you can verify its a pixel line is by zooming in.

e.g use a camera node in the layer connection. pixel lines will keep their width when zooming in, while others will have thei width changing.

1 Like

@joreg Got it about hairline strokes.

For drawing a UI-style hard grid (with fully covered pixels, no antialiasing/blending) in PixelTopLeft space using Skia, what would be the recommended approach?

With my current Line + Stroke setup, is it better to disable antialiasing o’r pixel-snap the coordinates? Is there have setting?

Raster.vl (53.0 KB)

@joreg Emmm…I understand… the problem I’m having isn’t entirely about drawing 1-pixel lines. it’s a fundamental pixel sampling and rendering pipeline issue, but I haven’t found a good solution yet…

A positive development:

I’ve constrained the animation values.
Specifically, I constrained the Float32 data to two decimal places, resulting in a completely smooth animation.

However, I still haven’t found a better way to achieve a more perfect effect. For example, when the line stroke width ends in an odd number, the lines appear grayish and the edges are blurry.

Does anyone have any good experiences with this?

Raster.vl (65.1 KB)

Basically solved…

When the line width ends in an odd number, I offset the position coordinates by 0.5px, and it appeared sharper. In terms of layout, it basically meets my needs.

3 Likes