FXAA
Copy link to clipboard
Copied
Hi. I've drawn a curved line but it's very jagged and don't know how to smooth it. Does anyone know if it's possible to implement FXAA or a similar method?
I've considered drawing my line at a much higher res and then downscaling, but I think FXAA would be more efficient. Thanks!
Copy link to clipboard
Copied
Hi James!
'Super sampling' (writing at higher scale then reducing) gives good results, but you'll have to handle large EffectWorlds.
It used to be a bummer, but nowadays, machines can deal with it, so it can be an easy way to go.
I don't know of any built in function for FXAA. I'm using OpenGL, so I just added a FXAA shader...
But you could adapt it to an iteration function pretty easily. You'll have to try to be sure, but I think Super Sampling can be faster than iteration.
Otherwise, if you're only drawing lines, the easiest is to draw antialiased lines directly!
You can check this link https://en.wikipedia.org/wiki/Xiaolin_Wu
Hope it helps!
François
Copy link to clipboard
Copied
Thanks for the info Francois. Super noob question, can AMD cards run FXAA? I believe it was developed by an Nvidia employee so it wouldn't surprise me if they kept it to themselves.
I did see that link, would be good but I'm doing curved lines .
Copy link to clipboard
Copied
Well, any card can run it, as long as you write your own shader. Cos' it doesn't rely on any specific function, it is very basic Glsl.
I use a slightly modified version of this one: (Tested) Fast Approximate Anti-Aliasing (FXAA) Demo (GLSL) – Page 3 – Geeks3D
You can start from there if you want to implement it for an AE iteration function.
Now about curves: curves can be seen as straight segments put together! So you can split your curves in pieces and write them already antialiased. 🙂
Cheers,
François
Copy link to clipboard
Copied
Great, thanks for the link!
I'm using penner's easing to draw my curved line, I think it's a little advanced for me to implement wu's algorithm into that but it's nice to know it can be done.
Copy link to clipboard
Copied
If you're using Penner's easing (or bezier, or actually a lot of algorithms!), you probably have a 't' variable, varying from 0 to 1 along the curve, right?
Instead of drawing pixels one by one, you can draw a small segment with wu's algorithm each time.
Here's a pseudo code for a curve split in 100:
A_FloatPoint previousPoint = easing( easing_parameter1, easing_parameter2, 0);// startPoint of the curve, i.e at t == 0
A_FloatPoint newPoint;
for (float tf = 1; tf <= 100; tf++) {
newPoint = easing( easing_parameter1, easing_parameter2, tf * myCurveLength / 100);//get newPosition along the curve
drawSmoothLine( previousPoint, newPoint);//draw segment from previous point to new point with wu's algorithm
previousPoint = newPoint;//update previous point with new point's position, so you don't need to re-compute it
}
Hope it helps!
Cheers,
François
Copy link to clipboard
Copied
Thanks for that code Francois. Unfortunately I'm putting this plugin on the backburner for now as I just learned how difficult it is to make a curved line that's wider than 1px
Copy link to clipboard
Copied
Well, there is a way, close to what the stroke effect does:
_create a PF_EffectWorld the size of your line width. This will be your brush.
_fill it with a circle of your color. Here you can make the circle slightly blurry (lets say 1 pixel or 2).
_copy your brush along your path with WorldTransform.
Tada! You have an antialiased thickline!
Not the most efficient in terms of memory, and transparency can be an issue, but it's easy to do. 🙂
Cheers,
François
Copy link to clipboard
Copied
You could also make use of OS libraries - Quartz on Mac and GDI+ on Windows. They're a bit fiddly to get working - you need to set aside some memory for a bitmap, and each library has its own way of setting things up, but I managed to figure it out 😉 If you search for GDI+ on here you may find some old posts from me asking questions about doing this.
These libraries provide functions for drawing all sorts of things antialiased, nice and fast using the GPU. I used them extensively for my plugin qp Grade Assistant, which was my first native plugin. I'd be happy to share some code with you if you want to get in touch privately.

