4

I found a shader code to draw a filled Quadratic Bezier in

https://developer.nvidia.com/gpugems/GPUGems3/gpugems3_ch25.html

How can I use something similar to draw a Bezier line that follows the same path?

fospathi
  • 149
  • 4
Zhen
  • 1,316
  • 1
  • 13
  • 30

1 Answers1

7

The HLSL code in the linked article gives you a signed distance to the curve, which is used for antialiasing. Since the value is signed instead of clamped, it can be used on both sides of the curve. Absolute value of the signed distance gives the distance to the curve.

Changing

float alpha = 0.5 - sd;

to

float alpha = 1.0 - abs(sd);

gives you alpha = 1 when the pixel is exactly on the curve and alpha between [0,1] when the pixel is within 1 pixel radius of the curve.

You can set the thickness of the curve with:

float alpha = thickness - abs(sd);

Beware that the polygon must be large enough to cover the thick curve.

msell
  • 5,848
  • 1
  • 28
  • 41