View Full Version : Architecture choice for rending a bezier curve (for UI purposes)

02-12-2018, 10:59 AM

I have another architecture question, I'm building a mini vector graphics library so I can draw some nice ui components (such as a curved rectangle panel). I'm currently building the points manually in my code during initialization and then drawing them via a line loop. I have seen in some places that an alternative method is to pass the points and control points to a shader (as they form triangle/s) and to let the shader choose whether to draw the point or not (via some sort of test such as u^2 -v > 0 for fill or =0 for line, for a quadratic bezier). Is there a better choice here? The 1st has more work to do upfront but makes it harder to do things such as anti aliasing (unless there is a good way to incorporate it here) and the 2nd has more work to do but allows so extra logic to anti alias.

There is the tessalation shader too but I can't see it being any better here than the 1st method (could be wrong here again :))

02-12-2018, 01:19 PM
Using the implicit form directly in a fragment shader is more accurate, but it's awkward for arbitrary piecewise curves. You typically need additional data to determine which segment(s) need to be considered at any point.

With the parametric form, a tessellation shader allows most of the work to be moved to the GPU. It also avoids the need to calculate and upload new data if the sample spacing changes. The latter point is more relevant if you need to be able to vary the level of detail dynamically, e.g. for a first-person perspective view where it would vary with distance from the viewpoint.