memononen / nanovg

Antialiased 2D vector drawing library on top of OpenGL for UI and visualizations.
zlib License
5.13k stars 768 forks source link

feathering of a shape : how to do this #467

Open qtnext opened 6 years ago

qtnext commented 6 years ago

Hi,

we plan to use nanovg to draw a closed vector shape to do a mask in a real time compositing application but we need to be able to adjust the external feather of the shape to have a smooth adjustable fading in alpha. is there a way to do this ?

memononen commented 6 years ago

Take a look at nvgFill https://github.com/memononen/nanovg/blob/master/src/nanovg.c#L2205 There's paramter fringeWidth this is the size of the AA feather or fringe that is drawn. You can increase this value to make the fringe artificially larger.

Be aware that it will not handle overlapping fringes gracefully.

I think better approach for your use case would be to render the mask into an FBO and blur the result. There are many ways to do that with OpenGL, google is your friend.

qtnext commented 6 years ago

thanks :) we will try this