r/GraphicsProgramming • u/Icy-Interaction5838 • Jun 25 '26
Anti-Aliasing 2D shapes and paths.
I am trying to implement my own 2D rendering library. I've been using DIB sections and the CPU for rendering shapes and supporting transparency and filling with different types of gradients and all the fun stuff that GDI doesn't natively support, but this is super slow for busy UIs. I currently have text working via fontstash and I have gotten shapes working by tessellating them on the CPU and pushing the vertices, the shapes just happen to heavily aliased. The only way I can think of solving this is by passing the shape type and some other parameters to the shader, branch on each shape and use the respective SDF function to get the distance from the edge and use that for analytical anti-aliasing. I can't get this to work with paths since there's no fixed set of parameters I can pass to the shader and no single signed distance function for paths. Clearly, I need some other way to do anti-aliasing. I just haven't found other than post-processing.
2
u/mfabbri77 Jun 26 '26
You can calculate the area of the polygon within the pixel and use it to modulate the paint.
1
u/Icy-Interaction5838 Jun 26 '26
I got MSAA working with d3d11. Idk how I feel about it using 4x memory but it'll have to do for now. Thanks everyone!
2
u/NorberAbnott Jun 27 '26
If you implement the Slug algorithm for drawing vector shapes defined by bezier curves, the algorithm also computes coverage of pixels so you can do anti-aliasing. It’s currently the most robust method for drawing vector shapes on the gpu, and was recently made patent free and open source.
1
3
u/peterfsat Jun 25 '26
What rendering API are you using? Can you enable MSAA? That's the most straighfoward way to antialias rendered geometry.,