Advertisement

Venting: dashed lines and curves in nanoVG

Started by June 24, 2021 11:15 AM
0 comments, last by JB3DG 3 years, 5 months ago

So a while back I wrote my own dx11 shader based 2D vector graphics library as a GDI+ replacement. Can’t share it as its proprietary but sharing this tip for those who use nanoVG and don’t want to go through all the trouble of doing their own lib.

NanoVG renders arcs as Bézier curves, and when dashed it splits up each dash into its own draw call which is highly inefficient. If it stuck to a single draw call but placed the distance of each point in the curve from the starting point into a texture coordinate, and the dash pattern in a structured buffer or 1D texture, the pixel shader would automatically interpolate the length between points and a simple fmod could be used to determine whether you draw the pixel or discard it.

This topic is closed to new replies.

Advertisement